/* 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)
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;
/* 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 */
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);
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) {
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:
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);