xref: /openbmc/linux/include/net/ip6_route.h (revision 77d16f450ae0452d7d4b009f78debb1294fb435c)
11da177e4SLinus Torvalds #ifndef _NET_IP6_ROUTE_H
21da177e4SLinus Torvalds #define _NET_IP6_ROUTE_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds #define IP6_RT_PRIO_FW		16
51da177e4SLinus Torvalds #define IP6_RT_PRIO_USER	1024
61da177e4SLinus Torvalds #define IP6_RT_PRIO_ADDRCONF	256
71da177e4SLinus Torvalds #define IP6_RT_PRIO_KERN	512
81da177e4SLinus Torvalds #define IP6_RT_FLOW_MASK	0x00ff
91da177e4SLinus Torvalds 
1070ceb4f5SYOSHIFUJI Hideaki struct route_info {
1170ceb4f5SYOSHIFUJI Hideaki 	__u8			type;
1270ceb4f5SYOSHIFUJI Hideaki 	__u8			length;
1370ceb4f5SYOSHIFUJI Hideaki 	__u8			prefix_len;
1470ceb4f5SYOSHIFUJI Hideaki #if defined(__BIG_ENDIAN_BITFIELD)
1570ceb4f5SYOSHIFUJI Hideaki 	__u8			reserved_h:3,
1670ceb4f5SYOSHIFUJI Hideaki 				route_pref:2,
1770ceb4f5SYOSHIFUJI Hideaki 				reserved_l:3;
1870ceb4f5SYOSHIFUJI Hideaki #elif defined(__LITTLE_ENDIAN_BITFIELD)
1970ceb4f5SYOSHIFUJI Hideaki 	__u8			reserved_l:3,
2070ceb4f5SYOSHIFUJI Hideaki 				route_pref:2,
2170ceb4f5SYOSHIFUJI Hideaki 				reserved_h:3;
2270ceb4f5SYOSHIFUJI Hideaki #endif
2370ceb4f5SYOSHIFUJI Hideaki 	__u32			lifetime;
2470ceb4f5SYOSHIFUJI Hideaki 	__u8			prefix[0];	/* 0,8 or 16 */
2570ceb4f5SYOSHIFUJI Hideaki };
2670ceb4f5SYOSHIFUJI Hideaki 
271da177e4SLinus Torvalds #ifdef __KERNEL__
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #include <net/flow.h>
301da177e4SLinus Torvalds #include <net/ip6_fib.h>
311da177e4SLinus Torvalds #include <net/sock.h>
321da177e4SLinus Torvalds #include <linux/ip.h>
331da177e4SLinus Torvalds #include <linux/ipv6.h>
341da177e4SLinus Torvalds 
35*77d16f45SYOSHIFUJI Hideaki #define RT6_LOOKUP_F_IFACE	0x1
36*77d16f45SYOSHIFUJI Hideaki #define RT6_LOOKUP_F_REACHABLE	0x2
37*77d16f45SYOSHIFUJI Hideaki #define RT6_LOOKUP_F_HAS_SADDR	0x4
38*77d16f45SYOSHIFUJI Hideaki 
391da177e4SLinus Torvalds struct pol_chain {
401da177e4SLinus Torvalds 	int			type;
411da177e4SLinus Torvalds 	int			priority;
421da177e4SLinus Torvalds 	struct fib6_node	*rules;
431da177e4SLinus Torvalds 	struct pol_chain	*next;
441da177e4SLinus Torvalds };
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds extern struct rt6_info	ip6_null_entry;
471da177e4SLinus Torvalds 
48101367c2SThomas Graf #ifdef CONFIG_IPV6_MULTIPLE_TABLES
49101367c2SThomas Graf extern struct rt6_info	ip6_prohibit_entry;
50101367c2SThomas Graf extern struct rt6_info	ip6_blk_hole_entry;
51101367c2SThomas Graf #endif
52101367c2SThomas Graf 
531da177e4SLinus Torvalds extern int ip6_rt_gc_interval;
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds extern void			ip6_route_input(struct sk_buff *skb);
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds extern struct dst_entry *	ip6_route_output(struct sock *sk,
581da177e4SLinus Torvalds 						 struct flowi *fl);
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds extern int			ip6_route_me_harder(struct sk_buff *skb);
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds extern void			ip6_route_init(void);
631da177e4SLinus Torvalds extern void			ip6_route_cleanup(void);
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds extern int			ipv6_route_ioctl(unsigned int cmd, void __user *arg);
661da177e4SLinus Torvalds 
6786872cb5SThomas Graf extern int			ip6_route_add(struct fib6_config *cfg);
6840e22e8fSThomas Graf extern int			ip6_ins_rt(struct rt6_info *);
69e0a1ad73SThomas Graf extern int			ip6_del_rt(struct rt6_info *);
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds extern int			ip6_rt_addr_add(struct in6_addr *addr,
721da177e4SLinus Torvalds 						struct net_device *dev,
731da177e4SLinus Torvalds 						int anycast);
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds extern int			ip6_rt_addr_del(struct in6_addr *addr,
761da177e4SLinus Torvalds 						struct net_device *dev);
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds extern void			rt6_sndmsg(int type, struct in6_addr *dst,
791da177e4SLinus Torvalds 					   struct in6_addr *src,
801da177e4SLinus Torvalds 					   struct in6_addr *gw,
811da177e4SLinus Torvalds 					   struct net_device *dev,
821da177e4SLinus Torvalds 					   int dstlen, int srclen,
831da177e4SLinus Torvalds 					   int metric, __u32 flags);
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds extern struct rt6_info		*rt6_lookup(struct in6_addr *daddr,
861da177e4SLinus Torvalds 					    struct in6_addr *saddr,
871da177e4SLinus Torvalds 					    int oif, int flags);
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds extern struct dst_entry *ndisc_dst_alloc(struct net_device *dev,
901da177e4SLinus Torvalds 					 struct neighbour *neigh,
911da177e4SLinus Torvalds 					 struct in6_addr *addr,
921da177e4SLinus Torvalds 					 int (*output)(struct sk_buff *));
931da177e4SLinus Torvalds extern int ndisc_dst_gc(int *more);
941da177e4SLinus Torvalds extern void fib6_force_start_gc(void);
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds extern struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
971da177e4SLinus Torvalds 					   const struct in6_addr *addr,
981da177e4SLinus Torvalds 					   int anycast);
991da177e4SLinus Torvalds 
1001da177e4SLinus Torvalds /*
1011da177e4SLinus Torvalds  *	support functions for ND
1021da177e4SLinus Torvalds  *
1031da177e4SLinus Torvalds  */
1041da177e4SLinus Torvalds extern struct rt6_info *	rt6_get_dflt_router(struct in6_addr *addr,
1051da177e4SLinus Torvalds 						    struct net_device *dev);
1061da177e4SLinus Torvalds extern struct rt6_info *	rt6_add_dflt_router(struct in6_addr *gwaddr,
107ebacaaa0SYOSHIFUJI Hideaki 						    struct net_device *dev,
108ebacaaa0SYOSHIFUJI Hideaki 						    unsigned int pref);
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds extern void			rt6_purge_dflt_routers(void);
1111da177e4SLinus Torvalds 
11270ceb4f5SYOSHIFUJI Hideaki extern int			rt6_route_rcv(struct net_device *dev,
11370ceb4f5SYOSHIFUJI Hideaki 					      u8 *opt, int len,
11470ceb4f5SYOSHIFUJI Hideaki 					      struct in6_addr *gwaddr);
11570ceb4f5SYOSHIFUJI Hideaki 
1161da177e4SLinus Torvalds extern void			rt6_redirect(struct in6_addr *dest,
1175e032e32SYOSHIFUJI Hideaki 					     struct in6_addr *src,
1181da177e4SLinus Torvalds 					     struct in6_addr *saddr,
1191da177e4SLinus Torvalds 					     struct neighbour *neigh,
1201da177e4SLinus Torvalds 					     u8 *lladdr,
1211da177e4SLinus Torvalds 					     int on_link);
1221da177e4SLinus Torvalds 
1231da177e4SLinus Torvalds extern void			rt6_pmtu_discovery(struct in6_addr *daddr,
1241da177e4SLinus Torvalds 						   struct in6_addr *saddr,
1251da177e4SLinus Torvalds 						   struct net_device *dev,
1261da177e4SLinus Torvalds 						   u32 pmtu);
1271da177e4SLinus Torvalds 
1281da177e4SLinus Torvalds struct nlmsghdr;
1291da177e4SLinus Torvalds struct netlink_callback;
1301da177e4SLinus Torvalds extern int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb);
1311da177e4SLinus Torvalds extern int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
1321da177e4SLinus Torvalds extern int inet6_rtm_delroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
1331da177e4SLinus Torvalds extern int inet6_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg);
1341da177e4SLinus Torvalds 
1351b43af54SPatrick McHardy struct rt6_rtnl_dump_arg
1361b43af54SPatrick McHardy {
1371b43af54SPatrick McHardy 	struct sk_buff *skb;
1381b43af54SPatrick McHardy 	struct netlink_callback *cb;
1391b43af54SPatrick McHardy };
1401b43af54SPatrick McHardy 
1411b43af54SPatrick McHardy extern int rt6_dump_route(struct rt6_info *rt, void *p_arg);
1421da177e4SLinus Torvalds extern void rt6_ifdown(struct net_device *dev);
1431da177e4SLinus Torvalds extern void rt6_mtu_change(struct net_device *dev, unsigned mtu);
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds extern rwlock_t rt6_lock;
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds /*
1481da177e4SLinus Torvalds  *	Store a destination cache entry in a socket
1491da177e4SLinus Torvalds  */
150497c615aSHerbert Xu static inline void __ip6_dst_store(struct sock *sk, struct dst_entry *dst,
1518e1ef0a9SYOSHIFUJI Hideaki 				   struct in6_addr *daddr, struct in6_addr *saddr)
1521da177e4SLinus Torvalds {
1531da177e4SLinus Torvalds 	struct ipv6_pinfo *np = inet6_sk(sk);
1541da177e4SLinus Torvalds 	struct rt6_info *rt = (struct rt6_info *) dst;
1551da177e4SLinus Torvalds 
156f83ef8c0SHerbert Xu 	sk_setup_caps(sk, dst);
1571da177e4SLinus Torvalds 	np->daddr_cache = daddr;
1588e1ef0a9SYOSHIFUJI Hideaki #ifdef CONFIG_IPV6_SUBTREES
1598e1ef0a9SYOSHIFUJI Hideaki 	np->saddr_cache = saddr;
1608e1ef0a9SYOSHIFUJI Hideaki #endif
1611da177e4SLinus Torvalds 	np->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
162497c615aSHerbert Xu }
163497c615aSHerbert Xu 
164497c615aSHerbert Xu static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
1658e1ef0a9SYOSHIFUJI Hideaki 				 struct in6_addr *daddr, struct in6_addr *saddr)
166497c615aSHerbert Xu {
167497c615aSHerbert Xu 	write_lock(&sk->sk_dst_lock);
1688e1ef0a9SYOSHIFUJI Hideaki 	__ip6_dst_store(sk, dst, daddr, saddr);
1691da177e4SLinus Torvalds 	write_unlock(&sk->sk_dst_lock);
1701da177e4SLinus Torvalds }
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds static inline int ipv6_unicast_destination(struct sk_buff *skb)
1731da177e4SLinus Torvalds {
1741da177e4SLinus Torvalds 	struct rt6_info *rt = (struct rt6_info *) skb->dst;
1751da177e4SLinus Torvalds 
1761da177e4SLinus Torvalds 	return rt->rt6i_flags & RTF_LOCAL;
1771da177e4SLinus Torvalds }
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds #endif
1801da177e4SLinus Torvalds #endif
181