2 * IPv6 library code, needed by static components when full IPv6 support is
3 * not configured or static.
6 #include <linux/export.h>
8 #include <net/addrconf.h>
11 /* if ipv6 module registers this function is used by xfrm to force all
12 * sockets to relookup their nodes - this is fairly expensive, be
15 void (*__fib6_flush_trees
)(struct net
*);
16 EXPORT_SYMBOL(__fib6_flush_trees
);
18 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
20 static inline unsigned int ipv6_addr_scope2type(unsigned int scope
)
23 case IPV6_ADDR_SCOPE_NODELOCAL
:
24 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL
) |
26 case IPV6_ADDR_SCOPE_LINKLOCAL
:
27 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
) |
29 case IPV6_ADDR_SCOPE_SITELOCAL
:
30 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
) |
33 return IPV6_ADDR_SCOPE_TYPE(scope
);
36 int __ipv6_addr_type(const struct in6_addr
*addr
)
40 st
= addr
->s6_addr32
[0];
42 /* Consider all addresses with the first three bits different of
43 000 and 111 as unicasts.
45 if ((st
& htonl(0xE0000000)) != htonl(0x00000000) &&
46 (st
& htonl(0xE0000000)) != htonl(0xE0000000))
47 return (IPV6_ADDR_UNICAST
|
48 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
));
50 if ((st
& htonl(0xFF000000)) == htonl(0xFF000000)) {
53 return (IPV6_ADDR_MULTICAST
|
54 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr
)));
57 if ((st
& htonl(0xFFC00000)) == htonl(0xFE800000))
58 return (IPV6_ADDR_LINKLOCAL
| IPV6_ADDR_UNICAST
|
59 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.1 */
60 if ((st
& htonl(0xFFC00000)) == htonl(0xFEC00000))
61 return (IPV6_ADDR_SITELOCAL
| IPV6_ADDR_UNICAST
|
62 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
)); /* addr-select 3.1 */
63 if ((st
& htonl(0xFE000000)) == htonl(0xFC000000))
64 return (IPV6_ADDR_UNICAST
|
65 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* RFC 4193 */
67 if ((addr
->s6_addr32
[0] | addr
->s6_addr32
[1]) == 0) {
68 if (addr
->s6_addr32
[2] == 0) {
69 if (addr
->s6_addr32
[3] == 0)
72 if (addr
->s6_addr32
[3] == htonl(0x00000001))
73 return (IPV6_ADDR_LOOPBACK
| IPV6_ADDR_UNICAST
|
74 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.4 */
76 return (IPV6_ADDR_COMPATv4
| IPV6_ADDR_UNICAST
|
77 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
80 if (addr
->s6_addr32
[2] == htonl(0x0000ffff))
81 return (IPV6_ADDR_MAPPED
|
82 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
85 return (IPV6_ADDR_UNICAST
|
86 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.4 */
88 EXPORT_SYMBOL(__ipv6_addr_type
);
90 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain
);
91 static BLOCKING_NOTIFIER_HEAD(inet6addr_validator_chain
);
93 int register_inet6addr_notifier(struct notifier_block
*nb
)
95 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
97 EXPORT_SYMBOL(register_inet6addr_notifier
);
99 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
101 return atomic_notifier_chain_unregister(&inet6addr_chain
, nb
);
103 EXPORT_SYMBOL(unregister_inet6addr_notifier
);
105 int inet6addr_notifier_call_chain(unsigned long val
, void *v
)
107 return atomic_notifier_call_chain(&inet6addr_chain
, val
, v
);
109 EXPORT_SYMBOL(inet6addr_notifier_call_chain
);
111 int register_inet6addr_validator_notifier(struct notifier_block
*nb
)
113 return blocking_notifier_chain_register(&inet6addr_validator_chain
, nb
);
115 EXPORT_SYMBOL(register_inet6addr_validator_notifier
);
117 int unregister_inet6addr_validator_notifier(struct notifier_block
*nb
)
119 return blocking_notifier_chain_unregister(&inet6addr_validator_chain
,
122 EXPORT_SYMBOL(unregister_inet6addr_validator_notifier
);
124 int inet6addr_validator_notifier_call_chain(unsigned long val
, void *v
)
126 return blocking_notifier_call_chain(&inet6addr_validator_chain
, val
, v
);
128 EXPORT_SYMBOL(inet6addr_validator_notifier_call_chain
);
130 static struct dst_entry
*eafnosupport_ipv6_dst_lookup_flow(struct net
*net
,
131 const struct sock
*sk
,
133 const struct in6_addr
*final_dst
)
135 return ERR_PTR(-EAFNOSUPPORT
);
138 static struct fib6_table
*eafnosupport_fib6_get_table(struct net
*net
, u32 id
)
143 static struct fib6_info
*
144 eafnosupport_fib6_table_lookup(struct net
*net
, struct fib6_table
*table
,
145 int oif
, struct flowi6
*fl6
, int flags
)
150 static struct fib6_info
*
151 eafnosupport_fib6_lookup(struct net
*net
, int oif
, struct flowi6
*fl6
,
157 static struct fib6_info
*
158 eafnosupport_fib6_multipath_select(const struct net
*net
, struct fib6_info
*f6i
,
159 struct flowi6
*fl6
, int oif
,
160 const struct sk_buff
*skb
, int strict
)
166 eafnosupport_ip6_mtu_from_fib6(struct fib6_info
*f6i
, struct in6_addr
*daddr
,
167 struct in6_addr
*saddr
)
172 const struct ipv6_stub
*ipv6_stub __read_mostly
= &(struct ipv6_stub
) {
173 .ipv6_dst_lookup_flow
= eafnosupport_ipv6_dst_lookup_flow
,
174 .fib6_get_table
= eafnosupport_fib6_get_table
,
175 .fib6_table_lookup
= eafnosupport_fib6_table_lookup
,
176 .fib6_lookup
= eafnosupport_fib6_lookup
,
177 .fib6_multipath_select
= eafnosupport_fib6_multipath_select
,
178 .ip6_mtu_from_fib6
= eafnosupport_ip6_mtu_from_fib6
,
180 EXPORT_SYMBOL_GPL(ipv6_stub
);
182 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
183 const struct in6_addr in6addr_loopback
= IN6ADDR_LOOPBACK_INIT
;
184 EXPORT_SYMBOL(in6addr_loopback
);
185 const struct in6_addr in6addr_any
= IN6ADDR_ANY_INIT
;
186 EXPORT_SYMBOL(in6addr_any
);
187 const struct in6_addr in6addr_linklocal_allnodes
= IN6ADDR_LINKLOCAL_ALLNODES_INIT
;
188 EXPORT_SYMBOL(in6addr_linklocal_allnodes
);
189 const struct in6_addr in6addr_linklocal_allrouters
= IN6ADDR_LINKLOCAL_ALLROUTERS_INIT
;
190 EXPORT_SYMBOL(in6addr_linklocal_allrouters
);
191 const struct in6_addr in6addr_interfacelocal_allnodes
= IN6ADDR_INTERFACELOCAL_ALLNODES_INIT
;
192 EXPORT_SYMBOL(in6addr_interfacelocal_allnodes
);
193 const struct in6_addr in6addr_interfacelocal_allrouters
= IN6ADDR_INTERFACELOCAL_ALLROUTERS_INIT
;
194 EXPORT_SYMBOL(in6addr_interfacelocal_allrouters
);
195 const struct in6_addr in6addr_sitelocal_allrouters
= IN6ADDR_SITELOCAL_ALLROUTERS_INIT
;
196 EXPORT_SYMBOL(in6addr_sitelocal_allrouters
);
198 static void snmp6_free_dev(struct inet6_dev
*idev
)
200 kfree(idev
->stats
.icmpv6msgdev
);
201 kfree(idev
->stats
.icmpv6dev
);
202 free_percpu(idev
->stats
.ipv6
);
205 static void in6_dev_finish_destroy_rcu(struct rcu_head
*head
)
207 struct inet6_dev
*idev
= container_of(head
, struct inet6_dev
, rcu
);
209 snmp6_free_dev(idev
);
213 /* Nobody refers to this device, we may destroy it. */
215 void in6_dev_finish_destroy(struct inet6_dev
*idev
)
217 struct net_device
*dev
= idev
->dev
;
219 WARN_ON(!list_empty(&idev
->addr_list
));
220 WARN_ON(idev
->mc_list
);
221 WARN_ON(timer_pending(&idev
->rs_timer
));
223 #ifdef NET_REFCNT_DEBUG
224 pr_debug("%s: %s\n", __func__
, dev
? dev
->name
: "NIL");
228 pr_warn("Freeing alive inet6 device %p\n", idev
);
231 call_rcu(&idev
->rcu
, in6_dev_finish_destroy_rcu
);
233 EXPORT_SYMBOL(in6_dev_finish_destroy
);