From: Nick Porter Date: Mon, 24 Jun 2024 13:46:06 +0000 (+0100) Subject: Add client_port to proto_dhcpv4_udp X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdaadd62f01fed107b3ddb12bb5ac6008fdbd0e9;p=thirdparty%2Ffreeradius-server.git Add client_port to proto_dhcpv4_udp --- diff --git a/raddb/sites-available/dhcp b/raddb/sites-available/dhcp index d1c16a0321b..58e03654068 100644 --- a/raddb/sites-available/dhcp +++ b/raddb/sites-available/dhcp @@ -56,6 +56,14 @@ listen { # This is also the destination port when sending to a giaddr. port = 6700 + # The port to which server -> client messages should be sent. + # This should be 68 on a production network, though other ports + # can be useful for testing. + # + # If this is not set then server -> client replies will be sent + # to the source port of the client -> server request. + client_port = 68 + # Interface name we are listening on. See comments above. # interface = lo0 diff --git a/src/listen/dhcpv4/proto_dhcpv4_udp.c b/src/listen/dhcpv4/proto_dhcpv4_udp.c index 8492b065bbf..8364c89ba69 100644 --- a/src/listen/dhcpv4/proto_dhcpv4_udp.c +++ b/src/listen/dhcpv4/proto_dhcpv4_udp.c @@ -61,6 +61,7 @@ typedef struct { uint32_t max_attributes; //!< Limit maximum decodable attributes. uint16_t port; //!< Port to listen on. + uint16_t client_port; //!< Client port to reply to. bool broadcast; //!< whether we listen for broadcast packets @@ -95,6 +96,7 @@ static const conf_parser_t udp_listen_config[] = { { FR_CONF_OFFSET("port_name", proto_dhcpv4_udp_t, port_name) }, { FR_CONF_OFFSET("port", proto_dhcpv4_udp_t, port) }, + { FR_CONF_OFFSET("client_port", proto_dhcpv4_udp_t, client_port) }, { FR_CONF_OFFSET_IS_SET("recv_buff", FR_TYPE_UINT32, 0, proto_dhcpv4_udp_t, recv_buff) }, { FR_CONF_OFFSET("broadcast", proto_dhcpv4_udp_t, broadcast) } , @@ -319,6 +321,16 @@ static ssize_t mod_write(fr_listen_t *li, void *packet_ctx, UNUSED fr_time_t req packet->opcode = 2; /* server message */ + /* + * If the client port is specified, use it. + * + * RFC 2131 page 23. + * + * "DHCP messages from a server to a client are sent + * to the 'DHCP client' port (68)" + */ + if (inst->client_port) socket.inet.dst_port = inst->client_port; + /* * NAKs are broadcast when there's no giaddr. *