aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2012-07-12 02:26:46 -0400
committerDavid S. Miller <davem@davemloft.net>2012-07-12 02:39:11 -0400
commit30f2a5f379d0b4b4e733df138a49e054ebf75ff8 (patch)
treeddd818a29e28e49b1916d3e9dba62c1272912f5f
parent1f42539d257af671d56d4bdbcf13aef31abff6ef (diff)
ipv6: Export ndisc option parsing from ndisc.c
This is going to be used internally by the rt6 redirect code. Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/ndisc.h50
-rw-r--r--net/ipv6/ndisc.c47
2 files changed, 52 insertions, 45 deletions
diff --git a/include/net/ndisc.h b/include/net/ndisc.h
index c02b6ad3f6c5..96a3b5c03e37 100644
--- a/include/net/ndisc.h
+++ b/include/net/ndisc.h
@@ -47,6 +47,8 @@ enum {
47#include <linux/icmpv6.h> 47#include <linux/icmpv6.h>
48#include <linux/in6.h> 48#include <linux/in6.h>
49#include <linux/types.h> 49#include <linux/types.h>
50#include <linux/if_arp.h>
51#include <linux/netdevice.h>
50 52
51#include <net/neighbour.h> 53#include <net/neighbour.h>
52 54
@@ -80,6 +82,54 @@ struct nd_opt_hdr {
80 __u8 nd_opt_len; 82 __u8 nd_opt_len;
81} __packed; 83} __packed;
82 84
85/* ND options */
86struct ndisc_options {
87 struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX];
88#ifdef CONFIG_IPV6_ROUTE_INFO
89 struct nd_opt_hdr *nd_opts_ri;
90 struct nd_opt_hdr *nd_opts_ri_end;
91#endif
92 struct nd_opt_hdr *nd_useropts;
93 struct nd_opt_hdr *nd_useropts_end;
94};
95
96#define nd_opts_src_lladdr nd_opt_array[ND_OPT_SOURCE_LL_ADDR]
97#define nd_opts_tgt_lladdr nd_opt_array[ND_OPT_TARGET_LL_ADDR]
98#define nd_opts_pi nd_opt_array[ND_OPT_PREFIX_INFO]
99#define nd_opts_pi_end nd_opt_array[__ND_OPT_PREFIX_INFO_END]
100#define nd_opts_rh nd_opt_array[ND_OPT_REDIRECT_HDR]
101#define nd_opts_mtu nd_opt_array[ND_OPT_MTU]
102
103#define NDISC_OPT_SPACE(len) (((len)+2+7)&~7)
104
105extern struct ndisc_options *ndisc_parse_options(u8 *opt, int opt_len,
106 struct ndisc_options *ndopts);
107
108/*
109 * Return the padding between the option length and the start of the
110 * link addr. Currently only IP-over-InfiniBand needs this, although
111 * if RFC 3831 IPv6-over-Fibre Channel is ever implemented it may
112 * also need a pad of 2.
113 */
114static int ndisc_addr_option_pad(unsigned short type)
115{
116 switch (type) {
117 case ARPHRD_INFINIBAND: return 2;
118 default: return 0;
119 }
120}
121
122static inline u8 *ndisc_opt_addr_data(struct nd_opt_hdr *p,
123 struct net_device *dev)
124{
125 u8 *lladdr = (u8 *)(p + 1);
126 int lladdrlen = p->nd_opt_len << 3;
127 int prepad = ndisc_addr_option_pad(dev->type);
128 if (lladdrlen != NDISC_OPT_SPACE(dev->addr_len + prepad))
129 return NULL;
130 return lladdr + prepad;
131}
132
83static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, __u32 *hash_rnd) 133static inline u32 ndisc_hashfn(const void *pkey, const struct net_device *dev, __u32 *hash_rnd)
84{ 134{
85 const u32 *p32 = pkey; 135 const u32 *p32 = pkey;
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 0fddd571400d..a3189baa9f4f 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -143,40 +143,8 @@ struct neigh_table nd_tbl = {
143 .gc_thresh3 = 1024, 143 .gc_thresh3 = 1024,
144}; 144};
145 145
146/* ND options */
147struct ndisc_options {
148 struct nd_opt_hdr *nd_opt_array[__ND_OPT_ARRAY_MAX];
149#ifdef CONFIG_IPV6_ROUTE_INFO
150 struct nd_opt_hdr *nd_opts_ri;
151 struct nd_opt_hdr *nd_opts_ri_end;
152#endif
153 struct nd_opt_hdr *nd_useropts;
154 struct nd_opt_hdr *nd_useropts_end;
155};
156
157#define nd_opts_src_lladdr nd_opt_array[ND_OPT_SOURCE_LL_ADDR]
158#define nd_opts_tgt_lladdr nd_opt_array[ND_OPT_TARGET_LL_ADDR]
159#define nd_opts_pi nd_opt_array[ND_OPT_PREFIX_INFO]
160#define nd_opts_pi_end nd_opt_array[__ND_OPT_PREFIX_INFO_END]
161#define nd_opts_rh nd_opt_array[ND_OPT_REDIRECT_HDR]
162#define nd_opts_mtu nd_opt_array[ND_OPT_MTU]
163
164#define NDISC_OPT_SPACE(len) (((len)+2+7)&~7) 146#define NDISC_OPT_SPACE(len) (((len)+2+7)&~7)
165 147
166/*
167 * Return the padding between the option length and the start of the
168 * link addr. Currently only IP-over-InfiniBand needs this, although
169 * if RFC 3831 IPv6-over-Fibre Channel is ever implemented it may
170 * also need a pad of 2.
171 */
172static int ndisc_addr_option_pad(unsigned short type)
173{
174 switch (type) {
175 case ARPHRD_INFINIBAND: return 2;
176 default: return 0;
177 }
178}
179
180static inline int ndisc_opt_addr_space(struct net_device *dev) 148static inline int ndisc_opt_addr_space(struct net_device *dev)
181{ 149{
182 return NDISC_OPT_SPACE(dev->addr_len + ndisc_addr_option_pad(dev->type)); 150 return NDISC_OPT_SPACE(dev->addr_len + ndisc_addr_option_pad(dev->type));
@@ -233,8 +201,8 @@ static struct nd_opt_hdr *ndisc_next_useropt(struct nd_opt_hdr *cur,
233 return cur <= end && ndisc_is_useropt(cur) ? cur : NULL; 201 return cur <= end && ndisc_is_useropt(cur) ? cur : NULL;
234} 202}
235 203
236static struct ndisc_options *ndisc_parse_options(u8 *opt, int opt_len, 204struct ndisc_options *ndisc_parse_options(u8 *opt, int opt_len,
237 struct ndisc_options *ndopts) 205 struct ndisc_options *ndopts)
238{ 206{
239 struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)opt; 207 struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)opt;
240 208
@@ -297,17 +265,6 @@ static struct ndisc_options *ndisc_parse_options(u8 *opt, int opt_len,
297 return ndopts; 265 return ndopts;
298} 266}
299 267
300static inline u8 *ndisc_opt_addr_data(struct nd_opt_hdr *p,
301 struct net_device *dev)
302{
303 u8 *lladdr = (u8 *)(p + 1);
304 int lladdrlen = p->nd_opt_len << 3;
305 int prepad = ndisc_addr_option_pad(dev->type);
306 if (lladdrlen != NDISC_OPT_SPACE(dev->addr_len + prepad))
307 return NULL;
308 return lladdr + prepad;
309}
310
311int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir) 268int ndisc_mc_map(const struct in6_addr *addr, char *buf, struct net_device *dev, int dir)
312{ 269{
313 switch (dev->type) { 270 switch (dev->type) {