Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.65 KB)

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_snh;
17
static struct f_inst **this_srt_last_cmd;
18

    
19
static struct static_route *
20
static_nexthop_new(void)
21
{
22
  struct static_route *nh = this_srt;
23

    
24
  if (this_snh)
25
  {
26
    /* Additional next hop */
27
    nh = cfg_allocz(sizeof(struct static_route));
28
    nh->net = this_srt->net;
29
    this_snh->mp_next = nh;
30
  }
31

    
32
  nh->dest = RTD_UNICAST;
33
  nh->mp_head = this_srt;
34
  return nh;
35
};
36

    
37
static void
38
static_route_finish(void)
39
{
40
  if (net_type_match(this_srt->net, NB_DEST) == !this_srt->dest)
41
    cf_error("Unexpected or missing nexthop/type");
42
}
43

    
44
CF_DECLS
45

    
46
CF_KEYWORDS(STATIC, ROUTE, VIA, DROP, REJECT, PROHIBIT, PREFERENCE, CHECK, LINK)
47
CF_KEYWORDS(ONLINK, WEIGHT, RECURSIVE, IGP, TABLE, BLACKHOLE, UNREACHABLE, BFD, MPLS)
48

    
49

    
50
CF_GRAMMAR
51

    
52
CF_ADDTO(proto, static_proto '}')
53

    
54
static_proto_start: proto_start STATIC
55
{
56
  this_proto = proto_config_new(&proto_static, $1);
57
  init_list(&STATIC_CFG->routes);
58
};
59

    
60
static_proto:
61
   static_proto_start proto_name '{'
62
 | static_proto proto_item ';'
63
 | static_proto proto_channel ';' { this_proto->net_type = $2->net_type; }
64
 | static_proto CHECK LINK bool ';' { STATIC_CFG->check_link = $4; }
65
 | static_proto IGP TABLE rtable ';' {
66
    if ($4->addr_type == NET_IP4)
67
      STATIC_CFG->igp_table_ip4 = $4;
68
    else if ($4->addr_type == NET_IP6)
69
      STATIC_CFG->igp_table_ip6 = $4;
70
    else
71
      cf_error("Incompatible IGP table type");
72
   }
73
 | static_proto stat_route stat_route_opt_list ';' { static_route_finish(); }
74
 ;
75

    
76
stat_nexthop:
77
    VIA ipa ipa_scope {
78
      this_snh = static_nexthop_new();
79
      this_snh->via = $2;
80
      this_snh->iface = $3;
81
    }
82
  | VIA TEXT {
83
      this_snh = static_nexthop_new();
84
      this_snh->via = IPA_NONE;
85
      this_snh->iface = if_get_by_name($2);
86
    }
87
  | stat_nexthop MPLS label_stack {
88
    this_snh->mls = $3;
89
  }
90
  | stat_nexthop ONLINK bool {
91
    this_snh->onlink = $3;
92
  }
93
  | stat_nexthop WEIGHT expr {
94
    this_snh->weight = $3 - 1;
95
    if (($3<1) || ($3>256)) cf_error("Weight must be in range 1-256");
96
  }
97
  | stat_nexthop BFD bool {
98
    this_snh->use_bfd = $3; cf_check_bfd($3);
99
  }
100
;
101

    
102
stat_nexthops:
103
    stat_nexthop
104
  | stat_nexthops stat_nexthop
105
;
106

    
107
stat_route0: ROUTE net_any {
108
     this_srt = cfg_allocz(sizeof(struct static_route));
109
     add_tail(&STATIC_CFG->routes, &this_srt->n);
110
     this_srt->net = $2;
111
     this_srt_last_cmd = &(this_srt->cmds);
112
     this_srt->mp_next = NULL;
113
     this_snh = NULL;
114
  }
115
 ;
116

    
117
stat_route:
118
   stat_route0 stat_nexthops
119
 | stat_route0 RECURSIVE ipa {
120
      this_srt->dest = RTDX_RECURSIVE;
121
      this_srt->via = $3;
122
   }
123
 | stat_route0 RECURSIVE ipa MPLS label_stack {
124
      this_srt->dest = RTDX_RECURSIVE;
125
      this_srt->via = $3;
126
      this_srt->mls = $5;
127
   }
128
 | stat_route0			{ this_srt->dest = RTD_NONE; }
129
 | stat_route0 DROP		{ this_srt->dest = RTD_BLACKHOLE; }
130
 | stat_route0 REJECT		{ this_srt->dest = RTD_UNREACHABLE; }
131
 | stat_route0 BLACKHOLE	{ this_srt->dest = RTD_BLACKHOLE; }
132
 | stat_route0 UNREACHABLE	{ this_srt->dest = RTD_UNREACHABLE; }
133
 | stat_route0 PROHIBIT		{ this_srt->dest = RTD_PROHIBIT; }
134
 ;
135

    
136
stat_route_item:
137
   cmd { *this_srt_last_cmd = $1; this_srt_last_cmd = &($1->next); }
138
 ;
139

    
140
stat_route_opts:
141
   /* empty */
142
 | stat_route_opts stat_route_item
143
 ;
144

    
145
stat_route_opt_list:
146
   /* empty */
147
 | '{' stat_route_opts '}'
148
 ;
149

    
150

    
151
CF_CLI(SHOW STATIC, optsym, [<name>], [[Show details of static protocol]])
152
{ static_show(proto_get_named($3, &proto_static)); } ;
153

    
154
CF_CODE
155

    
156
CF_END