ip_mp_alg.h 2.5 KB

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