84 ip6_route(
const ip6_addr_t *src,
const ip6_addr_t *dest)
89 #ifdef LWIP_HOOK_IP6_ROUTE 90 netif = LWIP_HOOK_IP6_ROUTE(src, dest);
105 if (ip6_addr_islinklocal(dest)) {
106 if (ip6_addr_isany(src)) {
120 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
121 ip6_addr_cmp(src, netif_ip6_addr(netif, i))) {
140 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
141 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
148 i = nd6_select_router(dest,
NULL);
150 if (default_router_list[i].neighbor_entry !=
NULL) {
151 if (default_router_list[i].neighbor_entry->netif !=
NULL) {
153 return default_router_list[i].neighbor_entry->netif;
160 if (!ip6_addr_isany(src)) {
166 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
167 ip6_addr_cmp(src, netif_ip6_addr(netif, i))) {
174 #if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF 176 if (ip6_addr_isloopback(dest)) {
209 ip6_select_source_address(
struct netif *netif,
const ip6_addr_t * dest)
215 if (ip6_addr_islinklocal(dest) || ip6_addr_ismulticast_linklocal(dest) || ip6_addr_ismulticast_iflocal(dest)) {
217 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
218 ip6_addr_islinklocal(netif_ip6_addr(netif, i))) {
219 return netif_ip_addr6(netif, i);
225 if (ip6_addr_issitelocal(dest) || ip6_addr_ismulticast_sitelocal(dest)) {
227 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
228 ip6_addr_issitelocal(netif_ip6_addr(netif, i)) &&
229 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
230 return netif_ip_addr6(netif, i);
236 if (ip6_addr_isuniquelocal(dest) || ip6_addr_ismulticast_orglocal(dest)) {
238 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
239 ip6_addr_isuniquelocal(netif_ip6_addr(netif, i)) &&
240 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
241 return netif_ip_addr6(netif, i);
247 if (ip6_addr_isglobal(dest) || ip6_addr_ismulticast_global(dest)) {
249 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
250 ip6_addr_isglobal(netif_ip6_addr(netif, i))) {
252 src = netif_ip_addr6(netif, i);
257 if ((!(ip6_addr_netcmp(
ip_2_ip6(src), dest))) &&
258 ip6_addr_netcmp(netif_ip6_addr(netif, i), dest)) {
259 src = netif_ip_addr6(netif, i);
271 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
272 ip6_addr_netcmp(dest, netif_ip6_addr(netif, i))) {
273 return netif_ip_addr6(netif, i);
280 #if LWIP_IPV6_FORWARD 291 ip6_forward(
struct pbuf *p,
struct ip6_hdr *iphdr,
struct netif *inp)
296 if (ip6_addr_islinklocal(ip6_current_dest_addr())) {
304 netif = ip6_route(IP6_ADDR_ANY6, ip6_current_dest_addr());
307 IP6_ADDR_BLOCK1(ip6_current_dest_addr()),
308 IP6_ADDR_BLOCK2(ip6_current_dest_addr()),
309 IP6_ADDR_BLOCK3(ip6_current_dest_addr()),
310 IP6_ADDR_BLOCK4(ip6_current_dest_addr()),
311 IP6_ADDR_BLOCK5(ip6_current_dest_addr()),
312 IP6_ADDR_BLOCK6(ip6_current_dest_addr()),
313 IP6_ADDR_BLOCK7(ip6_current_dest_addr()),
314 IP6_ADDR_BLOCK8(ip6_current_dest_addr())));
317 if (IP6H_NEXTH(iphdr) != IP6_NEXTH_ICMP6) {
335 IP6H_HOPLIM_SET(iphdr, IP6H_HOPLIM(iphdr) - 1);
337 if (IP6H_HOPLIM(iphdr) == 0) {
340 if (IP6H_NEXTH(iphdr) != IP6_NEXTH_ICMP6) {
351 if (IP6H_NEXTH(iphdr) != IP6_NEXTH_ICMP6) {
352 icmp6_packet_too_big(p, netif->
mtu);
359 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",
360 IP6_ADDR_BLOCK1(ip6_current_dest_addr()),
361 IP6_ADDR_BLOCK2(ip6_current_dest_addr()),
362 IP6_ADDR_BLOCK3(ip6_current_dest_addr()),
363 IP6_ADDR_BLOCK4(ip6_current_dest_addr()),
364 IP6_ADDR_BLOCK5(ip6_current_dest_addr()),
365 IP6_ADDR_BLOCK6(ip6_current_dest_addr()),
366 IP6_ADDR_BLOCK7(ip6_current_dest_addr()),
367 IP6_ADDR_BLOCK8(ip6_current_dest_addr())));
370 netif->output_ip6(netif, p, ip6_current_dest_addr());
385 return ip6_input(p, inp);
404 ip6_input(
struct pbuf *p,
struct netif *inp)
406 struct ip6_hdr *ip6hdr;
419 ip6hdr = (
struct ip6_hdr *)p->
payload;
420 if (IP6H_V(ip6hdr) != 6) {
429 #ifdef LWIP_HOOK_IP6_INPUT 430 if (LWIP_HOOK_IP6_INPUT(p, inp)) {
437 if ((IP6_HLEN > p->
len) || ((IP6H_PLEN(ip6hdr) + IP6_HLEN) > p->
tot_len)) {
438 if (IP6_HLEN > p->
len) {
440 (
"IPv6 header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet dropped.\n",
443 if ((IP6H_PLEN(ip6hdr) + IP6_HLEN) > p->
tot_len) {
445 (
"IPv6 (plen %"U16_F") is longer than pbuf (len %"U16_F"), IP packet dropped.\n",
446 IP6H_PLEN(ip6hdr) + IP6_HLEN, p->
tot_len));
464 ip_data.current_ip6_header = ip6hdr;
471 if (ip6_addr_ismulticast(ip6_current_dest_addr())) {
473 if (ip6_addr_isallnodes_iflocal(ip6_current_dest_addr()) ||
474 ip6_addr_isallnodes_linklocal(ip6_current_dest_addr())) {
478 else if (mld6_lookfor_group(inp, ip6_current_dest_addr())) {
482 else if (ip6_addr_issolicitednode(ip6_current_dest_addr())) {
487 if (ip6_addr_isvalid(netif_ip6_addr_state(inp, i)) &&
488 ip6_addr_cmp_solicitednode(ip6_current_dest_addr(), netif_ip6_addr(inp, i))) {
511 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
512 ip6_addr_cmp(ip6_current_dest_addr(), netif_ip6_addr(netif, i))) {
518 if (ip6_addr_islinklocal(ip6_current_dest_addr())) {
532 }
while (netif !=
NULL);
535 netif ? netif->
name[0] :
'X', netif? netif->
name[1] :
'X'));
539 if (ip6_addr_isany(ip6_current_src_addr()) &&
540 (!ip6_addr_issolicitednode(ip6_current_dest_addr()))) {
546 goto ip6_input_cleanup;
553 #if LWIP_IPV6_FORWARD 555 if (!ip6_addr_ismulticast(ip6_current_dest_addr())) {
557 ip6_forward(p, ip6hdr, inp);
561 goto ip6_input_cleanup;
568 nexth = IP6H_NEXTH(ip6hdr);
577 while (nexth != IP6_NEXTH_NONE)
580 case IP6_NEXTH_HOPBYHOP:
592 (
"IPv6 options header (hlen %"U16_F") does not fit in first pbuf (len %"U16_F"), IPv6 packet dropped.\n",
598 goto ip6_input_cleanup;
603 case IP6_NEXTH_DESTOPTS:
615 (
"IPv6 options header (hlen %"U16_F") does not fit in first pbuf (len %"U16_F"), IPv6 packet dropped.\n",
621 goto ip6_input_cleanup;
626 case IP6_NEXTH_ROUTING:
638 (
"IPv6 options header (hlen %"U16_F") does not fit in first pbuf (len %"U16_F"), IPv6 packet dropped.\n",
644 goto ip6_input_cleanup;
650 case IP6_NEXTH_FRAGMENT:
652 struct ip6_frag_hdr * frag_hdr;
655 frag_hdr = (
struct ip6_frag_hdr *)p->
payload;
658 nexth = frag_hdr->_nexth;
667 (
"IPv6 options header (hlen %"U16_F") does not fit in first pbuf (len %"U16_F"), IPv6 packet dropped.\n",
673 goto ip6_input_cleanup;
677 if ((frag_hdr->_fragment_offset &
678 PP_HTONS(IP6_FRAG_OFFSET_MASK | IP6_FRAG_MORE_FLAG)) == 0) {
689 goto ip6_input_cleanup;
694 ip6hdr = (
struct ip6_hdr *)p->
payload;
695 nexth = IP6H_NEXTH(ip6hdr);
701 LWIP_DEBUGF(
IP6_DEBUG, (
"ip6_input: packet with Fragment header dropped (with LWIP_IPV6_REASS==0)\n"));
705 goto ip6_input_cleanup;
727 if (raw_input(p, inp) == 0)
737 case IP6_NEXTH_UDPLITE:
752 case IP6_NEXTH_ICMP6:
761 if ((!ip6_addr_ismulticast(ip6_current_dest_addr())) &&
762 (IP6H_NEXTH(ip6hdr) != IP6_NEXTH_ICMP6)) {
779 ip6_addr_set_zero(ip6_current_src_addr());
780 ip6_addr_set_zero(ip6_current_dest_addr());
811 ip6_output_if(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
813 u8_t nexth,
struct netif *netif)
815 const ip6_addr_t *src_used = src;
817 if (src !=
NULL && ip6_addr_isany(src)) {
818 src =
ip_2_ip6(ip6_select_source_address(netif, dest));
819 if ((src ==
NULL) || ip6_addr_isany(src)) {
827 return ip6_output_if_src(p, src_used, dest, hl, tc, nexth, netif);
835 ip6_output_if_src(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
837 u8_t nexth,
struct netif *netif)
839 struct ip6_hdr *ip6hdr;
840 ip6_addr_t dest_addr;
853 ip6hdr = (
struct ip6_hdr *)p->
payload;
854 LWIP_ASSERT(
"check that first pbuf can hold struct ip6_hdr",
855 (p->
len >=
sizeof(
struct ip6_hdr)));
857 IP6H_HOPLIM_SET(ip6hdr, hl);
858 IP6H_NEXTH_SET(ip6hdr, nexth);
861 ip6_addr_copy(ip6hdr->dest, *dest);
863 IP6H_VTCFL_SET(ip6hdr, 6, tc, 0);
864 IP6H_PLEN_SET(ip6hdr, p->
tot_len - IP6_HLEN);
870 ip6_addr_copy(ip6hdr->src, *src);
874 ip6hdr = (
struct ip6_hdr *)p->
payload;
875 ip6_addr_copy(dest_addr, ip6hdr->dest);
887 #if !LWIP_HAVE_LOOPIF 888 if (ip6_addr_isloopback(dest)) {
889 return netif_loop_output(netif, p);
893 if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
894 ip6_addr_cmp(dest, netif_ip6_addr(netif, i))) {
897 return netif_loop_output(netif, p);
904 if (netif->
mtu && (p->
tot_len > nd6_get_destination_mtu(dest, netif))) {
905 return ip6_frag(p, netif, dest);
910 return netif->output_ip6(netif, p, dest);
932 ip6_output(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
936 struct ip6_hdr *ip6hdr;
937 ip6_addr_t src_addr, dest_addr;
942 netif = ip6_route(src, dest);
945 ip6hdr = (
struct ip6_hdr *)p->
payload;
946 ip6_addr_copy(src_addr, ip6hdr->src);
947 ip6_addr_copy(dest_addr, ip6hdr->dest);
948 netif = ip6_route(&src_addr, &dest_addr);
952 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",
953 IP6_ADDR_BLOCK1(dest),
954 IP6_ADDR_BLOCK2(dest),
955 IP6_ADDR_BLOCK3(dest),
956 IP6_ADDR_BLOCK4(dest),
957 IP6_ADDR_BLOCK5(dest),
958 IP6_ADDR_BLOCK6(dest),
959 IP6_ADDR_BLOCK7(dest),
960 IP6_ADDR_BLOCK8(dest)));
965 return ip6_output_if(p, src, dest, hl, tc, nexth, netif);
969 #if LWIP_NETIF_HWADDRHINT 990 ip6_output_hinted(
struct pbuf *p,
const ip6_addr_t *src,
const ip6_addr_t *dest,
994 struct ip6_hdr *ip6hdr;
995 ip6_addr_t src_addr, dest_addr;
1001 netif = ip6_route(src, dest);
1004 ip6hdr = (
struct ip6_hdr *)p->
payload;
1005 ip6_addr_copy(src_addr, ip6hdr->src);
1006 ip6_addr_copy(dest_addr, ip6hdr->dest);
1007 netif = ip6_route(&src_addr, &dest_addr);
1010 if (netif ==
NULL) {
1011 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",
1012 IP6_ADDR_BLOCK1(dest),
1013 IP6_ADDR_BLOCK2(dest),
1014 IP6_ADDR_BLOCK3(dest),
1015 IP6_ADDR_BLOCK4(dest),
1016 IP6_ADDR_BLOCK5(dest),
1017 IP6_ADDR_BLOCK6(dest),
1018 IP6_ADDR_BLOCK7(dest),
1019 IP6_ADDR_BLOCK8(dest)));
1025 err = ip6_output_if(p, src, dest, hl, tc, nexth, netif);
1044 ip6_options_add_hbh_ra(
struct pbuf * p,
u8_t nexth,
u8_t value)
1046 struct ip6_hbh_hdr * hbh_hdr;
1055 hbh_hdr = (
struct ip6_hbh_hdr *)p->
payload;
1058 hbh_hdr->_nexth = nexth;
1060 hbh_hdr->_ra_opt_type = IP6_ROUTER_ALERT_OPTION;
1061 hbh_hdr->_ra_opt_dlen = 2;
1062 hbh_hdr->_ra_opt_data = value;
1063 hbh_hdr->_padn_opt_type = IP6_PADN_ALERT_OPTION;
1064 hbh_hdr->_padn_opt_dlen = 0;
1075 ip6_debug_print(
struct pbuf *p)
1077 struct ip6_hdr *ip6hdr = (
struct ip6_hdr *)p->
payload;
1089 IP6H_HOPLIM(ip6hdr)));
1092 IP6_ADDR_BLOCK1(&(ip6hdr->src)),
1093 IP6_ADDR_BLOCK2(&(ip6hdr->src)),
1094 IP6_ADDR_BLOCK3(&(ip6hdr->src)),
1095 IP6_ADDR_BLOCK4(&(ip6hdr->src))));
1097 IP6_ADDR_BLOCK5(&(ip6hdr->src)),
1098 IP6_ADDR_BLOCK6(&(ip6hdr->src)),
1099 IP6_ADDR_BLOCK7(&(ip6hdr->src)),
1100 IP6_ADDR_BLOCK8(&(ip6hdr->src))));
1103 IP6_ADDR_BLOCK1(&(ip6hdr->dest)),
1104 IP6_ADDR_BLOCK2(&(ip6hdr->dest)),
1105 IP6_ADDR_BLOCK3(&(ip6hdr->dest)),
1106 IP6_ADDR_BLOCK4(&(ip6hdr->dest))));
1108 IP6_ADDR_BLOCK5(&(ip6hdr->dest)),
1109 IP6_ADDR_BLOCK6(&(ip6hdr->dest)),
1110 IP6_ADDR_BLOCK7(&(ip6hdr->dest)),
1111 IP6_ADDR_BLOCK8(&(ip6hdr->dest))));
struct netif * netif_list
#define LWIP_DBG_LEVEL_SERIOUS
struct netif * netif_default
#define LWIP_DBG_LEVEL_WARNING
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
void pbuf_realloc(struct pbuf *p, u16_t new_len)
#define netif_is_link_up(netif)
ip_addr_t current_iphdr_dest
err_t ip_input(struct pbuf *p, struct netif *inp)
u16_t current_ip_header_tot_len
ip_addr_t current_iphdr_src
struct netif * current_netif
u8_t pbuf_free(struct pbuf *p)
#define IP6_FRAG_STATS_INC(x)
#define NETIF_SET_HWADDRHINT(netif, hint)
#define LWIP_ASSERT(message, assertion)
struct ip_globals ip_data
#define ip_addr_copy_from_ip6(dest, src)
#define LWIP_IPV6_NUM_ADDRESSES
#define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p)
u8_t pbuf_header_force(struct pbuf *p, s16_t header_size_increment)
#define netif_is_up(netif)
#define LWIP_DEBUGF(debug, message)
struct netif * current_input_netif