Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / proto / babel / config.Y @ 6b3f1a54

History | View | Annotate | Download (4.88 KB)

1
/*
2
 *	BIRD -- Babel Configuration
3
 *
4
 *	Copyright (c) 2015-2016 Toke Hoiland-Jorgensen
5
 * 	(c) 2016--2017 Ondrej Zajicek <santiago@crfreenet.org>
6
 *	(c) 2016--2017 CZ.NIC z.s.p.o.
7
 *
8
 *	Can be freely distributed and used under the terms of the GNU GPL.
9
 */
10

    
11

    
12

    
13
CF_HDR
14

    
15
#include "proto/babel/babel.h"
16
#include "nest/iface.h"
17

    
18
CF_DEFINES
19

    
20
#define BABEL_CFG ((struct babel_config *) this_proto)
21
#define BABEL_IFACE ((struct babel_iface_config *) this_ipatt)
22

    
23
CF_DECLS
24

    
25
CF_KEYWORDS(BABEL, METRIC, RXCOST, HELLO, UPDATE, INTERVAL, PORT, WIRED,
26
	WIRELESS, RX, TX, BUFFER, LENGTH, CHECK, LINK, BABEL_METRIC, NEXT, HOP,
27
	IPV4, IPV6)
28

    
29
CF_GRAMMAR
30

    
31
CF_ADDTO(proto, babel_proto)
32

    
33
babel_proto_start: proto_start BABEL
34
{
35
  this_proto = proto_config_new(&proto_babel, $1);
36
  init_list(&BABEL_CFG->iface_list);
37
  BABEL_CFG->hold_time = 1 S_;
38
};
39

    
40
babel_proto_item:
41
   proto_item
42
 | proto_channel
43
 | INTERFACE babel_iface
44
 ;
45

    
46
babel_proto_opts:
47
   /* empty */
48
 | babel_proto_opts babel_proto_item ';'
49
 ;
50

    
51
babel_proto:
52
   babel_proto_start proto_name '{' babel_proto_opts '}';
53

    
54

    
55
babel_iface_start:
56
{
57
  this_ipatt = cfg_allocz(sizeof(struct babel_iface_config));
58
  add_tail(&BABEL_CFG->iface_list, NODE this_ipatt);
59
  init_list(&this_ipatt->ipn_list);
60
  BABEL_IFACE->port = BABEL_PORT;
61
  BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRED;
62
  BABEL_IFACE->limit = BABEL_HELLO_LIMIT;
63
  BABEL_IFACE->tx_tos = IP_PREC_INTERNET_CONTROL;
64
  BABEL_IFACE->tx_priority = sk_priority_control;
65
  BABEL_IFACE->check_link = 1;
66
};
67

    
68

    
69
babel_iface_finish:
70
{
71
  if (BABEL_IFACE->type == BABEL_IFACE_TYPE_WIRELESS)
72
  {
73
    if (!BABEL_IFACE->hello_interval)
74
      BABEL_IFACE->hello_interval = BABEL_HELLO_INTERVAL_WIRELESS;
75
    if (!BABEL_IFACE->rxcost)
76
      BABEL_IFACE->rxcost = BABEL_RXCOST_WIRELESS;
77
  }
78
  else
79
  {
80
    if (!BABEL_IFACE->hello_interval)
81
      BABEL_IFACE->hello_interval = BABEL_HELLO_INTERVAL_WIRED;
82
    if (!BABEL_IFACE->rxcost)
83
      BABEL_IFACE->rxcost = BABEL_RXCOST_WIRED;
84
  }
85

    
86
  /* Make sure we do not overflow the 16-bit centisec fields */
87
  if (!BABEL_IFACE->update_interval)
88
    BABEL_IFACE->update_interval = MIN_(BABEL_IFACE->hello_interval*BABEL_UPDATE_INTERVAL_FACTOR, BABEL_MAX_INTERVAL);
89
  BABEL_IFACE->ihu_interval = MIN_(BABEL_IFACE->hello_interval*BABEL_IHU_INTERVAL_FACTOR, BABEL_MAX_INTERVAL);
90

    
91
  BABEL_CFG->hold_time = MAX_(BABEL_CFG->hold_time, BABEL_IFACE->update_interval*BABEL_HOLD_TIME_FACTOR);
92
};
93

    
94

    
95
babel_iface_item:
96
 | PORT expr { BABEL_IFACE->port = $2; if (($2<1) || ($2>65535)) cf_error("Invalid port number"); }
97
 | RXCOST expr { BABEL_IFACE->rxcost = $2; if (($2<1) || ($2>65535)) cf_error("Invalid rxcost"); }
98
 | LIMIT expr { BABEL_IFACE->limit = $2; if (($2<1) || ($2>16)) cf_error("Limit must be in range 1-16"); }
99
 | TYPE WIRED { BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRED; }
100
 | TYPE WIRELESS { BABEL_IFACE->type = BABEL_IFACE_TYPE_WIRELESS; }
101
 | HELLO INTERVAL expr_us { BABEL_IFACE->hello_interval = $3; if (($3<BABEL_MIN_INTERVAL) || ($3>BABEL_MAX_INTERVAL)) cf_error("Hello interval must be in range 10 ms - 655 s"); }
102
 | UPDATE INTERVAL expr_us { BABEL_IFACE->update_interval = $3; if (($3<BABEL_MIN_INTERVAL) || ($3>BABEL_MAX_INTERVAL)) cf_error("Update interval must be in range 10 ms - 655 s"); }
103
 | RX BUFFER expr { BABEL_IFACE->rx_buffer = $3; if (($3<256) || ($3>65535)) cf_error("RX buffer must be in range 256-65535"); }
104
 | TX LENGTH expr { BABEL_IFACE->tx_length = $3; if (($3<256) || ($3>65535)) cf_error("TX length must be in range 256-65535"); }
105
 | TX tos { BABEL_IFACE->tx_tos = $2; }
106
 | TX PRIORITY expr { BABEL_IFACE->tx_priority = $3; }
107
 | CHECK LINK bool { BABEL_IFACE->check_link = $3; }
108
 | NEXT HOP IPV4 ipa { BABEL_IFACE->next_hop_ip4 = $4; if (!ipa_is_ip4($4)) cf_error("Must be an IPv4 address"); }
109
 | NEXT HOP IPV6 ipa { BABEL_IFACE->next_hop_ip6 = $4; if (!ipa_is_ip6($4)) cf_error("Must be an IPv6 address"); }
110
 ;
111

    
112
babel_iface_opts:
113
   /* empty */
114
 | babel_iface_opts babel_iface_item ';'
115
 ;
116

    
117
babel_iface_opt_list:
118
   /* empty */
119
 | '{' babel_iface_opts '}'
120
 ;
121

    
122

    
123
babel_iface:
124
  babel_iface_start iface_patt_list_nopx babel_iface_opt_list babel_iface_finish;
125

    
126
CF_ADDTO(dynamic_attr, BABEL_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_BABEL_METRIC); })
127

    
128
CF_CLI_HELP(SHOW BABEL, ..., [[Show information about Babel protocol]]);
129

    
130
CF_CLI(SHOW BABEL INTERFACES, optsym opttext, [<name>] [\"<interface>\"], [[Show information about Babel interfaces]])
131
{ babel_show_interfaces(proto_get_named($4, &proto_babel), $5); };
132

    
133
CF_CLI(SHOW BABEL NEIGHBORS, optsym opttext, [<name>] [\"<interface>\"], [[Show information about Babel neighbors]])
134
{ babel_show_neighbors(proto_get_named($4, &proto_babel), $5); };
135

    
136
CF_CLI(SHOW BABEL ENTRIES, optsym opttext, [<name>], [[Show information about Babel prefix entries]])
137
{ babel_show_entries(proto_get_named($4, &proto_babel)); };
138

    
139
CF_CLI(SHOW BABEL ROUTES, optsym opttext, [<name>], [[Show information about Babel route entries]])
140
{ babel_show_routes(proto_get_named($4, &proto_babel)); };
141

    
142
CF_CODE
143

    
144
CF_END