Add support for ip rules
[project/netifd.git] / iprule.h
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
18 #include "interface-ip.h"
19
20 enum iprule_flags {
21 /* address family for rule */
22 IPRULE_INET4 = (0 << 0),
23 IPRULE_INET6 = (1 << 0),
24 IPRULE_FAMILY = IPRULE_INET4 | IPRULE_INET6,
25
26 /* rule specifies input device */
27 IPRULE_IN = (1 << 2),
28
29 /* rule specifies output device */
30 IPRULE_OUT = (1 << 3),
31
32 /* rule specifies src */
33 IPRULE_SRC = (1 << 4),
34
35 /* rule specifies dest */
36 IPRULE_DEST = (1 << 5),
37
38 /* rule specifies priority */
39 IPRULE_PRIORITY = (1 << 6),
40
41 /* rule specifies diffserv/tos */
42 IPRULE_TOS = (1 << 7),
43
44 /* rule specifies fwmark */
45 IPRULE_FWMARK = (1 << 8),
46
47 /* rule specifies fwmask */
48 IPRULE_FWMASK = (1 << 9),
49
50 /* rule performs table lookup */
51 IPRULE_LOOKUP = (1 << 10),
52
53 /* rule performs routing action */
54 IPRULE_ACTION = (1 << 11),
55
56 /* rule is a goto */
57 IPRULE_GOTO = (1 << 12),
58 };
59
60 struct iprule {
61 struct vlist_node node;
62
63 /* everything below is used as avl tree key */
64 enum iprule_flags flags;
65
66 bool invert;
67
68 char in_dev[IFNAMSIZ + 1];
69 char out_dev[IFNAMSIZ + 1];
70
71 unsigned int src_mask;
72 union if_addr src_addr;
73
74 unsigned int dest_mask;
75 union if_addr dest_addr;
76
77 unsigned int priority;
78 unsigned int tos;
79
80 unsigned int fwmark;
81 unsigned int fwmask;
82
83 unsigned int lookup;
84 unsigned int action;
85 unsigned int gotoid;
86 };
87
88 extern struct vlist_tree iprules;
89 extern const struct config_param_list rule_attr_list;
90
91 void iprule_add(struct blob_attr *attr, bool v6);
92 void iprule_update_start(void);
93 void iprule_update_complete(void);
94
95 #endif