RTEMS CPU Kit with SuperCore  4.11.3
in_var.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1985, 1986, 1993
3  * The Regents of the University of California. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * @(#)in_var.h 8.2 (Berkeley) 1/9/95
30  * $FreeBSD: src/sys/netinet/in_var.h,v 1.52 2004/10/19 21:06:14 andre Exp $
31  */
32 
33 #ifndef _NETINET_IN_VAR_H_
34 #define _NETINET_IN_VAR_H_
35 
36 #include <sys/queue.h>
37 #include <net/if_var.h> /* struct ifaddr */
38 #include <netinet/in.h> /* struct in_addr */
39 
40 #if !defined(__rtems__)
41 #include <sys/fnv_hash.h>
42 #endif
43 
44 /*
45  * Interface address, Internet version. One of these structures
46  * is allocated for each Internet address on an interface.
47  * The ifaddr structure contains the protocol-independent part
48  * of the structure and is assumed to be first.
49  */
50 struct in_ifaddr {
51  struct ifaddr ia_ifa; /* protocol-independent info */
52 #define ia_ifp ia_ifa.ifa_ifp
53 #define ia_flags ia_ifa.ifa_flags
54  /* ia_{,sub}net{,mask} in host order */
55  u_long ia_net; /* network number of interface */
56  u_long ia_netmask; /* mask of net part */
57  u_long ia_subnet; /* subnet number, including net */
58  u_long ia_subnetmask; /* mask of subnet part */
59  struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
60  struct in_ifaddr *ia_next; /* next in list of internet addresses */
61  struct sockaddr_in ia_addr; /* reserve space for interface name */
62  struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
63 #define ia_broadaddr ia_dstaddr
64  struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
65  LIST_HEAD(in_multihead, in_multi) ia_multiaddrs;
66  /* list of multicast addresses */
67 };
68 
69 struct in_aliasreq {
70  char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
71  struct sockaddr_in ifra_addr;
72  struct sockaddr_in ifra_broadaddr;
73 #define ifra_dstaddr ifra_broadaddr
74  struct sockaddr_in ifra_mask;
75 };
76 /*
77  * Given a pointer to an in_ifaddr (ifaddr),
78  * return a pointer to the addr as a sockaddr_in.
79  */
80 #define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
81 #define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr))
82 
83 #define IN_LNAOF(in, ifa) \
84  ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask))
85 
86 
87 #ifdef _KERNEL
88 extern struct in_ifaddr *in_ifaddr;
89 extern struct ifqueue ipintrq; /* ip packet input queue */
90 extern struct in_addr zeroin_addr;
91 extern u_char inetctlerrmap[];
92 
93 /*
94  * Macro for finding the interface (ifnet structure) corresponding to one
95  * of our IP addresses.
96  */
97 #define INADDR_TO_IFP(addr, ifp) \
98  /* struct in_addr addr; */ \
99  /* struct ifnet *ifp; */ \
100 { \
101  register struct in_ifaddr *ia; \
102 \
103  for (ia = in_ifaddr; \
104  ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \
105  IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \
106  ia = ia->ia_next) \
107  continue; \
108  if (ia == NULL) \
109  for (ia = in_ifaddr; \
110  ia != NULL; \
111  ia = ia->ia_next) \
112  if (ia->ia_ifp->if_flags & IFF_POINTOPOINT && \
113  IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \
114  break; \
115  (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
116 }
117 
118 /*
119  * Macro for finding the internet address structure (in_ifaddr) corresponding
120  * to a given interface (ifnet structure).
121  */
122 #define IFP_TO_IA(ifp, ia) \
123  /* struct ifnet *ifp; */ \
124  /* struct in_ifaddr *ia; */ \
125 { \
126  for ((ia) = in_ifaddr; \
127  (ia) != NULL && (ia)->ia_ifp != (ifp); \
128  (ia) = (ia)->ia_next) \
129  continue; \
130 }
131 #endif
132 
133 /*
134  * This information should be part of the ifnet structure but we don't wish
135  * to change that - as it might break a number of things
136  */
137 
138 struct router_info {
139  struct ifnet *rti_ifp;
140  int rti_type; /* type of router which is querier on this interface */
141  int rti_time; /* # of slow timeouts since last old query */
142  struct router_info *rti_next;
143 };
144 
145 /*
146  * Internet multicast address structure. There is one of these for each IP
147  * multicast group to which this host belongs on a given network interface.
148  * They are kept in a linked list, rooted in the interface's in_ifaddr
149  * structure.
150  */
151 struct in_multi {
152  LIST_ENTRY(in_multi) inm_entry; /* list glue */
153  struct in_addr inm_addr; /* IP multicast address */
154  struct ifnet *inm_ifp; /* back pointer to ifnet */
155  struct in_ifaddr *inm_ia; /* back pointer to in_ifaddr */
156  u_int inm_refcount; /* no. membership claims by sockets */
157  u_int inm_timer; /* IGMP membership report timer */
158  u_int inm_state; /* state of the membership */
159  struct router_info *inm_rti; /* router info*/
160 };
161 
162 #ifdef _KERNEL
163 
164 #ifdef SYSCTL_DECL
165 SYSCTL_DECL(_net_inet_ip);
166 SYSCTL_DECL(_net_inet_raw);
167 #endif
168 
169 /*
170  * Structure used by macros below to remember position when stepping through
171  * all of the in_multi records.
172  */
173 struct in_multistep {
174  struct in_ifaddr *i_ia;
175  struct in_multi *i_inm;
176 };
177 
178 /*
179  * Macro for looking up the in_multi record for a given IP multicast address
180  * on a given interface. If no matching record is found, "inm" returns NULL.
181  */
182 #define IN_LOOKUP_MULTI(addr, ifp, inm) \
183  /* struct in_addr addr; */ \
184  /* struct ifnet *ifp; */ \
185  /* struct in_multi *inm; */ \
186 { \
187  register struct in_ifaddr *ia; \
188 \
189  IFP_TO_IA((ifp), ia); \
190  if (ia == NULL) \
191  (inm) = NULL; \
192  else \
193  for ((inm) = ia->ia_multiaddrs.lh_first; \
194  (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr; \
195  (inm) = inm->inm_entry.le_next) \
196  continue; \
197 }
198 
199 /*
200  * Macro to step through all of the in_multi records, one at a time.
201  * The current position is remembered in "step", which the caller must
202  * provide. IN_FIRST_MULTI(), below, must be called to initialize "step"
203  * and get the first record. Both macros return a NULL "inm" when there
204  * are no remaining records.
205  */
206 #define IN_NEXT_MULTI(step, inm) \
207  /* struct in_multistep step; */ \
208  /* struct in_multi *inm; */ \
209 { \
210  if (((inm) = (step).i_inm) != NULL) \
211  (step).i_inm = (inm)->inm_entry.le_next; \
212  else \
213  while ((step).i_ia != NULL) { \
214  (inm) = (step).i_ia->ia_multiaddrs.lh_first; \
215  (step).i_ia = (step).i_ia->ia_next; \
216  if ((inm) != NULL) { \
217  (step).i_inm = (inm)->inm_entry.le_next; \
218  break; \
219  } \
220  } \
221 }
222 
223 #define IN_FIRST_MULTI(step, inm) \
224  /* struct in_multistep step; */ \
225  /* struct in_multi *inm; */ \
226 { \
227  (step).i_ia = in_ifaddr; \
228  (step).i_inm = NULL; \
229  IN_NEXT_MULTI((step), (inm)); \
230 }
231 
232 struct in_multi *in_addmulti(struct in_addr *, struct ifnet *);
233 void in_delmulti(struct in_multi *);
234 int in_control(struct socket *, u_long, caddr_t, struct ifnet *);
235 void in_rtqdrain(void);
236 void ip_input(struct mbuf *);
237 
238 #endif /* _KERNEL */
239 
240 #endif /* _NETINET_IN_VAR_H_ */
Definition: in_var.h:139
Definition: in.h:74
Definition: socketvar.h:49
Definition: if_var.h:86
Definition: inet.h:93
Definition: if_var.h:99
Definition: if_var.h:211
Definition: mbuf.h:103
Definition: in_var.h:70
Definition: in_var.h:152