www.usr.com/support/gpl/USR9107_release.1.4.tar.gz
[bcm963xx.git] / userapps / opensource / udhcp / dhcpd.c
index 2d44386..6e00c5f 100755 (executable)
 /* globals */
 struct dhcpOfferedAddr *leases;
 struct server_config_t server_config;
 /* globals */
 struct dhcpOfferedAddr *leases;
 struct server_config_t server_config;
+// BRCM_begin
+struct dhcpOfferedAddr *declines;
+struct vendor_id_config_t vendor_id_config[MAX_VENDOR_IDS];
 
 
+static int vendor_id_cfg = 0;
+// BRCM_end
 
 /* Exit and cleanup */
 static void exit_server(int retval)
 
 /* Exit and cleanup */
 static void exit_server(int retval)
@@ -87,7 +92,8 @@ int main(int argc, char *argv[])
        int bytes, retval;
        struct dhcpMessage packet;
        unsigned char *state;
        int bytes, retval;
        struct dhcpMessage packet;
        unsigned char *state;
-       char *server_id, *requested, *hostname;
+        // BRCM added vendorid
+       char *server_id, *requested, *hostname, *vendorid = NULL;
        u_int32_t server_id_align, requested_align;
        unsigned long timeout_end;
        struct option_set *option;
        u_int32_t server_id_align, requested_align;
        unsigned long timeout_end;
        struct option_set *option;
@@ -98,6 +104,10 @@ int main(int argc, char *argv[])
        /* server ip addr */
        int fd = -1;
        struct ifreq ifr;
        /* server ip addr */
        int fd = -1;
        struct ifreq ifr;
+       // BRCM_begin
+        int i = 0;
+        char opt_vend[64];
+        // BRCM_end
 
        argc = argv[0][0]; /* get rid of some warnings */
        
 
        argc = argv[0][0]; /* get rid of some warnings */
        
@@ -120,6 +130,9 @@ int main(int argc, char *argv[])
        memset(leases, 0, sizeof(struct dhcpOfferedAddr) * server_config.max_leases);
        read_leases(server_config.lease_file);
 
        memset(leases, 0, sizeof(struct dhcpOfferedAddr) * server_config.max_leases);
        read_leases(server_config.lease_file);
 
+        // BRCM
+       declines = malloc(sizeof(struct dhcpOfferedAddr));
+
        if((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) {
                ifr.ifr_addr.sa_family = AF_INET;
                strcpy(ifr.ifr_name, server_config.interface);
        if((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) {
                ifr.ifr_addr.sa_family = AF_INET;
                strcpy(ifr.ifr_name, server_config.interface);
@@ -179,6 +192,7 @@ int main(int argc, char *argv[])
 
        while(1) { /* loop until universe collapses */
                 //BRCM_begin
 
        while(1) { /* loop until universe collapses */
                 //BRCM_begin
+                int declined = 0;
                 if (server_socket < 0) {
                      server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface);
                      if(server_socket < 0) {
                 if (server_socket < 0) {
                      server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface);
                      if(server_socket < 0) {
@@ -229,9 +243,41 @@ int main(int argc, char *argv[])
                switch (state[0]) {
                case DHCPDISCOVER:
                        DEBUG(LOG_INFO,"received DISCOVER");
                switch (state[0]) {
                case DHCPDISCOVER:
                        DEBUG(LOG_INFO,"received DISCOVER");
-                       
-                       if (sendOffer(&packet) < 0) {
-                               LOG(LOG_ERR, "send OFFER failed -- ignoring");
+                       //BRCM_begin
+                        vendorid = get_option(&packet, DHCP_VENDOR);
+
+                        /* Check the vendor ID with the configured vendor ID */
+                        if (read_vendor_id_config(DHCPD_VENDORID_CONF_FILE) == 1) {
+                                vendor_id_cfg = 1;
+                        }
+                        if (vendor_id_cfg) {
+                                int i = 0;
+                                for (i = 0; i < MAX_VENDOR_IDS; i++) {
+                                        if (strlen(vendor_id_config[i].vendorid) == 0) {
+                                                continue;
+                                        }
+                                        memset(opt_vend, 0, 64);
+                                        memcpy(opt_vend, vendorid, strlen(vendor_id_config[i].vendorid) - 1);
+                                        if (strncmp(opt_vend, vendor_id_config[i].vendorid,
+                                                strlen(vendor_id_config[i].vendorid) - 1) == 0) {
+                                                memset(declines, 0, sizeof(struct dhcpOfferedAddr));
+                                                memcpy(declines->chaddr, packet.chaddr, 16);
+                                                memcpy(declines->vendorid, vendorid, 64);
+                                                /* Write this to the decline file */
+                                                write_decline(0);
+                                                /* remain silent */
+                                                sendNAK(&packet);
+                                                declined = 1;
+                                                break;
+                                        }
+                                }
+                        }
+                       // BRCM_end
+
+                        if (!declined) {
+                               if (sendOffer(&packet) < 0) {
+                                       LOG(LOG_ERR, "send OFFER failed -- ignoring");
+                               }
                        }
                        break;                  
                case DHCPREQUEST:
                        }
                        break;                  
                case DHCPREQUEST:
@@ -240,7 +286,6 @@ int main(int argc, char *argv[])
                        requested = get_option(&packet, DHCP_REQUESTED_IP);
                        server_id = get_option(&packet, DHCP_SERVER_ID);
                        hostname = get_option(&packet, DHCP_HOST_NAME);
                        requested = get_option(&packet, DHCP_REQUESTED_IP);
                        server_id = get_option(&packet, DHCP_SERVER_ID);
                        hostname = get_option(&packet, DHCP_HOST_NAME);
-
                        if (requested) memcpy(&requested_align, requested, 4);
                        if (server_id) memcpy(&server_id_align, server_id, 4);
                
                        if (requested) memcpy(&requested_align, requested, 4);
                        if (server_id) memcpy(&server_id_align, server_id, 4);