ip_mp_alg.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* ip_mp_alg.h: IPV4 multipath algorithm support.
  2. *
  3. * Copyright (C) 2004, 2005 Einar Lueck <elueck@de.ibm.com>
  4. * Copyright (C) 2005 David S. Miller <davem@davemloft.net>
  5. */
  6. #ifndef _NET_IP_MP_ALG_H
  7. #define _NET_IP_MP_ALG_H
  8. #include <linux/ip_mp_alg.h>
  9. #include <net/flow.h>
  10. #include <net/route.h>
  11. struct fib_nh;
  12. struct ip_mp_alg_ops {
  13. void (*mp_alg_select_route)(const struct flowi *flp,
  14. struct rtable *rth, struct rtable **rp);
  15. void (*mp_alg_flush)(void);
  16. void (*mp_alg_set_nhinfo)(__u32 network, __u32 netmask,
  17. unsigned char prefixlen,
  18. const struct fib_nh *nh);
  19. void (*mp_alg_remove)(struct rtable *rth);
  20. };
  21. extern int multipath_alg_register(struct ip_mp_alg_ops *, enum ip_mp_alg);
  22. extern void multipath_alg_unregister(struct ip_mp_alg_ops *, enum ip_mp_alg);
  23. extern struct ip_mp_alg_ops *ip_mp_alg_table[];
  24. static inline int multipath_select_route(const struct flowi *flp,
  25. struct rtable *rth,
  26. struct rtable **rp)
  27. {
  28. #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
  29. struct ip_mp_alg_ops *ops = ip_mp_alg_table[rth->rt_multipath_alg];
  30. /* mp_alg_select_route _MUST_ be implemented */
  31. if (ops && (rth->u.dst.flags & DST_BALANCED)) {
  32. ops->mp_alg_select_route(flp, rth, rp);
  33. return 1;
  34. }
  35. #endif
  36. return 0;
  37. }
  38. static inline void multipath_flush(void)
  39. {
  40. #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
  41. int i;
  42. for (i = IP_MP_ALG_NONE; i <= IP_MP_ALG_MAX; i++) {
  43. struct ip_mp_alg_ops *ops = ip_mp_alg_table[i];
  44. if (ops && ops->mp_alg_flush)
  45. ops->mp_alg_flush();
  46. }
  47. #endif
  48. }
  49. static inline void multipath_set_nhinfo(struct rtable *rth,
  50. __u32 network, __u32 netmask,
  51. unsigned char prefixlen,
  52. const struct fib_nh *nh)
  53. {
  54. #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
  55. struct ip_mp_alg_ops *ops = ip_mp_alg_table[rth->rt_multipath_alg];
  56. if (ops && ops->mp_alg_set_nhinfo)
  57. ops->mp_alg_set_nhinfo(network, netmask, prefixlen, nh);
  58. #endif
  59. }
  60. static inline void multipath_remove(struct rtable *rth)
  61. {
  62. #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
  63. struct ip_mp_alg_ops *ops = ip_mp_alg_table[rth->rt_multipath_alg];
  64. if (ops && ops->mp_alg_remove &&
  65. (rth->u.dst.flags & DST_BALANCED))
  66. ops->mp_alg_remove(rth);
  67. #endif
  68. }
  69. static inline int multipath_comparekeys(const struct flowi *flp1,
  70. const struct flowi *flp2)
  71. {
  72. return flp1->fl4_dst == flp2->fl4_dst &&
  73. flp1->fl4_src == flp2->fl4_src &&
  74. flp1->oif == flp2->oif &&
  75. #ifdef CONFIG_IP_ROUTE_FWMARK
  76. flp1->fl4_fwmark == flp2->fl4_fwmark &&
  77. #endif
  78. !((flp1->fl4_tos ^ flp2->fl4_tos) &
  79. (IPTOS_RT_MASK | RTO_ONLINK));
  80. }
  81. #endif /* _NET_IP_MP_ALG_H */