赞
踩
在使用 buildroot 编译内核源码时,时常会有修改驱动或第三方包的需求,直接在 output/build/ 下修改源码,make clean 修改内容就会丢失,使用打补丁方式,把补丁包放到package下对于的包中,就能够解决此问题。
本篇博文记录修改 xl2tpd 源码打补丁过程。
第一步,拷贝 需要修改的文件 xl2tpd.c 文件,至指定文件夹下:
$ cd buildroot/output/build
$ mkdir src.xl2tp-v1.3.6
$ cp xl2tp-v1.3.6/xl2tpd.c ./src.xl2tp-v1.3.6/
修改文件内容如下:
void destroy_tunnel (struct tunnel *t) { .... if (t->lac) { t->lac->t = NULL; if (t->lac->redial && (t->lac->rtimeout > 0) && !t->lac->rsched && t->lac->active) { l2tp_log (LOG_INFO, "Will redial in %d seconds\n", t->lac->rtimeout); tv.tv_sec = t->lac->rtimeout; tv.tv_usec = 0; t->lac->rsched = schedule (tv, magic_lac_dial, t->lac); /* user add interface done process */ l2tp_log(LOG_INFO, "IXE-cloud Will closed usb 4g ether down..."); system("ifconfig usb0 down"); sleep(1); l2tp_log(LOG_INFO, "--> start 4g ether dailer ..."); system("/etc/init.d/S99NDIS.sh"); /* 增加内容如上 */ } } ......
第二步,生成补丁文件
$ diff -uNr xl2tp-v1.3.6/xl2tpd.c src.xl2tp-v1.3.6/xl2tpd.c > 0003_dialer.patch //补丁内容 --- xl2tp-v1.3.6/xl2tpd.c 2021-03-10 14:15:17.350065952 +0800 +++ src.xl2tp-v1.3.6/xl2tpd.c 2021-03-10 14:11:04.273344366 +0800 @@ -554,6 +554,8 @@ struct call *c, *me; struct tunnel *p; struct timeval tv; + //char *ether_4g_down = "ifconfig usb0 down"; + if (!t) return; @@ -619,6 +621,16 @@ tv.tv_sec = t->lac->rtimeout; tv.tv_usec = 0; t->lac->rsched = schedule (tv, magic_lac_dial, t->lac); + + /* user add interface done process */ + l2tp_log(LOG_INFO, "IXE-cloud Will closed usb 4g ether down..."); + system("ifconfig usb0 down"); + sleep(1); + l2tp_log(LOG_INFO, "--> start 4g ether dailer ..."); + system("/etc/init.d/S99NDIS.sh"); + //l2tp_log(LOG_INFO, "--> start l2tp service ..."); + //system("echo \"c vpn\" > /var/run/xl2tpd/l2tp-control"); + } } /* XXX L2TP/IPSec: remove relevant SAs here? NTB 20011010
第三步,拷贝补丁文件至 package/xl2tp/0003_redailer_4g.patch
$ cp 0003_dialer.patch ../../package/xl2tp/0003_dialer.patch
第四步,编译验证补丁是否正确
build-2016$ make -j4 xl2tp-v1.3.6.tar.gz: OK (sha256: 49b069aa8d873e1d8f615ccc4212351e427bf681ba453fdd211256a8345bb7fb) >>> xl2tp v1.3.6 Extracting gzip -d -c /home/robot/buildroot/build-2016/dl/xl2tp-v1.3.6.tar.gz | tar --strip-components=1 -C /home/robot/buildroot/build-2016/output/build/xl2tp-v1.3.6 -xf - >>> xl2tp v1.3.6 Patching Applying 0001-legacy.patch using patch: patching file osport.h Hunk #1 succeeded at 35 (offset -2 lines). Applying 0002-musl.patch using patch: patching file xl2tpd.c # 补丁包执行情况 Applying 0003_dialer.patch using patch: patching file xl2tpd.c >>> xl2tp v1.3.6 Configuring >>> xl2tp v1.3.6 Building
第5步 ,查看补丁后的源文件内容
if (t->lac) { t->lac->t = NULL; if (t->lac->redial && (t->lac->rtimeout > 0) && !t->lac->rsched && t->lac->active) { l2tp_log (LOG_INFO, "Will redial in %d seconds\n", t->lac->rtimeout); tv.tv_sec = t->lac->rtimeout; tv.tv_usec = 0; t->lac->rsched = schedule (tv, magic_lac_dial, t->lac); /* user add patching */ l2tp_log(LOG_INFO, "IXE-cloud Will closed usb 4g ether down..."); system("ifconfig usb0 down"); sleep(1); l2tp_log(LOG_INFO, "--> start 4g ether dailer ..."); system("/etc/init.d/S99NDIS.sh"); //l2tp_log(LOG_INFO, "--> start l2tp service ..."); //system("echo \"c vpn\" > /var/run/xl2tpd/l2tp-control"); } } /* XXX L2TP/IPSec: remove relevant SAs here? NTB 20011010 * XXX But what if another tunnel is using same SA? */
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。