Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / lwip / repo / lwip / src / core / raw.c
1 /**
2  * @file
3  * Implementation of raw protocol PCBs for low-level handling of
4  * different types of protocols besides (or overriding) those
5  * already available in lwIP.\n
6  * See also @ref raw_raw
7  * 
8  * @defgroup raw_raw RAW
9  * @ingroup callbackstyle_api
10  * Implementation of raw protocol PCBs for low-level handling of
11  * different types of protocols besides (or overriding) those
12  * already available in lwIP.\n
13  * @see @ref raw_api
14  */
15
16 /*
17  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without modification,
21  * are permitted provided that the following conditions are met:
22  *
23  * 1. Redistributions of source code must retain the above copyright notice,
24  *    this list of conditions and the following disclaimer.
25  * 2. Redistributions in binary form must reproduce the above copyright notice,
26  *    this list of conditions and the following disclaimer in the documentation
27  *    and/or other materials provided with the distribution.
28  * 3. The name of the author may not be used to endorse or promote products
29  *    derived from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
34  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
36  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
40  * OF SUCH DAMAGE.
41  *
42  * This file is part of the lwIP TCP/IP stack.
43  *
44  * Author: Adam Dunkels <adam@sics.se>
45  *
46  */
47
48 #include "lwip/opt.h"
49
50 #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
51
52 #include "lwip/def.h"
53 #include "lwip/memp.h"
54 #include "lwip/ip_addr.h"
55 #include "lwip/netif.h"
56 #include "lwip/raw.h"
57 #include "lwip/stats.h"
58 #include "lwip/ip6.h"
59 #include "lwip/ip6_addr.h"
60 #include "lwip/inet_chksum.h"
61
62 #include <string.h>
63
64 /** The list of RAW PCBs */
65 static struct raw_pcb *raw_pcbs;
66
67 static u8_t
68 raw_input_local_match(struct raw_pcb *pcb, u8_t broadcast)
69 {
70   LWIP_UNUSED_ARG(broadcast); /* in IPv6 only case */
71   
72   /* check if PCB is bound to specific netif */
73   if ((pcb->netif_idx != NETIF_NO_INDEX) &&
74       (pcb->netif_idx != netif_get_index(ip_data.current_input_netif))) {
75     return 0;
76   }
77
78 #if LWIP_IPV4 && LWIP_IPV6
79   /* Dual-stack: PCBs listening to any IP type also listen to any IP address */
80   if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
81 #if IP_SOF_BROADCAST_RECV
82     if ((broadcast != 0) && !ip_get_option(pcb, SOF_BROADCAST)) {
83       return 0;
84     }
85 #endif /* IP_SOF_BROADCAST_RECV */
86     return 1;
87   }
88 #endif /* LWIP_IPV4 && LWIP_IPV6 */
89
90   /* Only need to check PCB if incoming IP version matches PCB IP version */
91   if (IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ip_current_dest_addr())) {
92 #if LWIP_IPV4
93     /* Special case: IPv4 broadcast: receive all broadcasts
94      * Note: broadcast variable can only be 1 if it is an IPv4 broadcast */
95     if (broadcast != 0) {
96 #if IP_SOF_BROADCAST_RECV
97       if (ip_get_option(pcb, SOF_BROADCAST))
98 #endif /* IP_SOF_BROADCAST_RECV */
99       {
100         if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip))) {
101           return 1;
102         }
103       }
104     } else
105 #endif /* LWIP_IPV4 */
106     /* Handle IPv4 and IPv6: catch all or exact match */
107     if (ip_addr_isany(&pcb->local_ip) ||
108        ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
109       return 1;
110     }
111   }
112
113   return 0;
114 }
115
116 /**
117  * Determine if in incoming IP packet is covered by a RAW PCB
118  * and if so, pass it to a user-provided receive callback function.
119  *
120  * Given an incoming IP datagram (as a chain of pbufs) this function
121  * finds a corresponding RAW PCB and calls the corresponding receive
122  * callback function.
123  *
124  * @param p pbuf to be demultiplexed to a RAW PCB.
125  * @param inp network interface on which the datagram was received.
126  * @return - 1 if the packet has been eaten by a RAW PCB receive
127  *           callback function. The caller MAY NOT not reference the
128  *           packet any longer, and MAY NOT call pbuf_free().
129  * @return - 0 if packet is not eaten (pbuf is still referenced by the
130  *           caller).
131  *
132  */
133 u8_t
134 raw_input(struct pbuf *p, struct netif *inp)
135 {
136   struct raw_pcb *pcb, *prev;
137   s16_t proto;
138   u8_t eaten = 0;
139   u8_t broadcast = ip_addr_isbroadcast(ip_current_dest_addr(), ip_current_netif());
140
141   LWIP_UNUSED_ARG(inp);
142
143 #if LWIP_IPV6
144 #if LWIP_IPV4
145   if (IP_HDR_GET_VERSION(p->payload) == 6)
146 #endif /* LWIP_IPV4 */
147   {
148     struct ip6_hdr *ip6hdr = (struct ip6_hdr *)p->payload;
149     proto = IP6H_NEXTH(ip6hdr);
150   }
151 #if LWIP_IPV4
152   else
153 #endif /* LWIP_IPV4 */
154 #endif /* LWIP_IPV6 */
155 #if LWIP_IPV4
156   {
157     proto = IPH_PROTO((struct ip_hdr *)p->payload);
158   }
159 #endif /* LWIP_IPV4 */
160
161   prev = NULL;
162   pcb = raw_pcbs;
163   /* loop through all raw pcbs until the packet is eaten by one */
164   /* this allows multiple pcbs to match against the packet by design */
165   while ((eaten == 0) && (pcb != NULL)) {
166
167     if ((pcb->protocol == proto) && raw_input_local_match(pcb, broadcast) &&
168         (((pcb->intf_filter == NULL || pcb->intf_filter == inp) &&
169           (ip_addr_isany(&pcb->local_ip) ||
170            ip_addr_cmp(&(pcb->local_ip), ip_current_dest_addr()))) ||
171          (((pcb->flags & RAW_FLAGS_CONNECTED) == 0) ||
172           ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr())))
173         ) {
174       /* receive callback function available? */
175 #if IP_SOF_BROADCAST_RECV
176       /* broadcast filter? */
177       if ((ip_get_option(pcb, SOF_BROADCAST) || !ip_addr_isbroadcast(ip_current_dest_addr(), inp))
178 #if LWIP_IPV6
179           && !PCB_ISIPV6(pcb)
180 #endif /* LWIP_IPV6 */
181           )
182 #endif /* IP_SOF_BROADCAST_RECV */
183       {
184 #ifndef LWIP_NOASSERT
185         void* old_payload = p->payload;
186 #endif
187         /* receive callback function available? */
188         if (pcb->recv != NULL) {
189           /* the receive callback function did not eat the packet? */
190           eaten = pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr());
191           if (eaten != 0) {
192             /* receive function ate the packet */
193             p = NULL;
194             eaten = 1;
195             if (prev != NULL) {
196             /* move the pcb to the front of raw_pcbs so that is
197                found faster next time */
198               prev->next = pcb->next;
199               pcb->next = raw_pcbs;
200               raw_pcbs = pcb;
201             }
202           }
203         } else {
204           /* sanity-check that the receive callback did not alter the pbuf */
205           LWIP_ASSERT("raw pcb recv callback altered pbuf payload pointer without eating packet",
206             p->payload == old_payload);
207         }
208       }
209       /* no receive callback function was set for this raw PCB */
210     }
211     /* drop the packet */
212     prev = pcb;
213     pcb = pcb->next;
214   }
215   return eaten;
216 }
217
218 /**
219  * @ingroup raw_raw
220  * Bind a RAW PCB.
221  *
222  * @param pcb RAW PCB to be bound with a local address ipaddr.
223  * @param ipaddr local IP address to bind with. Use IP4_ADDR_ANY to
224  * bind to all local interfaces.
225  *
226  * @return lwIP error code.
227  * - ERR_OK. Successful. No error occurred.
228  * - ERR_USE. The specified IP address is already bound to by
229  * another RAW PCB.
230  *
231  * @see raw_disconnect()
232  */
233 err_t
234 raw_bind(struct raw_pcb *pcb, const ip_addr_t *ipaddr)
235 {
236   LWIP_ASSERT_CORE_LOCKED();
237   if ((pcb == NULL) || (ipaddr == NULL)) {
238     return ERR_VAL;
239   }
240   ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
241   return ERR_OK;
242 }
243
244 /**
245  * @ingroup raw_raw
246  * Bind a RAW PCB.
247  *
248  * @param pcb RAW PCB to be bound with netif.
249  * @param netif netif to bind to. Can be NULL.
250  *
251  * @see raw_disconnect()
252  */
253 void
254 raw_bind_netif(struct raw_pcb *pcb, const struct netif *netif)
255 {
256   if (netif != NULL) {
257     pcb->netif_idx = netif_get_index(netif);
258   } else {
259     pcb->netif_idx = NETIF_NO_INDEX;
260   }
261 }
262
263 /**
264  * @ingroup raw_raw
265  * Connect an RAW PCB. This function is required by upper layers
266  * of lwip. Using the raw api you could use raw_sendto() instead
267  *
268  * This will associate the RAW PCB with the remote address.
269  *
270  * @param pcb RAW PCB to be connected with remote address ipaddr and port.
271  * @param ipaddr remote IP address to connect with.
272  *
273  * @return lwIP error code
274  *
275  * @see raw_disconnect() and raw_sendto()
276  */
277 err_t
278 raw_connect(struct raw_pcb *pcb, const ip_addr_t *ipaddr)
279 {
280   LWIP_ASSERT_CORE_LOCKED();
281   if ((pcb == NULL) || (ipaddr == NULL)) {
282     return ERR_VAL;
283   }
284   ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
285   raw_set_flags(pcb, RAW_FLAGS_CONNECTED);
286   return ERR_OK;
287 }
288
289 /**
290  * @ingroup raw_raw
291  * Disconnect a RAW PCB.
292  *
293  * @param pcb the raw pcb to disconnect.
294  */
295 void
296 raw_disconnect(struct raw_pcb *pcb)
297 {
298   LWIP_ASSERT_CORE_LOCKED();
299   /* reset remote address association */
300 #if LWIP_IPV4 && LWIP_IPV6
301   if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
302     ip_addr_copy(pcb->remote_ip, *IP_ANY_TYPE);
303   } else {
304 #endif
305     ip_addr_set_any(IP_IS_V6_VAL(pcb->remote_ip), &pcb->remote_ip);
306 #if LWIP_IPV4 && LWIP_IPV6
307   }
308 #endif
309   pcb->netif_idx = NETIF_NO_INDEX;
310   /* mark PCB as unconnected */
311   raw_clear_flags(pcb, RAW_FLAGS_CONNECTED);
312 }
313
314 /**
315  * @ingroup raw_raw
316  * Set the callback function for received packets that match the
317  * raw PCB's protocol and binding.
318  *
319  * The callback function MUST either
320  * - eat the packet by calling pbuf_free() and returning non-zero. The
321  *   packet will not be passed to other raw PCBs or other protocol layers.
322  * - not free the packet, and return zero. The packet will be matched
323  *   against further PCBs and/or forwarded to another protocol layers.
324  */
325 void
326 raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)
327 {
328   LWIP_ASSERT_CORE_LOCKED();
329   /* remember recv() callback and user data */
330   pcb->recv = recv;
331   pcb->recv_arg = recv_arg;
332 }
333
334 /**
335  * @ingroup raw_raw
336  * Send the raw IP packet to the given address. Note that actually you cannot
337  * modify the IP headers (this is inconsistent with the receive callback where
338  * you actually get the IP headers), you can only specify the IP payload here.
339  * It requires some more changes in lwIP. (there will be a raw_send() function
340  * then.)
341  *
342  * @param pcb the raw pcb which to send
343  * @param p the IP payload to send
344  * @param ipaddr the destination address of the IP packet
345  *
346  */
347 err_t
348 raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
349 {
350   struct netif *netif;
351   const ip_addr_t *src_ip;
352
353   if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) {
354     return ERR_VAL;
355   }
356
357   LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_sendto\n"));
358
359   if (pcb->intf_filter != NULL) {
360     netif = pcb->intf_filter;
361   } else if (pcb->netif_idx != NETIF_NO_INDEX) {
362     netif = netif_get_by_index(pcb->netif_idx);
363   } else {
364 #if LWIP_MULTICAST_TX_OPTIONS
365     netif = NULL;
366     if (ip_addr_ismulticast(ipaddr)) {
367       /* For multicast-destined packets, use the user-provided interface index to
368        * determine the outgoing interface, if an interface index is set and a
369        * matching netif can be found. Otherwise, fall back to regular routing. */
370       netif = netif_get_by_index(pcb->mcast_ifindex);
371     }
372
373     if (netif == NULL)
374 #endif /* LWIP_MULTICAST_TX_OPTIONS */
375     {
376       netif = ip_route(&pcb->local_ip, ipaddr);
377     }
378   }
379
380   if (netif == NULL) {
381     LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to "));
382     ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ipaddr);
383     return ERR_RTE;
384   }
385
386   if (ip_addr_isany(&pcb->local_ip) || ip_addr_ismulticast(&pcb->local_ip)) {
387     /* use outgoing network interface IP address as source address */
388     src_ip = ip_netif_get_local_ip(netif, ipaddr);
389 #if LWIP_IPV6
390     if (src_ip == NULL) {
391       return ERR_RTE;
392     }
393 #endif /* LWIP_IPV6 */
394   } else {
395     /* use RAW PCB local IP address as source address */
396     src_ip = &pcb->local_ip;
397   }
398
399   return raw_sendto_if_src(pcb, p, ipaddr, netif, src_ip);
400 }
401
402 /**
403  * @ingroup raw_raw
404  * Send the raw IP packet to the given address, using a particular outgoing
405  * netif and source IP address. An IP header will be prepended to the packet.
406  *
407  * @param pcb RAW PCB used to send the data
408  * @param p chain of pbufs to be sent
409  * @param dst_ip destination IP address
410  * @param netif the netif used for sending
411  * @param src_ip source IP address
412  */
413 err_t
414 raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
415     struct netif *netif, const ip_addr_t *src_ip)
416 {
417   err_t err;
418   struct pbuf *q; /* q will be sent down the stack */
419   s16_t header_size;
420   u8_t ttl;
421
422   if ((pcb == NULL) || (dst_ip == NULL) || (netif == NULL) || (src_ip == NULL) ||
423       !IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) || !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
424     return ERR_VAL;
425   }
426
427   header_size = (
428 #if LWIP_IPV4 && LWIP_IPV6
429     IP_IS_V6(dst_ip) ? IP6_HLEN : IP_HLEN);
430 #elif LWIP_IPV4
431     IP_HLEN);
432 #else
433     IP6_HLEN);
434 #endif
435
436   /* not enough space to add an IP header to first pbuf in given p chain? */
437   if (pbuf_header(p, header_size)) {
438     /* allocate header in new pbuf */
439     q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
440     /* new header pbuf could not be allocated? */
441     if (q == NULL) {
442       LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("raw_sendto: could not allocate header\n"));
443       return ERR_MEM;
444     }
445     if (p->tot_len != 0) {
446       /* chain header q in front of given pbuf p */
447       pbuf_chain(q, p);
448     }
449     /* { first pbuf q points to header pbuf } */
450     LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
451   } else {
452     /* first pbuf q equals given pbuf */
453     q = p;
454     if (pbuf_header(q, (s16_t)-header_size)) {
455       LWIP_ASSERT("Can't restore header we just removed!", 0);
456       return ERR_MEM;
457     }
458   }
459
460 #if IP_SOF_BROADCAST
461   if (IP_IS_V4(dst_ip))
462   {
463     /* broadcast filter? */
464     if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(dst_ip, netif)) {
465       LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
466       /* free any temporary header pbuf allocated by pbuf_header() */
467       if (q != p) {
468         pbuf_free(q);
469       }
470       return ERR_VAL;
471     }
472   }
473 #endif /* IP_SOF_BROADCAST */
474
475   /* Multicast Loop? */
476 #if LWIP_MULTICAST_TX_OPTIONS
477   if (((pcb->flags & RAW_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
478     q->flags |= PBUF_FLAG_MCASTLOOP;
479   }
480 #endif /* LWIP_MULTICAST_TX_OPTIONS */
481
482 #if LWIP_IPV6
483   /* If requested, based on the IPV6_CHECKSUM socket option per RFC3542,
484      compute the checksum and update the checksum in the payload. */
485   if (IP_IS_V6(dst_ip) && pcb->chksum_reqd) {
486     u16_t chksum = ip6_chksum_pseudo(p, pcb->protocol, p->tot_len, ip_2_ip6(src_ip), ip_2_ip6(dst_ip));
487     LWIP_ASSERT("Checksum must fit into first pbuf", p->len >= (pcb->chksum_offset + 2));
488     SMEMCPY(((u8_t *)p->payload) + pcb->chksum_offset, &chksum, sizeof(u16_t));
489   }
490 #endif
491
492   /* Determine TTL to use */
493 #if LWIP_MULTICAST_TX_OPTIONS
494   ttl = (ip_addr_ismulticast(dst_ip) ? raw_get_multicast_ttl(pcb) : pcb->ttl);
495 #else /* LWIP_MULTICAST_TX_OPTIONS */
496   ttl = pcb->ttl;
497 #endif /* LWIP_MULTICAST_TX_OPTIONS */
498
499   netif_apply_pcb(netif, (struct ip_pcb *)pcb);
500   err = ip_output_if(q, src_ip, dst_ip, ttl, pcb->tos, pcb->protocol, netif);
501   netif_apply_pcb(netif, NULL);
502
503   /* did we chain a header earlier? */
504   if (q != p) {
505     /* free the header */
506     pbuf_free(q);
507   }
508   return err;
509 }
510
511 /**
512  * @ingroup raw_raw
513  * Send the raw IP packet to the address given by raw_connect()
514  *
515  * @param pcb the raw pcb which to send
516  * @param p the IP payload to send
517  *
518  */
519 err_t
520 raw_send(struct raw_pcb *pcb, struct pbuf *p)
521 {
522   return raw_sendto(pcb, p, &pcb->remote_ip);
523 }
524
525 /**
526  * @ingroup raw_raw
527  * Remove an RAW PCB.
528  *
529  * @param pcb RAW PCB to be removed. The PCB is removed from the list of
530  * RAW PCB's and the data structure is freed from memory.
531  *
532  * @see raw_new()
533  */
534 void
535 raw_remove(struct raw_pcb *pcb)
536 {
537   struct raw_pcb *pcb2;
538   LWIP_ASSERT_CORE_LOCKED();
539   /* pcb to be removed is first in list? */
540   if (raw_pcbs == pcb) {
541     /* make list start at 2nd pcb */
542     raw_pcbs = raw_pcbs->next;
543     /* pcb not 1st in list */
544   } else {
545     for (pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
546       /* find pcb in raw_pcbs list */
547       if (pcb2->next != NULL && pcb2->next == pcb) {
548         /* remove pcb from list */
549         pcb2->next = pcb->next;
550         break;
551       }
552     }
553   }
554   memp_free(MEMP_RAW_PCB, pcb);
555 }
556
557 /**
558  * @ingroup raw_raw
559  * Create a RAW PCB.
560  *
561  * @return The RAW PCB which was created. NULL if the PCB data structure
562  * could not be allocated.
563  *
564  * @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
565  *
566  * @see raw_remove()
567  */
568 struct raw_pcb *
569 raw_new(u8_t proto)
570 {
571   struct raw_pcb *pcb;
572
573   LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_TRACE, ("raw_new\n"));
574   LWIP_ASSERT_CORE_LOCKED();
575
576   pcb = (struct raw_pcb *)memp_malloc(MEMP_RAW_PCB);
577   /* could allocate RAW PCB? */
578   if (pcb != NULL) {
579     /* initialize PCB to all zeroes */
580     memset(pcb, 0, sizeof(struct raw_pcb));
581     pcb->protocol = proto;
582     pcb->ttl = RAW_TTL;
583 #if LWIP_MULTICAST_TX_OPTIONS
584     raw_set_multicast_ttl(pcb, RAW_TTL);
585 #endif /* LWIP_MULTICAST_TX_OPTIONS */
586     pcb->next = raw_pcbs;
587     raw_pcbs = pcb;
588   }
589   return pcb;
590 }
591
592 /**
593  * @ingroup raw_raw
594  * Create a RAW PCB for specific IP type.
595  *
596  * @return The RAW PCB which was created. NULL if the PCB data structure
597  * could not be allocated.
598  *
599  * @param type IP address type, see @ref lwip_ip_addr_type definitions.
600  * If you want to listen to IPv4 and IPv6 (dual-stack) packets,
601  * supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE.
602  * @param proto the protocol number (next header) of the IPv6 packet payload
603  *              (e.g. IP6_NEXTH_ICMP6)
604  *
605  * @see raw_remove()
606  */
607 struct raw_pcb *
608 raw_new_ip_type(u8_t type, u8_t proto)
609 {
610   struct raw_pcb *pcb;
611   LWIP_ASSERT_CORE_LOCKED();
612   pcb = raw_new(proto);
613 #if LWIP_IPV4 && LWIP_IPV6
614   if (pcb != NULL) {
615     IP_SET_TYPE_VAL(pcb->local_ip,  type);
616     IP_SET_TYPE_VAL(pcb->remote_ip, type);
617   }
618 #else /* LWIP_IPV4 && LWIP_IPV6 */
619   LWIP_UNUSED_ARG(type);
620 #endif /* LWIP_IPV4 && LWIP_IPV6 */
621   return pcb;
622 }
623
624 /** This function is called from netif.c when address is changed
625  *
626  * @param old_addr IP address of the netif before change
627  * @param new_addr IP address of the netif after change
628  */
629 void raw_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr)
630 {
631   struct raw_pcb* rpcb;
632
633   if (!ip_addr_isany(old_addr) && !ip_addr_isany(new_addr)) {
634     for (rpcb = raw_pcbs; rpcb != NULL; rpcb = rpcb->next) {
635       /* PCB bound to current local interface address? */
636       if (ip_addr_cmp(&rpcb->local_ip, old_addr)) {
637         /* The PCB is bound to the old ipaddr and
638          * is set to bound to the new one instead */
639         ip_addr_copy(rpcb->local_ip, *new_addr);
640       }
641     }
642   }
643 }
644
645 #endif /* LWIP_RAW */