]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Support RFC 3361 SIP Servers.
authorRoy Marples <roy@marples.name>
Wed, 18 Jul 2007 14:22:02 +0000 (14:22 +0000)
committerRoy Marples <roy@marples.name>
Wed, 18 Jul 2007 14:22:02 +0000 (14:22 +0000)
ChangeLog
Makefile
client.c
dhcp.c
dhcp.h
info.c

index 12bedab61a07af598c54acc92b17cf452c853389..62fbfa6bf06d1e6ce2512296a2c14636d7e8fa1c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+Support RFC 3361 SIP Servers.
 We now do ARP checking by default as recommended by RFC 2131.
 Add RFC 3927 (aka IPV4LL aka APIPA) support by default.
 Suport DHCP option (52) overload.
index 8323d5b1a44943448d1f3d0fb56a1205ed05ae0d..56e1efa98ff62598c0c3def1b69ef7592ddfec0f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = 3.1.0_pre5
+VERSION = 3.1.0_pre6
 CFLAGS ?= -O2 -pipe
 
 # Should work for both GNU make and BSD make
index 9ba63314683b59b2f4b735fd7012d87e985fbf9c..4d55e6c54afb007b5d4742e379113f4a629af706 100644 (file)
--- a/client.c
+++ b/client.c
@@ -410,7 +410,9 @@ int dhcp_run (const options_t *options, int *pidfd)
                                                free_dhcp (dhcp);
                                                memset (dhcp, 0, sizeof (dhcp_t));
 #ifdef ENABLE_INFO
-                                               if (! get_old_lease (options, iface, dhcp, &timeout)) {
+                                               if (! options->test && 
+                                                       ! get_old_lease (options, iface, dhcp, &timeout))
+                                               {
                                                        if (options->dolastlease) {
                                                                retval = EXIT_FAILURE;
                                                                goto eexit;
@@ -422,9 +424,10 @@ int dhcp_run (const options_t *options, int *pidfd)
 #endif
 
 #ifdef ENABLE_IPV4LL
-                                               if (! dhcp->address.s_addr ||
-                                                       (! IN_LINKLOCAL (dhcp->address.s_addr) &&
-                                                        ! options->dolastlease))
+                                               if (! options->test &&
+                                                       (! dhcp->address.s_addr ||
+                                                        (! IN_LINKLOCAL (dhcp->address.s_addr) &&
+                                                         ! options->dolastlease)))
                                                {
                                                        logger (LOG_INFO, "probing for an IPV4LL address");
                                                        free_dhcp (dhcp);
diff --git a/dhcp.c b/dhcp.c
index b095d2f26c4e46cd00c12f0c42f95769314bb488..bbdc1c8dda819a27666506a86e7292d1b0b6b00d 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
 #include <netinet/in.h>
 #include <net/if_arp.h>
 
+#include <arpa/inet.h>
+
 #include <errno.h>
 #include <limits.h>
 #include <math.h>
+#include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -171,7 +174,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
                   RFC2131 Section 3.5 states that the REQUEST must include the list
                   from the DISCOVER message, so I think we can safely do this. */
 
-               if (type == DHCP_DISCOVER)
+               if (type == DHCP_DISCOVER && ! options->test)
                        *p++ = DHCP_DNSSERVER;
                else {
                        if (type != DHCP_INFORM) {
@@ -194,11 +197,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
                        *p++ = DHCP_NTPSERVER;
                        *p++ = DHCP_MTU;
                        *p++ = DHCP_ROOTPATH;
-                       /* These parameters were requested by dhcpcd-2.0 and earlier
-                          but we never did anything with them */
-                       /*    *p++ = DHCP_DEFAULTIPTTL;
-                        *p++ = DHCP_MASKDISCOVERY;
-                        *p++ = DHCP_ROUTERDISCOVERY; */
+                       *p++ = DHCP_SIPSERVER;
                }
 
                *n_params = p - n_params - 1;
@@ -356,7 +355,7 @@ static unsigned int decode_search (const unsigned char *p, int len, char *out)
 
 /* Add our classless static routes to the routes variable
  * and return the last route set */
-static route_t *decodeCSR(const unsigned char *p, int len)
+static route_t *decode_CSR(const unsigned char *p, int len)
 {
        const unsigned char *q = p;
        int cidr;
@@ -459,6 +458,48 @@ static bool dhcp_add_address(address_t **address, const unsigned char *data, int
        return (true);
 }
 
+static char *decode_sipservers (const unsigned char *data, int length)
+{
+       char *sip = NULL;
+       char *p;
+       const char encoding = *data++;
+       struct in_addr addr;
+       int len;
+
+       length--;
+
+       switch (encoding) {
+               case 0:
+                       if ((len = decode_search (data, length, NULL)) > 0) {
+                               sip = xmalloc (len);
+                               decode_search (data, length, sip);
+                       }
+                       break;
+
+               case 1:
+                       if (length % 4 != 0) {
+                               logger (LOG_ERR, "invalid length %d for option 120", length + 1);
+                               break;
+                       }
+                       len = ((length / 4) * (4 * 4)) + 1;
+                       sip = p = xmalloc (len);
+                       while (length != 0) {
+                               memcpy (&addr.s_addr, data, 4);
+                               data += 4;
+                               p += snprintf (p, len - (p - sip), "%s ", inet_ntoa (addr));
+                               length -= 4;
+                       }
+                       *--p = '\0';
+                       break;
+
+               default:
+                       logger (LOG_ERR, "unknown sip encoding %d", *data);
+                       break;
+       }
+
+       return (sip);
+}
+
 int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message)
 {
        const unsigned char *p = message->options;
@@ -510,6 +551,12 @@ parse_start:
 
                length = *p++;
 
+               if (option != DHCP_PAD && length == 0) {
+                       logger (LOG_ERR, "option %d has zero length", option);
+                       retval = -1;
+                       goto eexit;
+               }
+
                if (p + length >= end) {
                        logger (LOG_ERR, "dhcp option exceeds message length");
                        retval = -1;
@@ -646,7 +693,12 @@ parse_start:
                        case DHCP_CSR:
                                MIN_LENGTH (5);
                                free_route (csr);
-                               csr = decodeCSR (p, length);
+                               csr = decode_CSR (p, length);
+                               break;
+
+                       case DHCP_SIPSERVER:
+                               free (dhcp->sipservers);
+                               dhcp->sipservers = decode_sipservers (p, length);
                                break;
 
                        case DHCP_STATICROUTE:
diff --git a/dhcp.h b/dhcp.h
index 3f5b9cda23553154d98c99af0968bccabf2c94ca..e47113beeb46e791b1227f5eac225f827a07db4a 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -96,6 +96,7 @@ enum DHCP_OPTIONS
        DHCP_USERCLASS              = 77,  /* RFC 3004 */
        DHCP_FQDN                   = 81,
        DHCP_DNSSEARCH              = 119, /* RFC 3397 */
+       DHCP_SIPSERVER              = 120, /* RFC 3361 */
        DHCP_CSR                    = 121, /* RFC 3442 */
        DHCP_END                    = 255
 };
@@ -151,6 +152,8 @@ typedef struct dhcp_t
        address_t *nisservers;
        char *nisdomain;
 
+       char *sipservers;
+
        char *message;
        char *rootpath;
 
diff --git a/info.c b/info.c
index 6726a2893a85be94e1f29357762802d49fb29e51..316a1362fc264de9569222bf0178eb18f5b0f251 100644 (file)
--- a/info.c
+++ b/info.c
@@ -173,6 +173,9 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp,
        if (dhcp->rootpath)
                fprintf (f, "ROOTPATH='%s'\n", cleanmetas (dhcp->rootpath));
 
+       if (dhcp->sipservers)
+               fprintf (f, "SIPSERVERS='%s'\n", cleanmetas (dhcp->sipservers));
+
        if (dhcp->serveraddress.s_addr)
                fprintf (f, "DHCPSID='%s'\n", inet_ntoa (dhcp->serveraddress));
        if (dhcp->servername[0])