mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
improve IPCP, add IPV6CP and support for IPv6
This commit is contained in:
1 parent
ba47e29c28
commit
1c7be6d543
9 files changed
+347
-224
No files matched your search
+20
-14
@@ -869,6 +869,10 @@ static void tx_ndp_ns(struct mg_tcpip_if *ifp, uint64_t *ip_dst,
|
||||
uint64_t ip_mcast[2] = {0, 0};
|
||||
uint8_t *l2 = l2_addr;
|
||||
|
||||
if (ifp->l2type == MG_TCPIP_L2_PPP || ifp->l2type == MG_TCPIP_L2_PPPoE) {
|
||||
MG_DEBUG(("SKIP NS for %M", mg_print_ip6, ip_dst));
|
||||
return;
|
||||
}
|
||||
memset(payload, 0, sizeof(payload));
|
||||
memcpy(payload + 4, ip_dst, 16);
|
||||
if (mcast) {
|
||||
@@ -988,8 +992,8 @@ static void rx_ndp_ra(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
||||
// fill prefix and global
|
||||
if (gotprefix && !fill_global(ifp, prefix, prefix_len)) return;
|
||||
ifp->gw6[0] = pkt->ip6->src[0], ifp->gw6[1] = pkt->ip6->src[1];
|
||||
if (gotl2addr) {
|
||||
memcpy(ifp->gw6mac, l2, sizeof(ifp->gw6mac));
|
||||
if (gotl2addr) memcpy(ifp->gw6mac, l2, sizeof(ifp->gw6mac));
|
||||
if (gotl2addr || ifp->l2type == MG_TCPIP_L2_PPP || ifp->l2type == MG_TCPIP_L2_PPPoE) {
|
||||
ifp->state6 = MG_TCPIP_STATE_READY;
|
||||
ifp->gw6_ready = true;
|
||||
}
|
||||
@@ -1040,6 +1044,10 @@ static void rx_icmp6(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
||||
case 136: // Neighbor Advertisement
|
||||
rx_ndp_na(ifp, pkt);
|
||||
break;
|
||||
default:
|
||||
if (mg_log_level >= MG_LL_VERBOSE)
|
||||
mg_hexdump(pkt->icmp6, pkt->pay.len > 16 ? 16 : pkt->pay.len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1050,7 +1058,7 @@ static void onstate6change(struct mg_tcpip_if *ifp) {
|
||||
if (ifp->l2type == MG_TCPIP_L2_ETH) // TODO(): print other l2
|
||||
MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac));
|
||||
} else if (ifp->state6 == MG_TCPIP_STATE_IP) {
|
||||
if (ifp->gw6[0] != 0 || ifp->gw6[1] != 0)
|
||||
if ((ifp->gw6[0] != 0 || ifp->gw6[1] != 0) && (ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE))
|
||||
tx_ndp_ns(ifp, ifp->gw6, NULL); // unsolicited GW hwaddr resolution
|
||||
} else if (ifp->state6 == MG_TCPIP_STATE_UP) {
|
||||
MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll));
|
||||
@@ -1844,8 +1852,16 @@ static void mg_ip6_poll(struct mg_tcpip_if *ifp, bool s1) {
|
||||
static void mg_ip6_link(struct mg_tcpip_if *ifp, bool drv_up, bool l2_up) {
|
||||
bool cur_drv = (ifp->state6 != MG_TCPIP_STATE_DOWN);
|
||||
bool cur_l2 = (ifp->state6 >= MG_TCPIP_STATE_UP);
|
||||
if (!up && ifp->enable_slaac) ifp->ip6[0] = ifp->ip6[1] = 0;
|
||||
if (drv_up != cur_drv || l2_up != cur_l2) { // link/L2 state has changed
|
||||
if (l2_up && ifp->ip6ll[0] == 0 && ifp->ip6ll[1] == 0) { // gen ll address
|
||||
uint8_t px[8] = {0xfe, 0x80, 0, 0, 0, 0, 0, 0}; // RFC-4291 2.5.6
|
||||
mg_l2_genip6(ifp->l2type, ifp->ip6ll, 64, ifp->mac);
|
||||
memcpy(ifp->ip6ll, px, 8); // RFC-4291 2.5.4
|
||||
} // just got our link local address if we didn't have one.
|
||||
// If static configuration is used, global addresses,
|
||||
// prefix length, and gw are already filled at this point.
|
||||
if (ifp->ip6[0] == 0 && ifp->ip6[1] == 0) ifp->enable_slaac = true;
|
||||
if (!l2_up && ifp->enable_slaac) ifp->ip6[0] = ifp->ip6[1] = 0;
|
||||
ifp->state6 = !drv_up ? MG_TCPIP_STATE_DOWN
|
||||
: !l2_up ? MG_TCPIP_STATE_LINK_UP
|
||||
: ifp->enable_slaac || ifp->ip6[0] == 0 ? MG_TCPIP_STATE_UP
|
||||
@@ -2011,16 +2027,6 @@ void mg_tcpip_init(struct mg_mgr *mgr, struct mg_tcpip_if *ifp) {
|
||||
mg_random(&ifp->eport, sizeof(ifp->eport)); // Random from 0 to 65535
|
||||
ifp->eport |= MG_EPHEMERAL_PORT_BASE; // Random from
|
||||
// MG_EPHEMERAL_PORT_BASE to 65535
|
||||
#if MG_ENABLE_IPV6
|
||||
if (ifp->ip6ll[0] == 0 && ifp->ip6ll[1] == 0) { // gen link-local address
|
||||
uint8_t px[8] = {0xfe, 0x80, 0, 0, 0, 0, 0, 0}; // RFC-4291 2.5.6
|
||||
mg_l2_genip6(ifp->l2type, ifp->ip6ll, 64, ifp->mac);
|
||||
memcpy(ifp->ip6ll, px, 8); // RFC-4291 2.5.4
|
||||
} // just got our link local address if we didn't.
|
||||
// If static configuration is used, global addresses,
|
||||
// prefix length, and gw are already filled at this point.
|
||||
if (ifp->ip6[0] == 0 && ifp->ip6[1] == 0) ifp->enable_slaac = true;
|
||||
#endif
|
||||
if (ifp->tx.buf == NULL || ifp->recv_queue.buf == NULL) MG_ERROR(("OOM"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user