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