]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add warnings about requesting a link local address.
authorRoy Marples <roy@marples.name>
Sun, 21 Oct 2007 19:15:23 +0000 (19:15 +0000)
committerRoy Marples <roy@marples.name>
Sun, 21 Oct 2007 19:15:23 +0000 (19:15 +0000)
ChangeLog
client.c
dhcp.c
dhcpcd.c

index e7a543afaf79f1388978326a1f0d384ad1f0317b..4ff01af570cc96e3f80b41718f719b0dd162724b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+Add warnings about requesting a link local address.
 Always add a link-local route unless we're given a non-private
 address by the DHCP server.
 Reduce stack usage by using malloc more.
index 7c4deb3d1ba4423a46e77f81f5eb783e3d352c49..549a673528abefa9e53f0ea892fb2f527392e194 100644 (file)
--- a/client.c
+++ b/client.c
@@ -284,6 +284,11 @@ int dhcp_run (const options_t *options, int *pidfd)
                        return (-1);
                }
 
+               if (! options->daemonised && IN_LINKLOCAL (dhcp->address.s_addr)) {
+                       logger (LOG_ERR, "cannot request a link local address");
+                       return (-1);
+               }
+
 #ifdef THERE_IS_NO_FORK
                if (options->daemonised) {
                        state = STATE_BOUND;
diff --git a/dhcp.c b/dhcp.c
index 94e5510f771e1c2b815a59ed2a65cbfa9a9bf763..cc6e89b91bb225628daa98527088ef18cf6878b1 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -87,9 +87,10 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
        m = (unsigned char *) message;
        p = (unsigned char *) &message->options;
 
-       if (type == DHCP_INFORM ||
+       if ((type == DHCP_INFORM ||
                type == DHCP_RELEASE ||
-               type == DHCP_REQUEST)
+               type == DHCP_REQUEST) &&
+               ! IN_LINKLOCAL (iface->previous_address.s_addr))
        {
                message->ciaddr = iface->previous_address.s_addr;
                from.s_addr = iface->previous_address.s_addr;
@@ -154,13 +155,17 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
                        memcpy (p, &_val.s_addr, 4); \
                        p += 4; \
                }
-               if (dhcp->address.s_addr != iface->previous_address.s_addr &&
-                       type != DHCP_RELEASE)
-                       PUTADDR (DHCP_ADDRESS, dhcp->address);
+               if (IN_LINKLOCAL (dhcp->address.s_addr))
+                       logger (LOG_ERR, "cannot request a link local address");
+               else {
+                       if (dhcp->address.s_addr != iface->previous_address.s_addr &&
+                               type != DHCP_RELEASE)
+                               PUTADDR (DHCP_ADDRESS, dhcp->address);
 
-               if (dhcp->serveraddress.s_addr != 0 && dhcp->address.s_addr !=0 &&
-                       (iface->previous_address.s_addr == 0 || type == DHCP_RELEASE))
-                       PUTADDR (DHCP_SERVERIDENTIFIER, dhcp->serveraddress);
+                       if (dhcp->serveraddress.s_addr != 0 && dhcp->address.s_addr !=0 &&
+                               (iface->previous_address.s_addr == 0 || type == DHCP_RELEASE))
+                               PUTADDR (DHCP_SERVERIDENTIFIER, dhcp->serveraddress);
+               }
 #undef PUTADDR
        }
 
index ac4de0848c7ce0e90a8bb3e10d966732f778e041..e053bf2c3150a2be29c7607fb3fe807a1c07d34c 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -130,8 +130,9 @@ static pid_t read_pid (const char *pidfile)
 static void usage ()
 {
        printf ("usage: "PACKAGE" [-adknpEGHMNRTY] [-c script] [-h hostame] [-i classID]\n"
-               "              [-l leasetime] [-m metric] [-s ipaddress] [-t timeout]\n"
-               "              [-u userclass] [-F none | ptr | both] [-I clientID]\n");
+               "              [-l leasetime] [-m metric] [-r ipaddress] [-s ipaddress]\n"
+                       "              [-t timeout] [-u userclass] [-F none | ptr | both]\n"
+                       "              [-I clientID] <interface>\n");
 }
 
 int main(int argc, char **argv)
@@ -442,6 +443,11 @@ int main(int argc, char **argv)
                        options->keep_address = true;
        }
 
+       if (IN_LINKLOCAL (options->request_address.s_addr)) {
+               logger (LOG_ERR, "you are not allowed to request a link local address");
+               exit (EXIT_FAILURE);
+       }
+
        if (geteuid ()) {
                logger (LOG_ERR, "you need to be root to run "PACKAGE);
                exit (EXIT_FAILURE);