X-Git-Url: http://git.rot13.org/?p=bcm963xx.git;a=blobdiff_plain;f=userapps%2Fopensource%2Fudhcp%2Fdhcpd.c;h=6e00c5f9829f558c4a2b0080562bb1d301728959;hp=2d4438698e0448391ceb8fe59454eeec9705d5fb;hb=57a096f051259ceaefd5977f30d269884e1dd248;hpb=9887430fc6b7c0f8eb8e81de2bfe3bba12d8d4a1 diff --git a/userapps/opensource/udhcp/dhcpd.c b/userapps/opensource/udhcp/dhcpd.c index 2d443869..6e00c5f9 100755 --- a/userapps/opensource/udhcp/dhcpd.c +++ b/userapps/opensource/udhcp/dhcpd.c @@ -54,7 +54,12 @@ /* 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) @@ -87,7 +92,8 @@ int main(int argc, char *argv[]) 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; @@ -98,6 +104,10 @@ int main(int argc, char *argv[]) /* 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 */ @@ -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); + // 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); @@ -179,6 +192,7 @@ int main(int argc, char *argv[]) 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) { @@ -229,9 +243,41 @@ int main(int argc, char *argv[]) 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: @@ -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); - if (requested) memcpy(&requested_align, requested, 4); if (server_id) memcpy(&server_id_align, server_id, 4);