A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
ip6/icmp/ndp/ra.c@119:8e1a7805b801, 2019-01-29 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Jan 29 15:07:14 2019 +0000
- Revision:
- 119:8e1a7805b801
- Parent:
- 101:a677d8aee6dd
- Child:
- 137:cf6e7db0e985
Updated NDP module to backoff its requests in not successful.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 61:aad055f1b0d1 | 1 | #include <stdint.h> |
andrewboyson | 61:aad055f1b0d1 | 2 | #include <stdbool.h> |
andrewboyson | 61:aad055f1b0d1 | 3 | |
andrewboyson | 46:40d33e9037e4 | 4 | #include "log.h" |
andrewboyson | 101:a677d8aee6dd | 5 | #include "clk.h" |
andrewboyson | 46:40d33e9037e4 | 6 | #include "net.h" |
andrewboyson | 46:40d33e9037e4 | 7 | #include "action.h" |
andrewboyson | 46:40d33e9037e4 | 8 | #include "ip6.h" |
andrewboyson | 46:40d33e9037e4 | 9 | #include "mac.h" |
andrewboyson | 46:40d33e9037e4 | 10 | #include "slaac.h" |
andrewboyson | 46:40d33e9037e4 | 11 | #include "ndp.h" |
andrewboyson | 46:40d33e9037e4 | 12 | |
andrewboyson | 46:40d33e9037e4 | 13 | bool RaTrace = false; |
andrewboyson | 46:40d33e9037e4 | 14 | |
andrewboyson | 46:40d33e9037e4 | 15 | __packed struct header |
andrewboyson | 46:40d33e9037e4 | 16 | { |
andrewboyson | 46:40d33e9037e4 | 17 | uint8_t hop; |
andrewboyson | 46:40d33e9037e4 | 18 | uint8_t mo; |
andrewboyson | 46:40d33e9037e4 | 19 | uint16_t lifetime; |
andrewboyson | 46:40d33e9037e4 | 20 | uint32_t reachable; |
andrewboyson | 46:40d33e9037e4 | 21 | uint32_t retrans; |
andrewboyson | 46:40d33e9037e4 | 22 | }; |
andrewboyson | 47:73af5c0b0dc2 | 23 | void logHeader(struct header* pHeader, char* pData, int dataLength) |
andrewboyson | 46:40d33e9037e4 | 24 | { |
andrewboyson | 46:40d33e9037e4 | 25 | if (NetTraceVerbose) |
andrewboyson | 46:40d33e9037e4 | 26 | { |
andrewboyson | 46:40d33e9037e4 | 27 | Log("RA header\r\n"); |
andrewboyson | 46:40d33e9037e4 | 28 | LogF(" Hop limit %d\r\n", pHeader->hop); |
andrewboyson | 46:40d33e9037e4 | 29 | LogF(" M O %x\r\n", pHeader->mo); |
andrewboyson | 46:40d33e9037e4 | 30 | LogF(" Lifetime %d\r\n", NetToHost16(pHeader->lifetime)); |
andrewboyson | 46:40d33e9037e4 | 31 | LogF(" Reachable %d\r\n", NetToHost32(pHeader->reachable)); |
andrewboyson | 46:40d33e9037e4 | 32 | LogF(" Retrans %d\r\n", NetToHost32(pHeader->retrans)); |
andrewboyson | 47:73af5c0b0dc2 | 33 | NdpLogOptionsVerbose(pData, dataLength); |
andrewboyson | 46:40d33e9037e4 | 34 | } |
andrewboyson | 46:40d33e9037e4 | 35 | else |
andrewboyson | 46:40d33e9037e4 | 36 | { |
andrewboyson | 47:73af5c0b0dc2 | 37 | Log("RA header"); |
andrewboyson | 47:73af5c0b0dc2 | 38 | NdpLogOptionsQuiet(pData, dataLength); |
andrewboyson | 47:73af5c0b0dc2 | 39 | Log("\r\n"); |
andrewboyson | 46:40d33e9037e4 | 40 | } |
andrewboyson | 46:40d33e9037e4 | 41 | } |
andrewboyson | 46:40d33e9037e4 | 42 | int RaHandleReceivedAdvertisement(void (*traceback)(void), void* pPacket, int* pSize) |
andrewboyson | 46:40d33e9037e4 | 43 | { |
andrewboyson | 61:aad055f1b0d1 | 44 | struct header* pHeader = (struct header*)pPacket; |
andrewboyson | 46:40d33e9037e4 | 45 | char* pData = (char*)pHeader + sizeof(struct header); |
andrewboyson | 46:40d33e9037e4 | 46 | int dataLength = *pSize - sizeof(struct header); |
andrewboyson | 46:40d33e9037e4 | 47 | |
andrewboyson | 47:73af5c0b0dc2 | 48 | NdpHopLimit = pHeader->hop; |
andrewboyson | 47:73af5c0b0dc2 | 49 | NdpManagedConfiguration = pHeader->mo & 0x80; |
andrewboyson | 47:73af5c0b0dc2 | 50 | NdpOtherConfiguration = pHeader->mo & 0x40; |
andrewboyson | 119:8e1a7805b801 | 51 | NdpSetLease (NetToHost16(pHeader->lifetime)); //This resets the NdpElapsedTimer |
andrewboyson | 46:40d33e9037e4 | 52 | |
andrewboyson | 46:40d33e9037e4 | 53 | if (RaTrace) |
andrewboyson | 46:40d33e9037e4 | 54 | { |
andrewboyson | 46:40d33e9037e4 | 55 | if (NetTraceNewLine) Log("\r\n"); |
andrewboyson | 46:40d33e9037e4 | 56 | LogTimeF("NDP received router advertise\r\n"); |
andrewboyson | 46:40d33e9037e4 | 57 | if (NetTraceStack) traceback(); |
andrewboyson | 47:73af5c0b0dc2 | 58 | logHeader(pHeader, pData, dataLength); |
andrewboyson | 46:40d33e9037e4 | 59 | } |
andrewboyson | 47:73af5c0b0dc2 | 60 | NdpDecodeOptions(pData, dataLength, NdpRouterMac, NULL); |
andrewboyson | 46:40d33e9037e4 | 61 | |
andrewboyson | 46:40d33e9037e4 | 62 | return DO_NOTHING; |
andrewboyson | 46:40d33e9037e4 | 63 | |
andrewboyson | 46:40d33e9037e4 | 64 | } |