1 /* ip_mp_alg.h: IPV4 multipath algorithm support.
3 * Copyright (C) 2004, 2005 Einar Lueck <elueck@de.ibm.com>
4 * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
7 #ifndef _NET_IP_MP_ALG_H
8 #define _NET_IP_MP_ALG_H
10 #include <linux/ip_mp_alg.h>
12 #include <net/route.h>
16 struct ip_mp_alg_ops
{
17 void (*mp_alg_select_route
)(const struct flowi
*flp
,
18 struct rtable
*rth
, struct rtable
**rp
);
19 void (*mp_alg_flush
)(void);
20 void (*mp_alg_set_nhinfo
)(__be32 network
, __be32 netmask
,
21 unsigned char prefixlen
,
22 const struct fib_nh
*nh
);
23 void (*mp_alg_remove
)(struct rtable
*rth
);
26 extern int multipath_alg_register(struct ip_mp_alg_ops
*, enum ip_mp_alg
);
27 extern void multipath_alg_unregister(struct ip_mp_alg_ops
*, enum ip_mp_alg
);
29 extern struct ip_mp_alg_ops
*ip_mp_alg_table
[];
31 static inline int multipath_select_route(const struct flowi
*flp
,
35 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
36 struct ip_mp_alg_ops
*ops
= ip_mp_alg_table
[rth
->rt_multipath_alg
];
38 /* mp_alg_select_route _MUST_ be implemented */
39 if (ops
&& (rth
->u
.dst
.flags
& DST_BALANCED
)) {
40 ops
->mp_alg_select_route(flp
, rth
, rp
);
47 static inline void multipath_flush(void)
49 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
52 for (i
= IP_MP_ALG_NONE
; i
<= IP_MP_ALG_MAX
; i
++) {
53 struct ip_mp_alg_ops
*ops
= ip_mp_alg_table
[i
];
55 if (ops
&& ops
->mp_alg_flush
)
61 static inline void multipath_set_nhinfo(struct rtable
*rth
,
62 __be32 network
, __be32 netmask
,
63 unsigned char prefixlen
,
64 const struct fib_nh
*nh
)
66 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
67 struct ip_mp_alg_ops
*ops
= ip_mp_alg_table
[rth
->rt_multipath_alg
];
69 if (ops
&& ops
->mp_alg_set_nhinfo
)
70 ops
->mp_alg_set_nhinfo(network
, netmask
, prefixlen
, nh
);
74 static inline void multipath_remove(struct rtable
*rth
)
76 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
77 struct ip_mp_alg_ops
*ops
= ip_mp_alg_table
[rth
->rt_multipath_alg
];
79 if (ops
&& ops
->mp_alg_remove
&&
80 (rth
->u
.dst
.flags
& DST_BALANCED
))
81 ops
->mp_alg_remove(rth
);
85 static inline int multipath_comparekeys(const struct flowi
*flp1
,
86 const struct flowi
*flp2
)
88 return flp1
->fl4_dst
== flp2
->fl4_dst
&&
89 flp1
->fl4_src
== flp2
->fl4_src
&&
90 flp1
->oif
== flp2
->oif
&&
91 flp1
->mark
== flp2
->mark
&&
92 !((flp1
->fl4_tos
^ flp2
->fl4_tos
) &
93 (IPTOS_RT_MASK
| RTO_ONLINK
));
96 #endif /* _NET_IP_MP_ALG_H */