我是靠谱客的博主 迷路康乃馨,这篇文章主要介绍[问题专题]DHCP option 60功能实现值修改,已解决 ,现在分享给大家,希望可以做个参考。

 

此问题堪称从业多年来困扰最大,方向全无的终极问题之一

问题来源

如上截图来源华为hilink平台适配调试文档。

新做的hilink linux网关,需要通过DHCP dicover包,上报option 60信息,信息内容就是一段字符串,例如huawei:hilink:gateway

 

DHCP包发送

  1. 我遇到这个问题,以为是在用户层代码,通过DHCP接口发送discover包,其中增加option60段,内容填充huawei:hilink:gateway即可,这个思想是错误的,方向性错误。应该是修改系统dhcp设置即可。

  2. 大部分人,包括我自己只知道dhcp是获取ip的,但是对dhcp的整个过程不是太了解,所以改变字段更是无从下手。

  3. 这个DHCP包是通过linux系统设置,具体步骤我是这样尝试的,但是失败了

    1. buildroot中增加dhcp client设置

    2. 升级网关系统,在etc/dhcp/下面有个dhclient.conf文件

    3. 在dhclient.conf文件中增加send vendor-class-identifier "huawei:hilink:gateway";(其中vendor-class-identifier就是60(3C)的字段标识。)

    4. 如下方法只能在dhcp的request包中增加了vendor-class-identifier(60)字段,但是值不是我设置的,而是系统默认的,所以修改此文件并未得到执行。

    5. 我再ubuntu电脑按照此方法修改,dhcp的request的包中是"huawei:hilink:gateway"

  4. 为什么要在discover增加字段,我在request中修改呢,因为找不到discover的位置,而且不会改这个conf文件

  5. 附上conf文件内容

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[root@sraum-gateway:/etc/dhcp]# ls dhclient.conf [root@sraum-gateway:/etc/dhcp]# cat dhclient.conf # Configuration file for /sbin/dhclient, which is included in Debian's # dhcp3-client package. # # This is a sample configuration file for dhclient. See dhclient.conf's # man page for more information about the syntax of this file # and a more comprehensive list of the parameters understood by # dhclient. # # Normally, if the DHCP server provides reasonable information and does # not leave anything out (like the domain name, for example), then # few changes must be made to this file, if any. # #send host-name "andare.fugue.com"; #send dhcp-client-identifier 1:0:a0:24:ab:fb:9c; #send dhcp-lease-time 3600; #supersede domain-name "fugue.com home.vix.com"; #prepend domain-name-servers 127.0.0.1; request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, host-name, netbios-name-servers, netbios-scope; #require subnet-mask, domain-name-servers; #timeout 60; send vendor-class-identifier "huawei:hilink:gateway"; #retry 60; #reboot 10; #select-timeout 5; #initial-interval 2; #script "/etc/dhcp3/dhclient-script"; #media "-link0 -link1 -link2", "link0 link1"; #reject 192.33.137.209; #alias { # interface "eth0"; # fixed-address 192.5.5.213; # option subnet-mask 255.255.255.255; #} #lease { # interface "eth0"; # fixed-address 192.33.137.200; # medium "link0 link1"; # option host-name "andare.swiftmedia.com"; # option subnet-mask 255.255.255.0; # option broadcast-address 192.33.137.255; # option routers 192.33.137.250; # option domain-name-servers 127.0.0.1; # renew 2 2000/1/12 00:00:01; # rebind 2 2000/1/12 00:00:01; # expire 2 2000/1/12 00:00:01; #}

 

问题分析

  • 修改文件系统,这个方向是不是也是错的?

  • 修改dhcp request,以为dicorver会自动加上option60 ,这个方向是不是也是错的?基本可以确定是错的。

  • 问题最终一定会解决,但是不知道以什么方式解决,加油吧!!!!!!!!!!!!!!!

解决问题2020年8月24号

成功的一个方向:修改dhcp源码!!!!

解决问题前先总结下dhcp有哪些开源库,因为我的linux文件系统是Buildroot构建的,buildroot又使用了busybox.

以下是buildroot中的dhcp相关的库

dhcp(ISC)

dhcpcd

dhcpdump:抓dhcp包,解析的,

dhsmasq:遇到上面的问题,有大佬让我试试这个库

 以下是Busybox中的dhcp相关的库

udhcpd:f服务端

udhcpc:客户端,就是我们需要添加和修改的,busybox默认自带,所以只要修改其源码即可

 

linux文件系统是Buildroot构建的,buildroot又使用了busybox,这里面有个天大的坑

修改udhcpc源码后,使用buildroot编译后没有效果,因为udhcpc是在busybox下面的,所以要先使用busybox编译后再使用buildroot编译,buildroot只会使用busybox的中间文件.o

 

修改点

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int udhcpc_main(int argc UNUSED_PARAM, char **argv) { uint8_t *message; const char *str_V, *str_h, *str_F, *str_r; IF_FEATURE_UDHCPC_ARPING(const char *str_a = "2000";) IF_FEATURE_UDHCP_PORT(char *str_P;) void *clientid_mac_ptr; llist_t *list_O = NULL; llist_t *list_x = NULL; int tryagain_timeout = 20; int discover_timeout = 3; int discover_retries = 3; uint32_t server_addr = server_addr; /* for compiler */ uint32_t requested_ip = 0; uint32_t xid = xid; /* for compiler */ int packet_num; int timeout; /* must be signed */ unsigned already_waited_sec; unsigned opt; IF_FEATURE_UDHCPC_ARPING(unsigned arpping_ms;) int retval; setup_common_bufsiz(); /* Default options */ IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;) IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;) client_config.interface = "eth0"; client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT; //修改处 str_V = "udhcp "BB_VER;//改成想要的值,默认是udhcp版本 ..... }

进入busybox目录,make

进入buildroot目录,把几个用不着的DHCP去掉,make

得到文件系统就去验证吧.

有问题的话,留言或者私信

 

最后

以上就是迷路康乃馨最近收集整理的关于[问题专题]DHCP option 60功能实现值修改,已解决 的全部内容,更多相关[问题专题]DHCP内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部