From: Alan T. DeKok Date: Fri, 1 Sep 2023 14:08:57 +0000 (-0400) Subject: make dhcpclient use Net.* X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43495619d30dfa4f36335a86e663fd6f198e8a24;p=thirdparty%2Ffreeradius-server.git make dhcpclient use Net.* --- diff --git a/src/bin/dhcpclient.c b/src/bin/dhcpclient.c index b6647932882..72323549af6 100644 --- a/src/bin/dhcpclient.c +++ b/src/bin/dhcpclient.c @@ -28,6 +28,7 @@ RCSID("$Id$") #include #include #include +#include #include #include @@ -85,12 +86,6 @@ fr_dict_autoload_t dhcpclient_dict[] = { { NULL } }; -static fr_dict_attr_t const *attr_packet_dst_ip_address; -static fr_dict_attr_t const *attr_packet_dst_ipv6_address; -static fr_dict_attr_t const *attr_packet_dst_port; -static fr_dict_attr_t const *attr_packet_src_ip_address; -static fr_dict_attr_t const *attr_packet_src_ipv6_address; -static fr_dict_attr_t const *attr_packet_src_port; static fr_dict_attr_t const *attr_packet_type; static fr_dict_attr_t const *attr_dhcp_message_type; static fr_dict_attr_t const *attr_dhcp_dhcp_server_identifier; @@ -98,12 +93,6 @@ static fr_dict_attr_t const *attr_dhcp_your_ip_address; extern fr_dict_attr_autoload_t dhcpclient_dict_attr[]; fr_dict_attr_autoload_t dhcpclient_dict_attr[] = { - { .out = &attr_packet_dst_ip_address, .name = "Packet-Dst-IP-Address", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_freeradius }, - { .out = &attr_packet_dst_ipv6_address, .name = "Packet-Dst-IPv6-Address", .type = FR_TYPE_IPV6_ADDR, .dict = &dict_freeradius }, - { .out = &attr_packet_dst_port, .name = "Packet-Dst-Port", .type = FR_TYPE_UINT16, .dict = &dict_freeradius }, - { .out = &attr_packet_src_ip_address, .name = "Packet-Src-IP-Address", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_freeradius }, - { .out = &attr_packet_src_ipv6_address, .name = "Packet-Src-IPv6-Address", .type = FR_TYPE_IPV6_ADDR, .dict = &dict_freeradius }, - { .out = &attr_packet_src_port, .name = "Packet-Src-Port", .type = FR_TYPE_UINT16, .dict = &dict_freeradius }, { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv4 }, { .out = &attr_dhcp_message_type, .name = "Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4}, { .out = &attr_dhcp_dhcp_server_identifier, .name = "Server-Identifier", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 }, @@ -171,6 +160,7 @@ static int request_init(fr_radius_packet_t **out, fr_pair_list_t *packet_vps, ch * Read the VP's. */ if (fr_pair_list_afrom_file(packet, dict_dhcpv4, packet_vps, fp, &filedone) < 0) { + error: fr_perror("dhcpclient"); fr_radius_packet_free(&packet); if (fp != stdin) fclose(fp); @@ -197,23 +187,16 @@ static int request_init(fr_radius_packet_t **out, fr_pair_list_t *packet_vps, ch } else if (vp->da == attr_packet_type) { packet->code = vp->vp_uint32; - } else if (vp->da == attr_packet_dst_port) { - packet->socket.inet.dst_port = vp->vp_uint16; - - } else if ((vp->da == attr_packet_dst_ip_address) || - (vp->da == attr_packet_dst_ipv6_address)) { - memcpy(&packet->socket.inet.dst_ipaddr, &vp->vp_ip, sizeof(packet->socket.inet.src_ipaddr)); - - } else if (vp->da == attr_packet_src_port) { - packet->socket.inet.src_port = vp->vp_uint16; - - } else if ((vp->da == attr_packet_src_ip_address) || - (vp->da == attr_packet_src_ipv6_address)) { - memcpy(&packet->socket.inet.src_ipaddr, &vp->vp_ip, sizeof(packet->socket.inet.src_ipaddr)); } /* switch over the attribute */ } /* loop over the VP's we read in */ + /* + * Fill in the packet header from attributes, and then + * re-realize the attributes. + */ + fr_packet_pairs_to_packet(packet, packet_vps); + if (fp != stdin) fclose(fp); /* @@ -629,6 +612,9 @@ int main(int argc, char **argv) fr_perror("dhcpclient"); fr_exit(EXIT_FAILURE); } + + packet_global_init(); + fr_strerror_clear(); /* Clear the error buffer */ /* @@ -752,6 +738,8 @@ int main(int argc, char **argv) fr_dhcpv4_global_free(); + packet_global_free(); + if (fr_dict_autofree(dhcpclient_dict) < 0) { fr_perror("dhcpclient"); ret = -1; diff --git a/src/bin/dhcpclient.mk b/src/bin/dhcpclient.mk index 0f90fbae1c3..1bc88bb2131 100644 --- a/src/bin/dhcpclient.mk +++ b/src/bin/dhcpclient.mk @@ -1,5 +1,6 @@ TARGET := dhcpclient$(E) -SOURCES := dhcpclient.c +SOURCES := dhcpclient.c \ + ${top_srcdir}/src/lib/server/packet.c TGT_PREREQS := libfreeradius-dhcpv4$(L) TGT_LDLIBS := $(LIBS)