Browse Source

fixed DHCPv6 options processing

tags/v1.0.0
Pascal Gloor 5 years ago
parent
commit
39ec8125c2
1 changed files with 33 additions and 29 deletions
  1. 33
    29
      dhcp_protect.c

+ 33
- 29
dhcp_protect.c View File

} }
} }


if ( conf->debug ) printf("remoteidlen=%i\n",remoteidlen);

if ( remoteidlen>0 ) { if ( remoteidlen>0 ) {
if ( conf->debug ) { if ( conf->debug ) {
int i; int i;
} }


void dp_dhcpv6_check(dp_conf *conf, unsigned char *pkt, int pktlen, int offset, unsigned char **remoteid, int *remoteidlen) { void dp_dhcpv6_check(dp_conf *conf, unsigned char *pkt, int pktlen, int offset, unsigned char **remoteid, int *remoteidlen) {
uint8_t msgtype = (uint8_t)pkt[offset];


while(offset<pktlen) {
uint8_t msgtype = (uint8_t)pkt[offset];
if ( conf->debug ) printf("offset=%i\n",offset);


switch(msgtype) {
case 11: // RELAY-FORW
case 12: // RELAY-REPL
offset += 2 + 16 + 16; // msg-type, hop-count, link-addr, peer-addr
break;
default: // all other msgtypes
offset += 2; // msg-type, hop-count
}
switch(msgtype) {
case 12: // RELAY-FORW
case 13: // RELAY-REPL
offset += 2 + 16 + 16; // msg-type, hop-count, link-addr, peer-addr
if ( conf->debug ) printf("this is a relay msg\n");
break;
default: // all other msgtypes
offset += 2; // msg-type, hop-count
}


while(offset+4<=pktlen) {
uint16_t code = ntohs((uint16_t)pkt[offset]);
uint16_t len = ntohs((uint16_t)pkt[offset+2]);
if ( conf->debug ) printf("offset=%i\n",offset);


offset+=4;
while(offset+4<=pktlen) {
uint16_t code = ntohs(*(uint16_t*)(pkt+offset));
uint16_t len = ntohs(*(uint16_t*)(pkt+offset+2));


if ( code == 9 ) { // relay message
offset += 4;
continue;
}
if ( conf->debug ) printf("code %i len %i\n", code, len);


if ( code == 1 ) { // Client identifier / DUID
// make sure there's enough space
if ( offset + len <= pktlen ) {
*remoteid = pkt+offset;
*remoteidlen = len;
break;
}
}
offset+=len;
offset+=4;

if ( code == 9 ) { // relay message
if ( conf->debug ) printf("option 9, relay msg\n");
offset+=4;
continue;
} }


if ( *remoteidlen>0 )
break;
if ( code == 1 ) { // Client identifier / DUID
// make sure there's enough space
if ( offset + len <= pktlen ) {
*remoteid = pkt+offset;
*remoteidlen = len;
break;
}
}
offset+=len;
} }
} }



Loading…
Cancel
Save