• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file
3  * raw API (to be used from TCPIP thread)\n
4  * See also @ref raw_raw
5  */
6 
7 /*
8  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  *    this list of conditions and the following disclaimer in the documentation
18  *    and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31  * OF SUCH DAMAGE.
32  *
33  * This file is part of the lwIP TCP/IP stack.
34  *
35  * Author: Adam Dunkels <adam@sics.se>
36  *
37  */
38 #ifndef LWIP_HDR_RAW_H
39 #define LWIP_HDR_RAW_H
40 
41 #include "lwip/opt.h"
42 
43 #if LWIP_RAW /* don't build if not configured for use in lwipopts.h */
44 
45 #include "lwip/pbuf.h"
46 #include "lwip/def.h"
47 #include "lwip/ip.h"
48 #include "lwip/ip_addr.h"
49 #include "lwip/ip6_addr.h"
50 #include "lwip/icmp6.h"
51 
52 #if defined (__cplusplus) && __cplusplus
53 extern "C" {
54 #endif
55 
56 #define RAW_FLAGS_CONNECTED      0x01U
57 #define RAW_FLAGS_HDRINCL        0x02U
58 #define RAW_FLAGS_MULTICAST_LOOP 0x04U
59 
60 struct raw_pcb;
61 extern struct raw_pcb *raw_pcbs;
62 
63 #if PF_PKT_SUPPORT
64 extern struct raw_pcb *pkt_raw_pcbs;
65 extern struct raw_pcb *all_pkt_raw_pcbs;
66 extern const struct eth_hdr *g_lwip_current_eth_hdr;
67 extern const struct netif *g_lwip_current_netif;
68 
69 /*
70  * Dest MAC add of current ethernet header of RAW packets
71  * received for PF_PACKET family
72  */
73 #define eth_current_hdr()       (g_lwip_current_eth_hdr)
74 #define eth_current_netif()     (g_lwip_current_netif)
75 #endif
76 
77 #if LWIP_NETIF_PROMISC
78 extern u8_t pkt_raw_pcbs_using_netif(u8_t ifindex);
79 #endif /* LWIP_NETIF_PROMISC */
80 
81 #ifndef IPPROTO_ICMPV6
82 #define IPPROTO_ICMPV6  58
83 #endif
84 
85 /* Function prototype for raw pcb receive callback functions.
86  * @param arg user supplied argument (raw_pcb.recv_arg)
87  * @param pcb the raw_pcb which received data
88  * @param p the packet buffer that was received
89  * @param addr the remote IP address from which the packet was received
90  * @return 1 if the packet was 'eaten' (aka. deleted),
91  *         0 if the packet lives on
92  * If returning 1, the callback is responsible for freeing the pbuf
93  * if it's not used any more.
94  */
95 typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
96                             const ip_addr_t *addr);
97 
98 /* the RAW protocol control block */
99 struct raw_pcb {
100   /* Common members of all PCB types */
101   IP_PCB;
102   u8_t hdrincl;
103 
104   struct raw_pcb *next;
105 #if PF_PKT_SUPPORT
106   struct raw_pcb *all_next;
107   u8_t netifindex;
108 
109   union {
110     u16_t eth_proto; /* Ethernet HeaderType/Protocol for Packet sockets */
111 #define raw_proto proto.protocol
112     u8_t  protocol;  /* IP protocol for AF_INET sockets */
113   } proto;
114 #else
115 #define raw_proto protocol
116   u8_t protocol;
117 #endif
118 
119 #if LWIP_MULTICAST_TX_OPTIONS
120   /** outgoing network interface for multicast packets, by interface index (if nonzero) */
121   u8_t mcast_ifindex;
122   /** TTL for outgoing multicast packets */
123   u8_t mcast_ttl;
124 #endif /* LWIP_MULTICAST_TX_OPTIONS */
125 
126   /* receive callback function */
127   raw_recv_fn recv;
128   /* user-supplied argument for the recv callback */
129   void *recv_arg;
130 
131 #if LWIP_SO_PRIORITY
132   prio_t priority;
133 #endif /* LWIP_SO_PRIORITY */
134 
135 #if LWIP_IPV6
136   /* fields for handling checksum computations as per RFC3542. */
137   u16_t chksum_offset;
138   u8_t  chksum_reqd;
139 
140 #if LWIP_MAC_SECURITY
141   u8_t macsec_reqd: 1;
142 #endif
143 #if LWIP_SOCK_OPT_ICMP6_FILTER
144   struct icmp6_filter icmp6_filter;
145 #endif
146 #endif
147 
148   u32_t flags;
149 };
150 
151 #if LWIP_SO_PRIORITY
152 #define  raw_getpriority(pcb)  ((pcb)->priority)
153 #endif /* LWIP_SO_PRIORITY */
154 
155 /* The following functions is the application layer interface to the
156    RAW code. */
157 struct raw_pcb  *raw_new        (u8_t proto);
158 struct raw_pcb  *raw_new_ip_type(u8_t type, u8_t proto);
159 void             raw_remove     (struct raw_pcb *pcb);
160 err_t            raw_bind       (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
161 err_t            raw_connect    (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
162 void             raw_disconnect (struct raw_pcb *pcb);
163 
164 err_t            raw_sendto     (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr);
165 err_t            raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, struct netif *netif, const ip_addr_t *src_ip);
166 err_t            raw_send       (struct raw_pcb *pcb, struct pbuf *p);
167 
168 void             raw_recv       (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
169 
170 #define          raw_flags(pcb) ((pcb)->flags)
171 #define          raw_setflags(pcb,f)  ((pcb)->flags = (f))
172 
173 #define          raw_set_flags(pcb, set_flags)     do { (pcb)->flags = (u8_t)((pcb)->flags |  (set_flags)); } while(0)
174 #define          raw_clear_flags(pcb, clr_flags)   do { (pcb)->flags = (u8_t)((pcb)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
175 #define          raw_is_flag_set(pcb, flag)        (((pcb)->flags & (flag)) != 0)
176 
177 #if PF_PKT_SUPPORT
178 struct raw_pcb  *raw_pkt_new    (u16_t proto);
179 void             raw_pkt_remove (struct raw_pcb *pcb);
180 void             raw_pkt_input  (struct pbuf *p, struct netif *inp, struct raw_pcb *from);
181 err_t            raw_pkt_sendto (struct raw_pcb *pcb, struct pbuf *p, u8_t ifindex);
182 err_t            raw_pkt_bind   (struct raw_pcb *pcb, u8_t ifindex, u16_t proto);
183 #endif
184 
185 #define raw_init() /* Compatibility define, no init needed. */
186 
187 /* for compatibility with older implementation */
188 #define raw_new_ip6(proto) raw_new_ip_type(IPADDR_TYPE_V6, proto)
189 
190 #if LWIP_MULTICAST_TX_OPTIONS
191 #define raw_set_multicast_netif_index(pcb, idx) ((pcb)->mcast_ifindex = (idx))
192 #define raw_get_multicast_netif_index(pcb)      ((pcb)->mcast_ifindex)
193 #define raw_set_multicast_ttl(pcb, value)       ((pcb)->mcast_ttl = (value))
194 #define raw_get_multicast_ttl(pcb)              ((pcb)->mcast_ttl)
195 #endif /* LWIP_MULTICAST_TX_OPTIONS */
196 
197 #if LWIP_IPV6 && LWIP_RAW
198 
199 u8_t  raw_input6(struct pbuf *p, s16_t proto, s8_t *isCheckSumInvalid,
200                  struct netif *inp);
201 #endif
202 
203 #if defined (__cplusplus) && __cplusplus
204 }
205 #endif
206 
207 #endif /* LWIP_RAW */
208 
209 #endif /* LWIP_HDR_RAW_H */
210