]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add client_port to proto_dhcpv4_udp
authorNick Porter <nick@portercomputing.co.uk>
Mon, 24 Jun 2024 13:46:06 +0000 (14:46 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Mon, 24 Jun 2024 13:46:06 +0000 (14:46 +0100)
raddb/sites-available/dhcp
src/listen/dhcpv4/proto_dhcpv4_udp.c

index d1c16a0321ba9e04a6176828a771a2472f62b991..58e03654068c218f817377bb0a25832a57fbab06 100644 (file)
@@ -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
 
index 8492b065bbfea3b6560fcd143c0ebb16fa8cd225..8364c89ba690b8b2488d07d0dae7b691bab2f340 100644 (file)
@@ -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.
                 *