1 /* $KAME: parser.y,v 1.8 2000/11/08 03:03:34 jinmei Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/usr.sbin/rrenumd/parser.y,v 1.1.2.2 2001/07/03 11:02:10 ume Exp $
32 * $DragonFly: src/usr.sbin/rrenumd/parser.y,v 1.4 2004/02/10 02:59:43 rob Exp $
36 #include <sys/param.h>
37 #include <sys/ioctl.h>
38 #include <sys/socket.h>
40 #include <sys/queue.h>
43 #if defined(__DragonFly__)
44 #include <net/if_var.h>
45 #endif /* __DragonFly__ */
47 #include <netinet/in.h>
48 #include <netinet/in_var.h>
49 #include <netinet/icmp6.h>
57 struct config_is_set
{
61 struct dst_list
*dl_head
;
62 struct payload_list
*pl_head
, ple_cur
;
64 char errbuf
[LINE_MAX
];
67 extern
void yyerror(const char *s
);
68 extern
int yylex(void);
69 static struct payload_list
* pllist_lookup
(int seqnum
);
70 static void pllist_enqueue
(struct payload_list
*pl_entry
);
72 #define MAX_RETRYNUM 10 /* upper limit of retry in this rrenumd program */
73 #define MAX_SEQNUM 256 /* upper limit of seqnum in this rrenumd program */
85 struct in6_addr addr6
;
91 struct payload_list
*pl
;
95 %token
<num
> ADD CHANGE SETGLOBAL
96 %token DEBUG_CMD DEST_CMD RETRY_CMD SEQNUM_CMD
97 %token MATCH_PREFIX_CMD MAXLEN_CMD MINLEN_CMD
98 %token USE_PREFIX_CMD KEEPLEN_CMD
99 %token VLTIME_CMD PLTIME_CMD
100 %token RAF_ONLINK_CMD RAF_AUTO_CMD RAF_DECRVALID_CMD RAF_DECRPREFD_CMD
101 %token
<num
> DAYS HOURS MINUTES SECONDS INFINITY
103 %token BCL ECL EOS ERROR
104 %token
<cs
> NAME HOSTNAME QSTRING DECSTRING
105 %token
<addr4
> IPV4ADDR
106 %token
<addr6
> IPV6ADDR
107 %token
<num
> PREFIXLEN
109 %type
<num
> retrynum seqnum rrenum_cmd
110 %type
<num
> prefixlen maxlen minlen keeplen vltime pltime
111 %type
<num
> lifetime days hours minutes seconds
112 %type
<num
> decstring
113 %type
<num
> raf_onlink raf_auto raf_decrvalid raf_decrprefd flag
114 %type
<dl
> dest_addrs dest_addr sin sin6
115 %type
<pl
> rrenum_statement
117 %type
<prefix
> prefixval
127 | statements statement
132 | destination_statement
133 | rrenum_statement_without_seqnum
134 | rrenum_statement_with_seqnum
151 destination_statement:
152 DEST_CMD dest_addrs retrynum EOS
161 | dest_addrs dest_addr
179 struct sockaddr_in6
*sin6
;
181 sin6
= (struct sockaddr_in6
*)$1->dl_dst
;
182 sin6
->sin6_scope_id
= if_nametoindex
($2.cp
);
188 struct sockaddr_storage
*ss
;
189 struct addrinfo hints
, *res
;
192 memset
(&hints
, 0, sizeof
(hints
));
193 hints.ai_flags
= AI_CANONNAME
;
194 hints.ai_family
= AF_UNSPEC
;
195 hints.ai_socktype
= SOCK_RAW
;
196 hints.ai_protocol
= 0;
197 error = getaddrinfo
($1.cp
, 0, &hints
, &res
);
199 snprintf
(errbuf
, sizeof
(errbuf
),
200 "name resolution failed for %s:%s",
201 $1.cp
, gai_strerror
(error));
204 ss
= (struct sockaddr_storage
*)malloc
(sizeof
(*ss
));
205 memset
(ss
, 0, sizeof
(*ss
));
206 memcpy
(ss
, res
->ai_addr
, res
->ai_addr
->sa_len
);
209 $$
= (struct dst_list
*)
210 malloc
(sizeof
(struct dst_list
));
211 memset
($$
, 0, sizeof
(struct dst_list
));
212 $$
->dl_dst
= (struct sockaddr
*)ss
;
219 struct sockaddr_in
*sin
;
221 sin
= (struct sockaddr_in
*)malloc
(sizeof
(*sin
));
222 memset
(sin
, 0, sizeof
(*sin
));
223 sin
->sin_len
= sizeof
(*sin
);
224 sin
->sin_family
= AF_INET
;
227 $$
= (struct dst_list
*)
228 malloc
(sizeof
(struct dst_list
));
229 memset
($$
, 0, sizeof
(struct dst_list
));
230 $$
->dl_dst
= (struct sockaddr
*)sin
;
237 struct sockaddr_in6
*sin6
;
239 sin6
= (struct sockaddr_in6
*)malloc
(sizeof
(*sin6
));
240 memset
(sin6
, 0, sizeof
(*sin6
));
241 sin6
->sin6_len
= sizeof
(*sin6
);
242 sin6
->sin6_family
= AF_INET6
;
243 sin6
->sin6_addr
= $1;
245 $$
= (struct dst_list
*)
246 malloc
(sizeof
(struct dst_list
));
247 memset
($$
, 0, sizeof
(struct dst_list
));
248 $$
->dl_dst
= (struct sockaddr
*)sin6
;
254 $$.cp
= strdup
($1.cp
);
259 $1.cp
[$1.len
- 1] = 0;
260 $$.cp
= strdup
(&$1.cp
[1]);
270 | RETRY_CMD decstring
272 if
($2 > MAX_RETRYNUM
)
278 rrenum_statement_with_seqnum:
281 if
(pllist_lookup
($2)) {
282 snprintf
(errbuf
, sizeof
(errbuf
),
283 "duplicate seqnum %ld specified at %d",
288 BCL rrenum_statement EOS ECL EOS
290 $5->pl_irr.rr_seqnum
= $2;
302 if
($1 > MAX_SEQNUM
) {
303 snprintf
(errbuf
, sizeof
(errbuf
),
304 "seqnum %ld is illegal for this program. "
305 "should be between 0 and %d",
313 rrenum_statement_without_seqnum:
316 if
(pllist_lookup
(0)) {
317 snprintf
(errbuf
, sizeof
(errbuf
),
318 "duplicate seqnum %d specified at %d",
322 $1->pl_irr.rr_seqnum
= 0;
328 match_prefix_definition use_prefix_definition
330 $$
= (struct payload_list
*)
331 malloc
(sizeof
(struct payload_list
));
332 memcpy
($$
, &ple_cur
, sizeof
(ple_cur
));
336 match_prefix_definition:
337 rrenum_cmd MATCH_PREFIX_CMD prefixval maxlen minlen
339 struct icmp6_router_renum
*irr
;
340 struct rr_pco_match
*rpm
;
342 irr
= (struct icmp6_router_renum
*)&ple_cur.pl_irr
;
343 rpm
= (struct rr_pco_match
*)(irr
+ 1);
344 memset
(rpm
, 0, sizeof
(*rpm
));
347 rpm
->rpm_prefix
= $3.addr
;
348 rpm
->rpm_matchlen
= $3.plen
;
349 rpm
->rpm_maxlen
= $4;
350 rpm
->rpm_minlen
= $5;
385 | MAXLEN_CMD decstring
398 | MINLEN_CMD decstring
406 use_prefix_definition:
409 struct icmp6_router_renum
*irr
;
410 struct rr_pco_match
*rpm
;
411 struct rr_pco_use
*rpu
;
413 irr
= (struct icmp6_router_renum
*)&ple_cur.pl_irr
;
414 rpm
= (struct rr_pco_match
*)(irr
+ 1);
415 rpu
= (struct rr_pco_use
*)(rpm
+ 1);
416 memset
(rpu
, 0, sizeof
(*rpu
));
418 | USE_PREFIX_CMD prefixval keeplen use_prefix_values
420 struct icmp6_router_renum
*irr
;
421 struct rr_pco_match
*rpm
;
422 struct rr_pco_use
*rpu
;
424 irr
= (struct icmp6_router_renum
*)&ple_cur.pl_irr
;
425 rpm
= (struct rr_pco_match
*)(irr
+ 1);
426 rpu
= (struct rr_pco_use
*)(rpm
+ 1);
428 rpu
->rpu_prefix
= $2.addr
;
429 rpu
->rpu_uselen
= $2.plen
;
430 rpu
->rpu_keeplen
= $3;
437 struct icmp6_router_renum
*irr
;
438 struct rr_pco_match
*rpm
;
439 struct rr_pco_use
*rpu
;
441 irr
= (struct icmp6_router_renum
*)&ple_cur.pl_irr
;
442 rpm
= (struct rr_pco_match
*)(irr
+ 1);
443 rpu
= (struct rr_pco_use
*)(rpm
+ 1);
444 memset
(rpu
, 0, sizeof
(*rpu
));
446 rpu
->rpu_vltime
= htonl
(DEF_VLTIME
);
447 rpu
->rpu_pltime
= htonl
(DEF_PLTIME
);
451 | BCL vltime pltime raf_onlink raf_auto raf_decrvalid raf_decrprefd ECL
453 struct icmp6_router_renum
*irr
;
454 struct rr_pco_match
*rpm
;
455 struct rr_pco_use
*rpu
;
457 irr
= (struct icmp6_router_renum
*)&ple_cur.pl_irr
;
458 rpm
= (struct rr_pco_match
*)(irr
+ 1);
459 rpu
= (struct rr_pco_use
*)(rpm
+ 1);
460 memset
(rpu
, 0, sizeof
(*rpu
));
462 rpu
->rpu_vltime
= $2;
463 rpu
->rpu_pltime
= $3;
466 ~ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
;
469 ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
;
472 ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
;
475 ~ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
;
480 ICMP6_RR_PCOUSE_RAFLAGS_AUTO
;
483 ICMP6_RR_PCOUSE_RAFLAGS_AUTO
;
486 ICMP6_RR_PCOUSE_RAFLAGS_AUTO
;
489 ~ICMP6_RR_PCOUSE_RAFLAGS_AUTO
;
495 ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
;
499 ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
;
509 | KEEPLEN_CMD decstring
521 $$
= htonl
(DEF_VLTIME
);
523 | VLTIME_CMD lifetime
532 $$
= htonl
(DEF_PLTIME
);
534 | PLTIME_CMD lifetime
544 | RAF_ONLINK_CMD flag
566 | RAF_DECRVALID_CMD flag
577 | RAF_DECRPREFD_CMD flag
594 | days hours minutes seconds
598 d
= $1 * 24 * 60 * 60;
650 static struct payload_list
*
651 pllist_lookup
(int seqnum
)
653 struct payload_list
*pl
;
654 for
(pl
= pl_head
; pl
&& pl
->pl_irr.rr_seqnum
!= seqnum
;
661 pllist_enqueue
(struct payload_list
*pl_entry
)
663 struct payload_list
*pl
, *pl_last
;
667 pl
&& pl
->pl_irr.rr_seqnum
< pl_entry
->pl_irr.rr_seqnum
;
668 pl_last
= pl
, pl
= pl
->pl_next
)
671 pl_last
->pl_next
= pl_entry
;