if_inet6.h 6.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 *	inet6 interface/address list definitions
 *	Linux INET6 implementation 
 *
 *	Authors:
 *	Pedro Roque		<roque@di.fc.ul.pt>	
 *
 *
 *	This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License
 *      as published by the Free Software Foundation; either version
 *      2 of the License, or (at your option) any later version.
 */

#ifndef _NET_IF_INET6_H
#define _NET_IF_INET6_H

#include <net/snmp.h>
#include <linux/ipv6.h>
20
#include <linux/refcount.h>
L
Linus Torvalds 已提交
21 22 23 24 25 26 27

/* inet6_dev.if_flags */

#define IF_RA_OTHERCONF	0x80
#define IF_RA_MANAGED	0x40
#define IF_RA_RCVD	0x20
#define IF_RS_SENT	0x10
28
#define IF_READY	0x80000000
L
Linus Torvalds 已提交
29 30 31 32 33

/* prefix flags */
#define IF_PREFIX_ONLINK	0x01
#define IF_PREFIX_AUTOCONF	0x02

34
enum {
35
	INET6_IFADDR_STATE_PREDAD,
36 37
	INET6_IFADDR_STATE_DAD,
	INET6_IFADDR_STATE_POSTDAD,
38
	INET6_IFADDR_STATE_ERRDAD,
39 40 41
	INET6_IFADDR_STATE_DEAD,
};

E
Eric Dumazet 已提交
42
struct inet6_ifaddr {
L
Linus Torvalds 已提交
43 44
	struct in6_addr		addr;
	__u32			prefix_len;
45

46
	/* In seconds, relative to tstamp. Expiry is at tstamp + HZ * lft. */
L
Linus Torvalds 已提交
47 48
	__u32			valid_lft;
	__u32			prefered_lft;
49
	refcount_t		refcnt;
L
Linus Torvalds 已提交
50
	spinlock_t		lock;
51 52

	int			state;
L
Linus Torvalds 已提交
53

54
	__u32			flags;
55
	__u8			dad_probes;
56
	__u8			stable_privacy_retry;
L
Linus Torvalds 已提交
57 58

	__u16			scope;
59
	__u64			dad_nonce;
L
Linus Torvalds 已提交
60

61 62 63
	unsigned long		cstamp;	/* created timestamp */
	unsigned long		tstamp; /* updated timestamp */

64
	struct delayed_work	dad_work;
L
Linus Torvalds 已提交
65 66 67 68

	struct inet6_dev	*idev;
	struct rt6_info		*rt;

69
	struct hlist_node	addr_lst;
70
	struct list_head	if_list;
L
Linus Torvalds 已提交
71

72
	struct list_head	tmp_list;
L
Linus Torvalds 已提交
73 74
	struct inet6_ifaddr	*ifpub;
	int			regen_count;
75

76 77
	bool			tokenized;

78
	struct rcu_head		rcu;
79
	struct in6_addr		peer_addr;
L
Linus Torvalds 已提交
80 81
};

E
Eric Dumazet 已提交
82
struct ip6_sf_socklist {
L
Linus Torvalds 已提交
83 84 85 86 87 88 89 90 91 92
	unsigned int		sl_max;
	unsigned int		sl_count;
	struct in6_addr		sl_addr[0];
};

#define IP6_SFLSIZE(count)	(sizeof(struct ip6_sf_socklist) + \
	(count) * sizeof(struct in6_addr))

#define IP6_SFBLOCK	10	/* allocate this many at once */

E
Eric Dumazet 已提交
93
struct ipv6_mc_socklist {
L
Linus Torvalds 已提交
94 95
	struct in6_addr		addr;
	int			ifindex;
E
Eric Dumazet 已提交
96
	struct ipv6_mc_socklist __rcu *next;
97
	rwlock_t		sflock;
L
Linus Torvalds 已提交
98 99
	unsigned int		sfmode;		/* MCAST_{INCLUDE,EXCLUDE} */
	struct ip6_sf_socklist	*sflist;
E
Eric Dumazet 已提交
100
	struct rcu_head		rcu;
L
Linus Torvalds 已提交
101 102
};

E
Eric Dumazet 已提交
103
struct ip6_sf_list {
L
Linus Torvalds 已提交
104 105 106 107 108 109 110 111 112 113 114 115 116 117
	struct ip6_sf_list	*sf_next;
	struct in6_addr		sf_addr;
	unsigned long		sf_count[2];	/* include/exclude counts */
	unsigned char		sf_gsresp;	/* include in g & s response? */
	unsigned char		sf_oldin;	/* change state */
	unsigned char		sf_crcount;	/* retrans. left to send */
};

#define MAF_TIMER_RUNNING	0x01
#define MAF_LAST_REPORTER	0x02
#define MAF_LOADED		0x04
#define MAF_NOREPORT		0x08
#define MAF_GSQUERY		0x10

E
Eric Dumazet 已提交
118
struct ifmcaddr6 {
L
Linus Torvalds 已提交
119 120 121 122 123 124
	struct in6_addr		mca_addr;
	struct inet6_dev	*idev;
	struct ifmcaddr6	*next;
	struct ip6_sf_list	*mca_sources;
	struct ip6_sf_list	*mca_tomb;
	unsigned int		mca_sfmode;
125
	unsigned char		mca_crcount;
L
Linus Torvalds 已提交
126 127
	unsigned long		mca_sfcount[2];
	struct timer_list	mca_timer;
128
	unsigned int		mca_flags;
L
Linus Torvalds 已提交
129
	int			mca_users;
130
	refcount_t		mca_refcnt;
L
Linus Torvalds 已提交
131 132 133 134 135 136 137
	spinlock_t		mca_lock;
	unsigned long		mca_cstamp;
	unsigned long		mca_tstamp;
};

/* Anycast stuff */

E
Eric Dumazet 已提交
138
struct ipv6_ac_socklist {
L
Linus Torvalds 已提交
139 140 141 142 143
	struct in6_addr		acl_addr;
	int			acl_ifindex;
	struct ipv6_ac_socklist *acl_next;
};

E
Eric Dumazet 已提交
144
struct ifacaddr6 {
L
Linus Torvalds 已提交
145 146 147 148 149
	struct in6_addr		aca_addr;
	struct inet6_dev	*aca_idev;
	struct rt6_info		*aca_rt;
	struct ifacaddr6	*aca_next;
	int			aca_users;
150
	refcount_t		aca_refcnt;
L
Linus Torvalds 已提交
151 152 153 154 155 156 157 158 159 160
	unsigned long		aca_cstamp;
	unsigned long		aca_tstamp;
};

#define	IFA_HOST	IPV6_ADDR_LOOPBACK
#define	IFA_LINK	IPV6_ADDR_LINKLOCAL
#define	IFA_SITE	IPV6_ADDR_SITELOCAL

struct ipv6_devstat {
	struct proc_dir_entry	*proc_dir_entry;
161
	DEFINE_SNMP_STAT(struct ipstats_mib, ipv6);
162 163
	DEFINE_SNMP_STAT_ATOMIC(struct icmpv6_mib_device, icmpv6dev);
	DEFINE_SNMP_STAT_ATOMIC(struct icmpv6msg_mib_device, icmpv6msgdev);
L
Linus Torvalds 已提交
164 165
};

E
Eric Dumazet 已提交
166
struct inet6_dev {
167
	struct net_device	*dev;
L
Linus Torvalds 已提交
168

169
	struct list_head	addr_list;
L
Linus Torvalds 已提交
170 171 172

	struct ifmcaddr6	*mc_list;
	struct ifmcaddr6	*mc_tomb;
173
	spinlock_t		mc_lock;
174 175

	unsigned char		mc_qrv;		/* Query Robustness Variable */
L
Linus Torvalds 已提交
176 177
	unsigned char		mc_gq_running;
	unsigned char		mc_ifc_count;
178
	unsigned char		mc_dad_count;
179 180 181 182

	unsigned long		mc_v1_seen;	/* Max time we stay in MLDv1 mode */
	unsigned long		mc_qi;		/* Query Interval */
	unsigned long		mc_qri;		/* Query Response Interval */
183
	unsigned long		mc_maxdelay;
184

L
Linus Torvalds 已提交
185 186
	struct timer_list	mc_gq_timer;	/* general query timer */
	struct timer_list	mc_ifc_timer;	/* interface change timer */
187
	struct timer_list	mc_dad_timer;	/* dad complete mc timer */
L
Linus Torvalds 已提交
188 189 190

	struct ifacaddr6	*ac_list;
	rwlock_t		lock;
191
	refcount_t		refcnt;
L
Linus Torvalds 已提交
192 193 194
	__u32			if_flags;
	int			dead;

J
Jiri Bohac 已提交
195
	u32			desync_factor;
L
Linus Torvalds 已提交
196
	u8			rndid[8];
197
	struct list_head	tempaddr_list;
L
Linus Torvalds 已提交
198

199 200
	struct in6_addr		token;

L
Linus Torvalds 已提交
201 202 203
	struct neigh_parms	*nd_parms;
	struct ipv6_devconf	cnf;
	struct ipv6_devstat	stats;
204 205

	struct timer_list	rs_timer;
206
	__s32			rs_interval;	/* in jiffies */
207 208
	__u8			rs_probes;

L
Linus Torvalds 已提交
209
	unsigned long		tstamp; /* ipv6InterfaceTable update timestamp */
210
	struct rcu_head		rcu;
L
Linus Torvalds 已提交
211 212
};

213
static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
L
Linus Torvalds 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
{
	/*
	 *	+-------+-------+-------+-------+-------+-------+
	 *      |   33  |   33  | DST13 | DST14 | DST15 | DST16 |
	 *      +-------+-------+-------+-------+-------+-------+
	 */

	buf[0]= 0x33;
	buf[1]= 0x33;

	memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
}

static inline void ipv6_arcnet_mc_map(const struct in6_addr *addr, char *buf)
{
	buf[0] = 0x00;
}

232 233
static inline void ipv6_ib_mc_map(const struct in6_addr *addr,
				  const unsigned char *broadcast, char *buf)
L
Linus Torvalds 已提交
234
{
235 236
	unsigned char scope = broadcast[5] & 0xF;

L
Linus Torvalds 已提交
237 238 239 240 241
	buf[0]  = 0;		/* Reserved */
	buf[1]  = 0xff;		/* Multicast QPN */
	buf[2]  = 0xff;
	buf[3]  = 0xff;
	buf[4]  = 0xff;
242
	buf[5]  = 0x10 | scope;	/* scope from broadcast address */
L
Linus Torvalds 已提交
243 244
	buf[6]  = 0x60;		/* IPv6 signature */
	buf[7]  = 0x1b;
245 246
	buf[8]  = broadcast[8];	/* P_Key */
	buf[9]  = broadcast[9];
L
Linus Torvalds 已提交
247 248
	memcpy(buf + 10, addr->s6_addr + 6, 10);
}
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264

static inline int ipv6_ipgre_mc_map(const struct in6_addr *addr,
				    const unsigned char *broadcast, char *buf)
{
	if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0) {
		memcpy(buf, broadcast, 4);
	} else {
		/* v4mapped? */
		if ((addr->s6_addr32[0] | addr->s6_addr32[1] |
		     (addr->s6_addr32[2] ^ htonl(0x0000ffff))) != 0)
			return -EINVAL;
		memcpy(buf, &addr->s6_addr32[3], 4);
	}
	return 0;
}

L
Linus Torvalds 已提交
265
#endif