Merge remote-tracking branch 'origin/libuv_dhcpd_dev' into libuv_dhcpd_dev

This commit is contained in:
huangxin 2023-04-21 15:01:45 +08:00
commit 68a5d8df80
5 changed files with 11 additions and 2 deletions

View File

@ -99,6 +99,8 @@ application:
# replication = ["10.10.0.1", "10.10.0.2"];
# MAC地址黑名单
# mac_filter = ["00:01:02:03:04:07", "00:01:02:03:04:01"];
# 数据包过滤器
net_filter = "vlan and udp and port 67 and port 68";
# IP地址池配置
range_set: (
{ dhcp_range = "192.168.101.0-192.168.101.4";

View File

@ -120,6 +120,7 @@ static CFG_ITEM g_cfgItem[] = {
DEF_CFG_ITEM(CFG_DHCP_LISTEN_ON, "dhcp_server.listen_on", VAL_ARRAY_STR, "", "DHCP listen interface"),
DEF_CFG_ITEM(CFG_DHCP_REPLICATION_SVR, "dhcp_server.replication", VAL_ARRAY_STR, "", "DHCP replication server configure"),
DEF_CFG_ITEM(CFG_DHCP_RANGE_SET, "dhcp_server.range_set", VAL_ARRAY_OBJ, "", "DHCP IP pool"),
DEF_CFG_ITEM(CFG_DHCP_NET_FILTER, "dhcp_server.net_filter", VAL_STR, "", "DHCP packet filter"),
DEF_CFG_ITEM(CFG_DHCP_MAC_FILTER, "dhcp_server.mac_filter", VAL_ARRAY_STR, "", "DHCP client MAC address black list"),
DEF_CFG_ITEM(CFG_DHCP_NIC_NAME, "dhcp_server.nic", VAL_STR, "ens192", "DHCP server network interface name"),
#endif

View File

@ -46,6 +46,10 @@ c_vector config_get_dhcp_replication_svr() {
return cfg_get_vector(CFG_DHCP_REPLICATION_SVR);
}
const char *config_get_dhcp_net_filter() {
return cfg_get_string_value(CFG_DHCP_NET_FILTER);
}
c_vector config_get_dhcp_mac_filter() {
return cfg_get_vector(CFG_DHCP_MAC_FILTER);
}

View File

@ -79,6 +79,7 @@ typedef enum {
CFG_DHCP_LISTEN_ON,
CFG_DHCP_REPLICATION_SVR,
CFG_DHCP_RANGE_SET,
CFG_DHCP_NET_FILTER,
CFG_DHCP_MAC_FILTER,
CFG_DHCP_NIC_NAME,
#endif
@ -152,6 +153,7 @@ c_vector config_get_dhcp_server_range_set();
c_vector config_get_dhcp_listen_on();
c_vector config_get_dhcp_replication_svr();
c_vector config_get_dhcp_mac_filter();
const char *config_get_dhcp_net_filter();
const char *config_get_dhcp_nic_name();
#endif

View File

@ -642,7 +642,7 @@ void init_filter(const char *pNetFilter) {
static pcap_t *pd;
pd = pcap_open_dead(DLT_EN10MB, MAXIMUM_SNAPLEN);
struct bpf_program fcode;
//char *cmd_buf = "vlan and udp and port 67 and port 68";
pcap_compile(pd, &fcode, pNetFilter, 1, 0);
struct bpf_insn *insn = fcode.bf_insns;
@ -691,7 +691,7 @@ int dhcpd_init() {
get_nic_info(g_nicInfo.pIfName, &g_nicInfo.ipAddr, &g_nicInfo.netmask, NULL, g_nicInfo.macAddr);
init_filter("vlan and udp and port 67 and port 68");
init_filter(config_get_dhcp_net_filter());
ret = create_udp_raw_socket(g_nicInfo.pIfName);
if (ret != ERR_SUCCESS) {