dhcpc.c: Added support for relay server parameter.
authorMartin Lewis <martin.lewis.x84@gmail.com>
Mon, 10 Jun 2019 15:06:17 +0000 (17:06 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 11 Jun 2019 15:18:28 +0000 (17:18 +0200)
Resolved a TODO by adding support for gateway_nip parameter.

function                                             old     new   delta
udhcp_run_script                                     792     835     +43

Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/dhcpc.c

index 739870bee8eda87d0a9822249635fb004fa69156..80391f6063abf68f17fd6b63b71699ff1b3152dd 100644 (file)
@@ -449,15 +449,16 @@ static char **fill_envp(struct dhcp_packet *packet)
 
        memset(found_opts, 0, sizeof(found_opts));
 
-       /* We need 6 elements for:
+       /* We need 7 elements for:
         * "interface=IFACE"
         * "ip=N.N.N.N" from packet->yiaddr
+        * "giaddr=IP" from packet->gateway_nip (unless 0)
         * "siaddr=IP" from packet->siaddr_nip (unless 0)
         * "boot_file=FILE" from packet->file (unless overloaded)
         * "sname=SERVER_HOSTNAME" from packet->sname (unless overloaded)
         * terminating NULL
         */
-       envc = 6;
+       envc = 7;
        /* +1 element for each option, +2 for subnet option: */
        if (packet) {
                /* note: do not search for "pad" (0) and "end" (255) options */
@@ -493,9 +494,7 @@ static char **fill_envp(struct dhcp_packet *packet)
         * uint16_t flags;  // only one flag so far: bcast. Never set by server
         * uint32_t ciaddr; // client IP (usually == yiaddr. can it be different
         *                  // if during renew server wants to give us different IP?)
-        * uint32_t gateway_nip; // relay agent IP address
         * uint8_t chaddr[16]; // link-layer client hardware address (MAC)
-        * TODO: export gateway_nip as $giaddr?
         */
        /* Most important one: yiaddr as $ip */
        *curr = xmalloc(sizeof("ip=255.255.255.255"));
@@ -507,6 +506,12 @@ static char **fill_envp(struct dhcp_packet *packet)
                sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip);
                putenv(*curr++);
        }
+       if (packet->gateway_nip) {
+               /* IP address of DHCP relay agent to use in bootstrap */
+               *curr = xmalloc(sizeof("giaddr=255.255.255.255"));
+               sprint_nip(*curr, "giaddr=", (uint8_t *) &packet->gateway_nip);
+               putenv(*curr++);
+       }
        if (!(overload & FILE_FIELD) && packet->file[0]) {
                /* watch out for invalid packets */
                *curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file);