コード例 #1
0
ファイル: dhcpd-dhcpd.c プロジェクト: l3akage/docsis_server
int	leaseQuery( dhcp_message *message ) {
	if ( (message->in_pack.htype != 0) &&
	     (message->in_pack.hlen  != 0) ) {
		/* Search by MAC address */
		my_findMAC( message );

		if (message->lease_type == LEASE_REJECT) return 0;

		if (message->lease_type == LEASE_CPE &&
		    message->cpe_type == CPE_DYNAMIC &&
		    message->lockip == 0 &&
		    message->lease_time < 0 ) {
			// Your Lease has expired. You get a new IP!
			my_DeleteLease( message );
			message->lease_type = LEASE_NOT_FOUND;
		}

		if (message->lease_type == LEASE_NOT_FOUND ) {
			send_Query_NAK( message );
		} else {
			send_Query_ACK( message );
		}
		return 1;
	} else if (message->in_pack.ciaddr != 0) {
		/* Search by IP -- The majority of requests from Cisco CMTS*/
		my_findIP( message, FIND_CIADDR );

		if (message->lease_type == LEASE_REJECT) return 0;

		if (message->lease_type == LEASE_CPE &&
		    message->cpe_type == CPE_DYNAMIC &&
		    message->lockip == 0 &&
		    message->lease_time < 0 ) {
			// Your Lease has expired. You get a new IP!
			my_DeleteLease( message );
			message->lease_type = LEASE_NOT_FOUND;
		}

		if (message->lease_type == LEASE_NOT_FOUND ) {
			send_Query_NAK( message );
		} else {
			send_Query_ACK( message );
		}
		return 1;
	} else if (message->in_opts.client_ident_len > 0) {
		/* Search by dhcp-client-ident flag */
		/* Im not sure how I will do this. Log it */
		char	tmpstr[4096];
		cv_macaddr( message->in_opts.client_ident, tmpstr,
			    message->in_opts.client_ident_len );
		my_syslog( LOG_INFO, "DHCPlq - dhcp-client-ident search -%s-", tmpstr );
		return 0;
	}
}
コード例 #2
0
void DecodeOptions( dhcp_message *message ) {
	packet_opts	*po;
	struct in_addr	s_ip;
	u_int8_t	*ino, *maxo;
	u_int8_t	kT, kL, kRL;
	int		flag = 1;
	char		*p;

	po = &(message->in_opts);
	ino = message->in_pack.options;
	maxo = ino + MAX_OPTIONS_LENGTH;

	while( flag ) {
		if (ino >= maxo) { flag = 0; continue; }
		kT = *ino; ino++; // DHCP-Option
		kL = *ino; ino++; // DHCP-Option-Length
		kRL = kL;
		if (kRL > (maxo - ino)) { kRL = (maxo - ino); }
		//fprintf(stderr,"DEBUG: OPTION: %d LENGTH: %d\n", kT, kL);
		switch( kT ) {
		case 0x00:
			flag = 0;
			break;

		case 0x0c:	/*  host-name  */
			memcpy( po->host_name, ino, kRL ); ino += kL;
			po->host_name_len = kRL;
			for( p = po->host_name; *p; p++ ) {
				if ( (*p < 48 ) ||
				     (*p >= 58 && *p <= 64) ||
				     (*p >= 91 && *p <= 96) ||
				     (*p >= 123 ) ) {
					*p = '-';
				}
			}
			break;

		case 0x2b:	/*  vendor-specific-information  */ {
                        u_int8_t        mmT, mmL, mmRL, mmCK;
			
			po->vsi_len = kRL;
                        mmCK = kRL;
                        while (mmCK > 0) {
                        	mmT = *ino; ino++; mmCK--; //DHCP-SubOption
                        	mmL = *ino; ino++; mmCK--; //DHCP-SubOptionLength
                      		mmRL = mmL;

                        	if (mmRL > (maxo - ino)) { mmRL = (maxo - ino); }
		//		fprintf(stderr,"DEBUG: OPTION: %d SUBOPTION: %d LENGTH: %d\n", kT, mmT, mmL);
                                switch( mmT ) {
                                case 0x04:              // Serialnumber
					memcpy( po->vsi_serialno, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"SERIAL: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_serialno);
                                        break;
                                case 0x05:              // HW-Version
					memcpy( po->vsi_hwver, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"HW-Version: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_hwver);
                                        break;
                                case 0x06:              // SW-Version
					memcpy( po->vsi_swver, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"SW-Version: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_swver);
                                        break;
                                case 0x07:              // Bootrom
					memcpy( po->vsi_bootrom, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"BOOTROM: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_bootrom);
                                        break;
                                case 0x08:              // Organizationally Uniqe Identifier
					memcpy( po->vsi_oui, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"OUI: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_oui);
                                        break; 
                                case 0x09:              // Modelnumber
					memcpy( po->vsi_model, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"MODEL: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_model);
                                        break;
                                case 0x0a:              // Vendorname
					memcpy( po->vsi_vendor, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                        //fprintf(stderr,"VENDOR: %d %d %d %s\n", mmT, mmL, mmRL, po->vsi_vendor);
                                        break;
	                         default:
       		                          ino += mmL;  mmCK -= mmL;
                                 	  break;
                                        }
				}
			}
			break;

		case 0x32:	/*  dhcp-requested-address  */
			memcpy( &(po->request_addr), ino, 4 ); ino += kL;
			s_ip.s_addr = po->request_addr;
			strcpy( po->s_request_addr, inet_ntoa( s_ip ) );
			break;

		case 0x35:	/*  dhcp-message-type  */
			po->message_type = *ino; ino++; break;

		case 0x36:	/*  dhcp-server-identifier  */
			memcpy( &(po->server_ident), ino, 4 ); ino += kL; break;
			break;

		case 0x37:	/*  dhcp-parameter-request-list  */
			memcpy( po->request_list, ino, kRL ); ino += kL;
			po->request_list_len = kRL;
			break;

		case 0x39:	/*  dhcp-max-message-size  */
			memcpy( po->request_list, ino, kRL ); ino += kL; break;

		case 0x3c:	/*  vendor-class-identifier  */
			memcpy( po->vendor_ident, ino, kRL ); ino += kL;
			po->vendor_ident_len = kRL;
			po->docsis_modem = 0;
			if ( memcmp(po->vendor_ident, "docsis", 6) == 0) {
				po->docsis_modem = 1;
				Parse_Modem_Caps( message );
			}
			if ( memcmp(po->vendor_ident, "pktc", 4) == 0) { /* MTA MB-DOPS */
				po->docsis_modem = 1;
				Parse_MTA_Caps( message );
			}
			break;

		case 0x3d:	/*  dhcp-client-identifier  */
			memcpy( po->client_ident, ino, kRL ); ino += kL;
			po->client_ident_len = kRL;
			break;

		case 0x51:	/*  fqdn  */
			memcpy( po->fqdn, ino, kRL ); ino += kL;
			po->fqdn_len = kRL;
			break;

		case 0x52:	/*  relay-agent-information  */
                        {
                                u_int8_t        mmT, mmL, mmRL, mmCK;

                                po->agent_mac_len = kRL;
                                mmCK = kRL;
                                while (mmCK > 0) {

                                        mmT = *ino; ino++; mmCK--;
                                        mmL = *ino; ino++; mmCK--;
                                        mmRL = mmL;
                                        if (mmRL > (maxo - ino)) { mmRL = (maxo - ino); }
				        //fprintf(stderr,"DEBUG: OPTION: %d SUBOPTION: %d LENGTH: %d\n", kT, mmT, mmL);
					switch( mmT ) {
					case 0x01:		// agent id from Cisco CMTS
                                                memcpy( po->agentid, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                                po->agentid_len = mmRL;
                                                cv_macaddr( po->agentid, po->s_agentid, mmRL );
                                                //fprintf(stderr,"AGENTID: %d %d %d %s -- \n", mmT, mmL, mmRL, po->s_agentid );
						break;
                                        case 0x02:		// CM mac address
                                                memcpy( po->modem_mac, ino, mmRL ); ino += mmL; mmCK -= mmL;
                                                po->modem_mac_len = mmRL;
                                                cv_macaddr( po->modem_mac, po->s_modem_mac, mmRL );
                                                cv_mac2num( &(po->b_modem_mac), po->modem_mac );
                                                strcpy( message->s_modem_macaddr, po->s_modem_mac );
                                                message->b_modem_macaddr = po->b_modem_mac;
                                                memcpy( message->modem_macaddr, po->modem_mac, 6 );
                                                //fprintf(stderr,"AGENTMAC: %d %d %d %s\n", mmT, mmL, mmRL, po->s_modem_mac );
						break;
					case 0x2b:		// CM IP from Moto
						ino += mmL;  mmCK -= mmL;
						break;
                                        default:
						ino += mmL;  mmCK -= mmL;
						break;
					}
                                }
                        }
			break;

		case 0xff:
			flag = 0;
			break;
		default:
			ino += kL;
			break;
		}
	}
}