]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/ipsend/in_var.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / ipsend / in_var.h
1 /*      $FreeBSD$       */
2
3 /*      @(#)in_var.h 1.3 88/08/19 SMI; from UCB 7.1 6/5/86      */
4
5 /*
6  * Copyright (c) 1985, 1986 Regents of the University of California.
7  * All rights reserved.  The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10
11 /*
12  * Interface address, Internet version.  One of these structures
13  * is allocated for each interface with an Internet address.
14  * The ifaddr structure contains the protocol-independent part
15  * of the structure and is assumed to be first.
16  */
17
18 #ifndef _netinet_in_var_h
19 #define _netinet_in_var_h
20
21 struct in_ifaddr {
22         struct  ifaddr ia_ifa;          /* protocol-independent info */
23 #define ia_addr ia_ifa.ifa_addr
24 #define ia_broadaddr    ia_ifa.ifa_broadaddr
25 #define ia_dstaddr      ia_ifa.ifa_dstaddr
26 #define ia_ifp          ia_ifa.ifa_ifp
27         u_long  ia_net;                 /* network number of interface */
28         u_long  ia_netmask;             /* mask of net part */
29         u_long  ia_subnet;              /* subnet number, including net */
30         u_long  ia_subnetmask;          /* mask of net + subnet */
31         struct  in_addr ia_netbroadcast; /* broadcast addr for (logical) net */
32         int     ia_flags;
33         struct  in_ifaddr *ia_next;     /* next in list of internet addresses */
34         struct  in_multi *ia_multiaddrs;/* list of multicast addresses */
35 };
36 /*
37  * Given a pointer to an in_ifaddr (ifaddr),
38  * return a pointer to the addr as a sockadd_in.
39  */
40 #define IA_SIN(ia) ((struct sockaddr_in *)(&((struct in_ifaddr *)ia)->ia_addr))
41 /*
42  * ia_flags
43  */
44 #define IFA_ROUTE       0x01            /* routing entry installed */
45
46 #ifdef  KERNEL
47 struct  in_ifaddr *in_ifaddr;
48 struct  in_ifaddr *in_iaonnetof();
49 struct  ifqueue ipintrq;                /* ip packet input queue */
50 #endif
51
52 #ifdef KERNEL
53 /*
54  * Macro for finding the interface (ifnet structure) corresponding to one
55  * of our IP addresses.
56  */
57 #define INADDR_TO_IFP(addr, ifp)                                          \
58         /* struct in_addr addr; */                                        \
59         /* struct ifnet  *ifp;  */                                        \
60 {                                                                         \
61         register struct in_ifaddr *ia;                                    \
62                                                                           \
63         for (ia = in_ifaddr;                                              \
64              ia != NULL && IA_SIN(ia)->sin_addr.s_addr != (addr).s_addr;  \
65              ia = ia->ia_next);                                           \
66         (ifp) = (ia == NULL) ? NULL : ia->ia_ifp;                         \
67 }
68
69 /*
70  * Macro for finding the internet address structure (in_ifaddr) corresponding
71  * to a given interface (ifnet structure).
72  */
73 #define IFP_TO_IA(ifp, ia)                                                \
74         /* struct ifnet     *ifp; */                                      \
75         /* struct in_ifaddr *ia;  */                                      \
76 {                                                                         \
77         for ((ia) = in_ifaddr;                                            \
78              (ia) != NULL && (ia)->ia_ifp != (ifp);                       \
79              (ia) = (ia)->ia_next);                                       \
80 }
81 #endif /* KERNEL */
82
83 /*
84  * Per-interface router version information is kept in this list.
85  * This information should be part of the ifnet structure but we don't wish
86  * to change that - as it might break a number of things
87  */
88
89 struct router_info {
90         struct ifnet *ifp;
91         int    type; /* type of router which is querier on this interface */
92         int    time; /* # of slow timeouts since last old query */
93         struct router_info *next;
94 };
95
96 /*
97  * Internet multicast address structure.  There is one of these for each IP
98  * multicast group to which this host belongs on a given network interface.
99  * They are kept in a linked list, rooted in the interface's in_ifaddr
100  * structure.
101  */
102
103 struct in_multi {
104         struct in_addr     inm_addr;    /* IP multicast address             */
105         struct ifnet      *inm_ifp;     /* back pointer to ifnet            */
106         struct in_ifaddr  *inm_ia;      /* back pointer to in_ifaddr        */
107         u_int              inm_refcount;/* no. membership claims by sockets */
108         u_int              inm_timer;   /* IGMP membership report timer     */
109         struct in_multi   *inm_next;    /* ptr to next multicast address    */
110         u_int              inm_state;   /*  state of the membership */
111         struct router_info *inm_rti;     /* router info*/
112 };
113
114 #ifdef KERNEL
115 /*
116  * Structure used by macros below to remember position when stepping through
117  * all of the in_multi records.
118  */
119 struct in_multistep {
120         struct in_ifaddr *i_ia;
121         struct in_multi  *i_inm;
122 };
123
124 /*
125  * Macro for looking up the in_multi record for a given IP multicast address
126  * on a given interface.  If no matching record is found, "inm" returns NULL.
127  */
128 #define IN_LOOKUP_MULTI(addr, ifp, inm)                                     \
129         /* struct in_addr  addr; */                                         \
130         /* struct ifnet    *ifp; */                                         \
131         /* struct in_multi *inm; */                                         \
132 {                                                                           \
133         register struct in_ifaddr *ia;                                      \
134                                                                             \
135         IFP_TO_IA((ifp), ia);                                               \
136         if (ia == NULL)                                                     \
137                 (inm) = NULL;                                               \
138         else                                                                \
139             for ((inm) = ia->ia_multiaddrs;                                 \
140                  (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr;  \
141                  (inm) = inm->inm_next);                                    \
142 }
143
144 /*
145  * Macro to step through all of the in_multi records, one at a time.
146  * The current position is remembered in "step", which the caller must
147  * provide.  IN_FIRST_MULTI(), below, must be called to initialize "step"
148  * and get the first record.  Both macros return a NULL "inm" when there
149  * are no remaining records.
150  */
151 #define IN_NEXT_MULTI(step, inm)                                        \
152         /* struct in_multistep  step; */                                \
153         /* struct in_multi     *inm;  */                                \
154 {                                                                       \
155         if (((inm) = (step).i_inm) != NULL) {                           \
156                 (step).i_inm = (inm)->inm_next;                         \
157         }                                                               \
158         else while ((step).i_ia != NULL) {                              \
159                 (inm) = (step).i_ia->ia_multiaddrs;                     \
160                 (step).i_ia = (step).i_ia->ia_next;                     \
161                 if ((inm) != NULL) {                                    \
162                         (step).i_inm = (inm)->inm_next;                 \
163                         break;                                          \
164                 }                                                       \
165         }                                                               \
166 }
167
168 #define IN_FIRST_MULTI(step, inm)                                       \
169         /* struct in_multistep  step; */                                \
170         /* struct in_multi     *inm;  */                                \
171 {                                                                       \
172         (step).i_ia  = in_ifaddr;                                       \
173         (step).i_inm = NULL;                                            \
174         IN_NEXT_MULTI((step), (inm));                                   \
175 }
176
177 struct in_multi *in_addmulti();
178 #endif /* KERNEL */
179 #endif /*!_netinet_in_var_h*/