iprule.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * netifd - network interface daemon
  3. * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4. * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2
  8. * as published by the Free Software Foundation
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef __IPRULE_H
  16. #define __IPRULE_H
  17. #include "interface-ip.h"
  18. #define IPRULE_PRIORITY_ADDR 10000
  19. #define IPRULE_PRIORITY_ADDR_MASK 20000
  20. #define IPRULE_PRIORITY_NW 90000
  21. #define IPRULE_PRIORITY_REJECT 4200000000
  22. enum iprule_flags {
  23. /* address family for rule */
  24. IPRULE_INET4 = (0 << 0),
  25. IPRULE_INET6 = (1 << 0),
  26. IPRULE_FAMILY = IPRULE_INET4 | IPRULE_INET6,
  27. /* rule specifies input device */
  28. IPRULE_IN = (1 << 2),
  29. /* rule specifies output device */
  30. IPRULE_OUT = (1 << 3),
  31. /* rule specifies src */
  32. IPRULE_SRC = (1 << 4),
  33. /* rule specifies dest */
  34. IPRULE_DEST = (1 << 5),
  35. /* rule specifies priority */
  36. IPRULE_PRIORITY = (1 << 6),
  37. /* rule specifies diffserv/tos */
  38. IPRULE_TOS = (1 << 7),
  39. /* rule specifies fwmark */
  40. IPRULE_FWMARK = (1 << 8),
  41. /* rule specifies fwmask */
  42. IPRULE_FWMASK = (1 << 9),
  43. /* rule performs table lookup */
  44. IPRULE_LOOKUP = (1 << 10),
  45. /* rule performs routing action */
  46. IPRULE_ACTION = (1 << 11),
  47. /* rule is a goto */
  48. IPRULE_GOTO = (1 << 12),
  49. /* rule suppresses results by prefix length */
  50. IPRULE_SUP_PREFIXLEN = (1 << 13),
  51. };
  52. struct iprule {
  53. struct vlist_node node;
  54. unsigned int order;
  55. /* to receive interface events */
  56. struct interface_user in_iface_user;
  57. struct interface_user out_iface_user;
  58. /* device name */
  59. char in_dev[IFNAMSIZ + 1];
  60. char out_dev[IFNAMSIZ + 1];
  61. /* everything below is used as avl tree key */
  62. /* don't change the order */
  63. /* uci interface name */
  64. char *in_iface;
  65. char *out_iface;
  66. enum iprule_flags flags;
  67. bool invert;
  68. unsigned int src_mask;
  69. union if_addr src_addr;
  70. unsigned int dest_mask;
  71. union if_addr dest_addr;
  72. unsigned int priority;
  73. unsigned int tos;
  74. unsigned int fwmark;
  75. unsigned int fwmask;
  76. unsigned int lookup;
  77. unsigned int sup_prefixlen;
  78. unsigned int action;
  79. unsigned int gotoid;
  80. };
  81. extern struct vlist_tree iprules;
  82. extern const struct uci_blob_param_list rule_attr_list;
  83. void iprule_add(struct blob_attr *attr, bool v6);
  84. void iprule_update_start(void);
  85. void iprule_update_complete(void);
  86. #endif