iprule.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* rule specifies uidrange */
  52. IPRULE_UIDRANGE = (1 << 14),
  53. };
  54. struct iprule {
  55. struct vlist_node node;
  56. unsigned int order;
  57. /* to receive interface events */
  58. struct interface_user in_iface_user;
  59. struct interface_user out_iface_user;
  60. /* device name */
  61. char in_dev[IFNAMSIZ];
  62. char out_dev[IFNAMSIZ];
  63. /* everything below is used as avl tree key */
  64. /* don't change the order */
  65. /* uci interface name */
  66. char *in_iface;
  67. char *out_iface;
  68. enum iprule_flags flags;
  69. bool invert;
  70. unsigned int src_mask;
  71. union if_addr src_addr;
  72. unsigned int dest_mask;
  73. union if_addr dest_addr;
  74. unsigned int priority;
  75. unsigned int tos;
  76. unsigned int fwmark;
  77. unsigned int fwmask;
  78. unsigned int lookup;
  79. unsigned int sup_prefixlen;
  80. unsigned int uidrange_start;
  81. unsigned int uidrange_end;
  82. unsigned int action;
  83. unsigned int gotoid;
  84. };
  85. extern struct vlist_tree iprules;
  86. extern const struct uci_blob_param_list rule_attr_list;
  87. void iprule_add(struct blob_attr *attr, bool v6);
  88. void iprule_update_start(void);
  89. void iprule_update_complete(void);
  90. #endif