1: /*
2: * BIRD -- Static Protocol Configuration
3: *
4: * (c) 1998--1999 Martin Mares <mj@ucw.cz>
5: *
6: * Can be freely distributed and used under the terms of the GNU GPL.
7: */
8:
9: CF_HDR
10:
11: #include "proto/static/static.h"
12:
13: CF_DEFINES
14:
15: #define STATIC_CFG ((struct static_config *) this_proto)
16: static struct static_route *this_srt, *this_srt_nh, *last_srt_nh;
17: static struct f_inst **this_srt_last_cmd;
18:
19: static void
20: static_route_finish(void)
21: {
22: struct static_route *r;
23:
24: /* Update undefined use_bfd entries in multipath nexthops */
25: if (this_srt->dest == RTD_MULTIPATH)
26: for (r = this_srt->mp_next; r; r = r->mp_next)
27: if (r->use_bfd < 0)
28: r->use_bfd = this_srt->use_bfd;
29: }
30:
31: CF_DECLS
32:
33: CF_KEYWORDS(STATIC, ROUTE, VIA, DROP, REJECT, PROHIBIT, PREFERENCE, CHECK, LINK)
34: CF_KEYWORDS(MULTIPATH, WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD)
35:
36:
37: CF_GRAMMAR
38:
39: CF_ADDTO(proto, static_proto '}')
40:
41: static_proto_start: proto_start STATIC {
42: this_proto = proto_config_new(&proto_static, $1);
43: static_init_config((struct static_config *) this_proto);
44: }
45: ;
46:
47: static_proto:
48: static_proto_start proto_name '{'
49: | static_proto proto_item ';'
50: | static_proto CHECK LINK bool ';' { STATIC_CFG->check_link = $4; }
51: | static_proto IGP TABLE rtable ';' { STATIC_CFG->igp_table = $4; }
52: | static_proto stat_route stat_route_opt_list ';' { static_route_finish(); }
53: ;
54:
55: stat_route0: ROUTE prefix {
56: this_srt = cfg_allocz(sizeof(struct static_route));
57: add_tail(&STATIC_CFG->other_routes, &this_srt->n);
58: this_srt->net = $2.addr;
59: this_srt->masklen = $2.len;
60: this_srt_last_cmd = &(this_srt->cmds);
61: }
62: ;
63:
64: stat_multipath1:
65: VIA ipa ipa_scope {
66: last_srt_nh = this_srt_nh;
67: this_srt_nh = cfg_allocz(sizeof(struct static_route));
68: this_srt_nh->dest = RTD_NONE;
69: this_srt_nh->via = $2;
70: this_srt_nh->via_if = $3;
71: this_srt_nh->if_name = (void *) this_srt; /* really */
72: this_srt_nh->use_bfd = -1; /* undefined */
73: }
74: | stat_multipath1 WEIGHT expr {
75: this_srt_nh->masklen = $3 - 1; /* really */
76: if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256");
77: }
78: | stat_multipath1 BFD bool {
79: this_srt_nh->use_bfd = $3; cf_check_bfd($3);
80: }
81: ;
82:
83: stat_multipath:
84: stat_multipath1 { this_srt->mp_next = this_srt_nh; }
85: | stat_multipath stat_multipath1 { last_srt_nh->mp_next = this_srt_nh; }
86: ;
87:
88: stat_route:
89: stat_route0 VIA ipa ipa_scope {
90: this_srt->dest = RTD_ROUTER;
91: this_srt->via = $3;
92: this_srt->via_if = $4;
93: }
94: | stat_route0 VIA TEXT {
95: this_srt->dest = RTD_DEVICE;
96: this_srt->if_name = $3;
97: rem_node(&this_srt->n);
98: add_tail(&STATIC_CFG->iface_routes, &this_srt->n);
99: }
100: | stat_route0 MULTIPATH stat_multipath {
101: this_srt->dest = RTD_MULTIPATH;
102: }
103: | stat_route0 RECURSIVE ipa {
104: this_srt->dest = RTDX_RECURSIVE;
105: this_srt->via = $3;
106: }
107:
108: | stat_route0 DROP { this_srt->dest = RTD_BLACKHOLE; }
109: | stat_route0 REJECT { this_srt->dest = RTD_UNREACHABLE; }
110: | stat_route0 BLACKHOLE { this_srt->dest = RTD_BLACKHOLE; }
111: | stat_route0 UNREACHABLE { this_srt->dest = RTD_UNREACHABLE; }
112: | stat_route0 PROHIBIT { this_srt->dest = RTD_PROHIBIT; }
113: ;
114:
115: stat_route_item:
116: cmd { *this_srt_last_cmd = $1; this_srt_last_cmd = &($1->next); }
117: | BFD bool ';' { this_srt->use_bfd = $2; cf_check_bfd($2); }
118: ;
119:
120: stat_route_opts:
121: /* empty */
122: | stat_route_opts stat_route_item
123: ;
124:
125: stat_route_opt_list:
126: /* empty */
127: | '{' stat_route_opts '}'
128: ;
129:
130:
131: CF_CLI(SHOW STATIC, optsym, [<name>], [[Show details of static protocol]])
132: { static_show(proto_get_named($3, &proto_static)); } ;
133:
134: CF_CODE
135:
136: CF_END
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>