1/* $OpenBSD: in_var.h,v 1.47 2026/03/22 23:14:00 bluhm Exp $ */
2/* $NetBSD: in_var.h,v 1.16 1996/02/13 23:42:15 christos Exp $ */
3
4/*
5 * Copyright (c) 1985, 1986, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)in_var.h 8.1 (Berkeley) 6/10/93
33 */
34
35#ifndef _NETINET_IN_VAR_H_
36#define _NETINET_IN_VAR_H_
37
38/*
39 * Locks used to protect struct members in this file:
40 * I immutable after creation
41 * m multicast if_maddrlock rwlock of parent interface
42 */
43
44#include <sys/queue.h>
45
46#ifdef _KERNEL
47/*
48 * Interface address, Internet version. One of these structures
49 * is allocated for each interface with an Internet address.
50 * The ifaddr structure contains the protocol-independent part
51 * of the structure and is assumed to be first.
52 */
53struct in_ifaddr {
54 struct ifaddr ia_ifa; /* protocol-independent info */
55#define ia_ifp ia_ifa.ifa_ifp
56#define ia_flags ia_ifa.ifa_flags
57 /* ia_net{,mask} in host order */
58 u_int32_t ia_net; /* network number of interface */
59 u_int32_t ia_netmask; /* mask of net part */
60 TAILQ_ENTRY(in_ifaddr) ia_list; /* 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 struct in_multi *ia_allhosts; /* multicast address record for
66 the allhosts multicast group */
67};
68#endif
69
70struct in_aliasreq {
71 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
72 union {
73 struct sockaddr_in ifrau_addr;
74 int ifrau_align;
75 } ifra_ifrau;
76#ifndef ifra_addr
77#define ifra_addr ifra_ifrau.ifrau_addr
78#endif
79 struct sockaddr_in ifra_dstaddr;
80#define ifra_broadaddr ifra_dstaddr
81 struct sockaddr_in ifra_mask;
82};
83
84#ifdef _KERNEL
85struct router_info;
86
87/*
88 * Internet multicast address structure. There is one of these for each IP
89 * multicast group to which this host belongs on a given network interface.
90 */
91struct in_multi {
92 struct ifmaddr inm_ifma; /* Protocol-independent info */
93#define inm_refcnt inm_ifma.ifma_refcnt
94#define inm_ifidx inm_ifma.ifma_ifidx
95
96 struct sockaddr_in inm_sin; /* [I] IPv4 multicast address */
97#define inm_addr inm_sin.sin_addr
98
99 u_int inm_state; /* [m] state of membership */
100 u_int inm_timer; /* [m] IGMP membership report */
101
102 struct router_info *inm_rti; /* router version info */
103};
104
105static __inline struct in_multi *
106ifmatoinm(struct ifmaddr *ifma)
107{
108 return ((struct in_multi *)(ifma));
109}
110
111struct in_ifaddr *in_ifp2ia(struct ifnet *);
112int in_ifinit(struct ifnet *,
113 struct in_ifaddr *, struct sockaddr_in *, int);
114struct in_multi *in_lookupmulti(const struct in_addr *, struct ifnet *);
115struct in_multi *in_addmulti(const struct in_addr *, struct ifnet *);
116void in_delmulti(struct in_multi *);
117int in_hasmulti(const struct in_addr *, struct ifnet *);
118void in_ifscrub(struct ifnet *, struct in_ifaddr *);
119int in_control(struct socket *, u_long, caddr_t, struct ifnet *);
120int in_ioctl(u_long, caddr_t, struct ifnet *, int);
121void in_prefixlen2mask(struct in_addr *, int);
122#endif /* _KERNEL */
123
124#endif /* _NETINET_IN_VAR_H_ */