82 #ifdef LWIP_HOOK_FILENAME 83 #include LWIP_HOOK_FILENAME 103 ip6_route(
const ip6_addr_t *src,
const ip6_addr_t *dest)
117 if (ip6_addr_islinklocal(dest)) {
118 if (ip6_addr_isany(src)) {
133 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
134 ip6_addr_cmp(src, netif_ip6_addr(netif, i))) {
149 #ifdef LWIP_HOOK_IP6_ROUTE 150 netif = LWIP_HOOK_IP6_ROUTE(src, dest);
162 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
163 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
170 netif = nd6_find_route(dest);
176 if (!ip6_addr_isany(src)) {
182 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
183 ip6_addr_cmp(src, netif_ip6_addr(netif, i))) {
190 #if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF 192 if (ip6_addr_isloopback(dest)) {
226 ip6_select_source_address(
struct netif *netif,
const ip6_addr_t *dest)
228 const ip_addr_t *src = NULL;
232 if (ip6_addr_islinklocal(dest) || ip6_addr_ismulticast_linklocal(dest) || ip6_addr_ismulticast_iflocal(dest)) {
234 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
235 ip6_addr_islinklocal(netif_ip6_addr(netif, i))) {
236 return netif_ip_addr6(netif, i);
242 if (ip6_addr_issitelocal(dest) || ip6_addr_ismulticast_sitelocal(dest)) {
244 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
245 ip6_addr_issitelocal(netif_ip6_addr(netif, i)) &&
246 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
247 return netif_ip_addr6(netif, i);
253 if (ip6_addr_isuniquelocal(dest) || ip6_addr_ismulticast_orglocal(dest)) {
255 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
256 ip6_addr_isuniquelocal(netif_ip6_addr(netif, i)) &&
257 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
258 return netif_ip_addr6(netif, i);
264 if (ip6_addr_isglobal(dest) || ip6_addr_ismulticast_global(dest)) {
266 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
267 ip6_addr_isglobal(netif_ip6_addr(netif, i))) {
269 src = netif_ip_addr6(netif, i);
274 if ((!(ip6_addr_netcmp(ip_2_ip6(src), dest))) &&
275 ip6_addr_netcmp(netif_ip6_addr(netif, i), dest)) {
276 src = netif_ip_addr6(netif, i);
288 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
289 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
290 return netif_ip_addr6(netif, i);
297 #if LWIP_IPV6_FORWARD 308 ip6_forward(
struct pbuf *p,
struct ip6_hdr *iphdr,
struct netif *inp)
313 if (ip6_addr_islinklocal(ip6_current_dest_addr()) ||
314 ip6_addr_isloopback(ip6_current_dest_addr())) {
316 IP6_STATS_INC(ip6.rterr);
317 IP6_STATS_INC(ip6.drop);
322 netif = ip6_route(IP6_ADDR_ANY6, ip6_current_dest_addr());
324 LWIP_DEBUGF(
IP6_DEBUG, (
"ip6_forward: no route for %"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
"\n",
325 IP6_ADDR_BLOCK1(ip6_current_dest_addr()),
326 IP6_ADDR_BLOCK2(ip6_current_dest_addr()),
327 IP6_ADDR_BLOCK3(ip6_current_dest_addr()),
328 IP6_ADDR_BLOCK4(ip6_current_dest_addr()),
329 IP6_ADDR_BLOCK5(ip6_current_dest_addr()),
330 IP6_ADDR_BLOCK6(ip6_current_dest_addr()),
331 IP6_ADDR_BLOCK7(ip6_current_dest_addr()),
332 IP6_ADDR_BLOCK8(ip6_current_dest_addr())));
335 if (IP6H_NEXTH(iphdr) != IP6_NEXTH_ICMP6) {
339 IP6_STATS_INC(ip6.rterr);
340 IP6_STATS_INC(ip6.drop);
347 IP6_STATS_INC(ip6.rterr);
348 IP6_STATS_INC(ip6.drop);
353 IP6H_HOPLIM_SET(iphdr, IP6H_HOPLIM(iphdr) - 1);
355 if (IP6H_HOPLIM(iphdr) == 0) {
358 if (IP6H_NEXTH(iphdr) != IP6_NEXTH_ICMP6) {
362 IP6_STATS_INC(ip6.drop);
369 if (IP6H_NEXTH(iphdr) != IP6_NEXTH_ICMP6) {
370 icmp6_packet_too_big(p, netif->
mtu);
373 IP6_STATS_INC(ip6.drop);
377 LWIP_DEBUGF(
IP6_DEBUG, (
"ip6_forward: forwarding packet to %"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
"\n",
378 IP6_ADDR_BLOCK1(ip6_current_dest_addr()),
379 IP6_ADDR_BLOCK2(ip6_current_dest_addr()),
380 IP6_ADDR_BLOCK3(ip6_current_dest_addr()),
381 IP6_ADDR_BLOCK4(ip6_current_dest_addr()),
382 IP6_ADDR_BLOCK5(ip6_current_dest_addr()),
383 IP6_ADDR_BLOCK6(ip6_current_dest_addr()),
384 IP6_ADDR_BLOCK7(ip6_current_dest_addr()),
385 IP6_ADDR_BLOCK8(ip6_current_dest_addr())));
388 netif->output_ip6(netif, p, ip6_current_dest_addr());
389 IP6_STATS_INC(ip6.fw);
390 IP6_STATS_INC(ip6.xmit);
410 ip6_input(
struct pbuf *p,
struct netif *inp)
422 IP6_STATS_INC(ip6.recv);
426 if (IP6H_V(ip6hdr) != 6) {
430 IP6_STATS_INC(ip6.err);
431 IP6_STATS_INC(ip6.drop);
435 #ifdef LWIP_HOOK_IP6_INPUT 436 if (LWIP_HOOK_IP6_INPUT(p, inp)) {
443 if ((IP6_HLEN > p->
len) || ((IP6H_PLEN(ip6hdr) + IP6_HLEN) > p->
tot_len)) {
444 if (IP6_HLEN > p->
len) {
446 (
"IPv6 header (len %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IP packet dropped.\n",
447 (u16_t)IP6_HLEN, p->
len));
449 if ((IP6H_PLEN(ip6hdr) + IP6_HLEN) > p->
tot_len) {
451 (
"IPv6 (plen %"U16_F
") is longer than pbuf (len %"U16_F
"), IP packet dropped.\n",
452 (u16_t)(IP6H_PLEN(ip6hdr) + IP6_HLEN), p->
tot_len));
456 IP6_STATS_INC(ip6.lenerr);
457 IP6_STATS_INC(ip6.drop);
474 IP6_STATS_INC(ip6.err);
475 IP6_STATS_INC(ip6.drop);
480 ip_data.current_ip6_header = ip6hdr;
487 if (ip6_addr_ismulticast(ip6_current_dest_addr())) {
489 if (ip6_addr_isallnodes_iflocal(ip6_current_dest_addr()) ||
490 ip6_addr_isallnodes_linklocal(ip6_current_dest_addr())) {
494 else if (mld6_lookfor_group(inp, ip6_current_dest_addr())) {
498 else if (ip6_addr_issolicitednode(ip6_current_dest_addr())) {
503 if (ip6_addr_isvalid(netif_ip6_addr_state(inp, i)) &&
504 ip6_addr_cmp_solicitednode(ip6_current_dest_addr(), netif_ip6_addr(inp, i))) {
527 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
528 ip6_addr_cmp(ip6_current_dest_addr(), netif_ip6_addr(netif, i))) {
535 if (ip6_addr_islinklocal(ip6_current_dest_addr())
537 || ip6_addr_isloopback(ip6_current_dest_addr())
557 }
while (netif != NULL);
560 netif ? netif->
name[0] :
'X', netif? netif->
name[1] :
'X'));
564 if (ip6_addr_isany(ip6_current_src_addr()) &&
565 (!ip6_addr_issolicitednode(ip6_current_dest_addr()))) {
570 IP6_STATS_INC(ip6.drop);
571 goto ip6_input_cleanup;
578 #if LWIP_IPV6_FORWARD 580 if (!ip6_addr_ismulticast(ip6_current_dest_addr())) {
582 ip6_forward(p, ip6hdr, inp);
586 goto ip6_input_cleanup;
593 nexth = IP6H_NEXTH(ip6hdr);
602 while (nexth != IP6_NEXTH_NONE)
605 case IP6_NEXTH_HOPBYHOP:
611 hlen = 8 * (1 + *((u8_t *)p->
payload + 1));
617 (
"IPv6 options header (hlen %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IPv6 packet dropped.\n",
621 IP6_STATS_INC(ip6.lenerr);
622 IP6_STATS_INC(ip6.drop);
623 goto ip6_input_cleanup;
628 case IP6_NEXTH_DESTOPTS:
634 hlen = 8 * (1 + *((u8_t *)p->
payload + 1));
640 (
"IPv6 options header (hlen %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IPv6 packet dropped.\n",
644 IP6_STATS_INC(ip6.lenerr);
645 IP6_STATS_INC(ip6.drop);
646 goto ip6_input_cleanup;
651 case IP6_NEXTH_ROUTING:
657 hlen = 8 * (1 + *((u8_t *)p->
payload + 1));
663 (
"IPv6 options header (hlen %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IPv6 packet dropped.\n",
667 IP6_STATS_INC(ip6.lenerr);
668 IP6_STATS_INC(ip6.drop);
669 goto ip6_input_cleanup;
675 case IP6_NEXTH_FRAGMENT:
683 nexth = frag_hdr->_nexth;
692 (
"IPv6 options header (hlen %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IPv6 packet dropped.\n",
696 IP6_FRAG_STATS_INC(ip6_frag.lenerr);
697 IP6_FRAG_STATS_INC(ip6_frag.drop);
698 goto ip6_input_cleanup;
702 if ((frag_hdr->_fragment_offset &
703 PP_HTONS(IP6_FRAG_OFFSET_MASK | IP6_FRAG_MORE_FLAG)) == 0) {
714 goto ip6_input_cleanup;
720 nexth = IP6H_NEXTH(ip6hdr);
726 LWIP_DEBUGF(
IP6_DEBUG, (
"ip6_input: packet with Fragment header dropped (with LWIP_IPV6_REASS==0)\n"));
728 IP6_STATS_INC(ip6.opterr);
729 IP6_STATS_INC(ip6.drop);
730 goto ip6_input_cleanup;
752 if (raw_input(p, inp) == 0)
762 case IP6_NEXTH_UDPLITE:
777 case IP6_NEXTH_ICMP6:
786 if ((!ip6_addr_ismulticast(ip6_current_dest_addr())) &&
787 (IP6H_NEXTH(ip6hdr) != IP6_NEXTH_ICMP6)) {
793 IP6_STATS_INC(ip6.proterr);
794 IP6_STATS_INC(ip6.drop);
802 ip_data.current_ip6_header = NULL;
804 ip6_addr_set_zero(ip6_current_src_addr());
805 ip6_addr_set_zero(ip6_current_dest_addr());
836 ip6_output_if(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
838 u8_t nexth,
struct netif *netif)
840 const ip6_addr_t *src_used = src;
841 if (dest != LWIP_IP_HDRINCL) {
842 if (src != NULL && ip6_addr_isany(src)) {
843 src_used = ip_2_ip6(ip6_select_source_address(netif, dest));
844 if ((src_used == NULL) || ip6_addr_isany(src_used)) {
847 IP6_STATS_INC(ip6.rterr);
852 return ip6_output_if_src(p, src_used, dest, hl, tc, nexth, netif);
860 ip6_output_if_src(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
862 u8_t nexth,
struct netif *netif)
865 ip6_addr_t dest_addr;
870 if (dest != LWIP_IP_HDRINCL) {
874 IP6_STATS_INC(ip6.err);
879 LWIP_ASSERT(
"check that first pbuf can hold struct ip6_hdr",
882 IP6H_HOPLIM_SET(ip6hdr, hl);
883 IP6H_NEXTH_SET(ip6hdr, nexth);
886 ip6_addr_copy(ip6hdr->dest, *dest);
888 IP6H_VTCFL_SET(ip6hdr, 6, tc, 0);
889 IP6H_PLEN_SET(ip6hdr, p->
tot_len - IP6_HLEN);
895 ip6_addr_copy(ip6hdr->src, *src);
900 ip6_addr_copy(dest_addr, ip6hdr->dest);
904 IP6_STATS_INC(ip6.xmit);
912 #if !LWIP_HAVE_LOOPIF 913 if (ip6_addr_isloopback(dest)) {
914 return netif_loop_output(netif, p);
918 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
919 ip6_addr_cmp(dest, netif_ip6_addr(netif, i))) {
922 return netif_loop_output(netif, p);
929 if (netif->
mtu && (p->
tot_len > nd6_get_destination_mtu(dest, netif))) {
930 return ip6_frag(p, netif, dest);
935 return netif->output_ip6(netif, p, dest);
957 ip6_output(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
958 u8_t hl, u8_t tc, u8_t nexth)
962 ip6_addr_t src_addr, dest_addr;
966 if (dest != LWIP_IP_HDRINCL) {
967 netif = ip6_route(src, dest);
971 ip6_addr_copy(src_addr, ip6hdr->src);
972 ip6_addr_copy(dest_addr, ip6hdr->dest);
973 netif = ip6_route(&src_addr, &dest_addr);
977 LWIP_DEBUGF(
IP6_DEBUG, (
"ip6_output: no route for %"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
"\n",
978 IP6_ADDR_BLOCK1(dest),
979 IP6_ADDR_BLOCK2(dest),
980 IP6_ADDR_BLOCK3(dest),
981 IP6_ADDR_BLOCK4(dest),
982 IP6_ADDR_BLOCK5(dest),
983 IP6_ADDR_BLOCK6(dest),
984 IP6_ADDR_BLOCK7(dest),
985 IP6_ADDR_BLOCK8(dest)));
986 IP6_STATS_INC(ip6.rterr);
990 return ip6_output_if(p, src, dest, hl, tc, nexth, netif);
994 #if LWIP_NETIF_HWADDRHINT 1015 ip6_output_hinted(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
1016 u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint)
1018 struct netif *netif;
1020 ip6_addr_t src_addr, dest_addr;
1025 if (dest != LWIP_IP_HDRINCL) {
1026 netif = ip6_route(src, dest);
1030 ip6_addr_copy(src_addr, ip6hdr->src);
1031 ip6_addr_copy(dest_addr, ip6hdr->dest);
1032 netif = ip6_route(&src_addr, &dest_addr);
1035 if (netif == NULL) {
1036 LWIP_DEBUGF(
IP6_DEBUG, (
"ip6_output: no route for %"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
":%"X16_F
"\n",
1037 IP6_ADDR_BLOCK1(dest),
1038 IP6_ADDR_BLOCK2(dest),
1039 IP6_ADDR_BLOCK3(dest),
1040 IP6_ADDR_BLOCK4(dest),
1041 IP6_ADDR_BLOCK5(dest),
1042 IP6_ADDR_BLOCK6(dest),
1043 IP6_ADDR_BLOCK7(dest),
1044 IP6_ADDR_BLOCK8(dest)));
1045 IP6_STATS_INC(ip6.rterr);
1049 NETIF_SET_HWADDRHINT(netif, addr_hint);
1050 err = ip6_output_if(p, src, dest, hl, tc, nexth, netif);
1051 NETIF_SET_HWADDRHINT(netif, NULL);
1069 ip6_options_add_hbh_ra(
struct pbuf *p, u8_t nexth, u8_t value)
1076 IP6_STATS_INC(ip6.err);
1083 hbh_hdr->_nexth = nexth;
1085 hbh_hdr->_ra_opt_type = IP6_ROUTER_ALERT_OPTION;
1086 hbh_hdr->_ra_opt_dlen = 2;
1087 hbh_hdr->_ra_opt_data = value;
1088 hbh_hdr->_padn_opt_type = IP6_PADN_ALERT_OPTION;
1089 hbh_hdr->_padn_opt_dlen = 0;
1100 ip6_debug_print(
struct pbuf *p)
1114 IP6H_HOPLIM(ip6hdr)));
1117 IP6_ADDR_BLOCK1(&(ip6hdr->src)),
1118 IP6_ADDR_BLOCK2(&(ip6hdr->src)),
1119 IP6_ADDR_BLOCK3(&(ip6hdr->src)),
1120 IP6_ADDR_BLOCK4(&(ip6hdr->src))));
1122 IP6_ADDR_BLOCK5(&(ip6hdr->src)),
1123 IP6_ADDR_BLOCK6(&(ip6hdr->src)),
1124 IP6_ADDR_BLOCK7(&(ip6hdr->src)),
1125 IP6_ADDR_BLOCK8(&(ip6hdr->src))));
1128 IP6_ADDR_BLOCK1(&(ip6hdr->dest)),
1129 IP6_ADDR_BLOCK2(&(ip6hdr->dest)),
1130 IP6_ADDR_BLOCK3(&(ip6hdr->dest)),
1131 IP6_ADDR_BLOCK4(&(ip6hdr->dest))));
1133 IP6_ADDR_BLOCK5(&(ip6hdr->dest)),
1134 IP6_ADDR_BLOCK6(&(ip6hdr->dest)),
1135 IP6_ADDR_BLOCK7(&(ip6hdr->dest)),
1136 IP6_ADDR_BLOCK8(&(ip6hdr->dest))));
void pbuf_realloc(struct pbuf *p, u16_t new_len)
struct netif * netif_list
struct netif * netif_default
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
#define netif_is_link_up(netif)
#define LWIP_DBG_LEVEL_SERIOUS
struct netif * current_netif
ip_addr_t current_iphdr_dest
u16_t current_ip_header_tot_len
#define LWIP_DEBUGF(debug, message)
#define netif_is_up(netif)
#define LWIP_DBG_LEVEL_WARNING
#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p)
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
u8_t pbuf_free(struct pbuf *p)
struct netif * current_input_netif
#define LWIP_IPV6_NUM_ADDRESSES
ip_addr_t current_iphdr_src