1/* $Id: client6_token.l,v 1.1.1.1 2006/12/04 00:45:22 Exp $ */ 2/* ported from KAME: cftoken.l,v 1.15 2002/09/24 14:20:49 itojun Exp */ 3 4/* 5 * Copyright (C) 2002 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33%option noyywrap 34 35%{ 36#include <sys/types.h> 37#include <sys/socket.h> 38 39#include <netinet/in.h> 40#include <arpa/inet.h> 41 42#include <errno.h> 43#include <syslog.h> 44#include <string.h> 45#ifdef HAVE_STDARG_H 46#include <stdarg.h> 47#else 48#include <varargs.h> 49#endif 50 51#include "queue.h" 52#include "dhcp6.h" 53#include "config.h" 54#include "common.h" 55#include "cp.tab.h" 56 57const char *configfilename; 58int lineno = 1; 59 60static int cpyy_first_time = 1; 61static int cpyyerrorcount = 0; 62 63 64#ifndef NOCONFIG_DEBUG 65#define YYDEBUG 1 66 67int cfdebug = 1; 68#else 69int cfdebug = 0; 70#endif 71 72static void cfdebug_print __P((char *, char *, int)); 73extern int cf_post_config __P((void)); 74 75extern int cpyyparse(void); 76extern int cf_post_config(void); 77 78#define DP(str) if (cfdebug) cfdebug_print(str, cpyytext, cpyyleng) 79#define DECHO if (cfdebug) cfdebug_print(NULL, cpyytext, cpyyleng); 80%} 81 82/* abbreviations */ 83nl \n 84ws [ \t]+ 85comma , 86comment \#.* 87semi \; 88string [a-zA-Z0-9:\._][a-zA-Z0-9:\._]* 89digit [0-9] 90number {digit}+ 91hexdigit [0-9A-Fa-f] 92hexpair {hexdigit}{hexdigit} 93hexstring 0[xX]{hexpair}+ 94duid {hexpair}(:{hexpair})* 95ipv4addr ({digit}{1,3}"."{digit}{1,3}"."{digit}{1,3}"."{digit}{1,3}) 96addr_head ("::"|{hexdigit}{1,4}(":"|"::")) 97addr_tail ({hexdigit}{1,4}|({hexdigit}{1,4}"::")|{ipv4addr}) 98addr_body ({hexdigit}{1,4}(":"|"::"))* 99ipv6addr {addr_head}{addr_body}{addr_tail} 100ifname [a-zA-Z]+[0-9]+ 101slash \/ 102bcl \{ 103ecl \} 104 105%s S_CNF 106%s S_IFACE 107%s S_ADDR 108%s S_RNT 109%s S_RBT 110 111%% 112%{ 113 if (cpyy_first_time) { 114 BEGIN S_CNF; 115 cpyy_first_time = 0; 116 } 117%} 118 /* interface configuration */ 119<S_CNF>interface { DECHO; BEGIN S_IFACE; return (INTERFACE); } 120<S_IFACE>{ifname} { 121 DECHO; 122 cpyylval.str = strdup(cpyytext); 123 BEGIN S_CNF; 124 return (IFNAME); 125} 126 127<S_CNF>address { DECHO; BEGIN S_ADDR; return (ADDRESS); } 128 129<S_CNF>prefix { DECHO; BEGIN S_ADDR; return (PREFIX); } 130<S_ADDR>{ipv6addr} { 131 struct in6_addr addr; 132 DECHO; 133 if (inet_pton(AF_INET6, cpyytext, &addr) < 1) { 134 dprintf(LOG_ERR, "invalid address in line %d", lineno); 135 return (-1); 136 } 137 cpyylval.addr = addr; 138 BEGIN S_CNF; 139 return (IPV6ADDR); 140} 141<S_CNF>iaid { DECHO; return (IAID); } 142<S_CNF>valid-life-time { DECHO; return (V_TIME); } 143<S_CNF>prefer-life-time { DECHO; return (P_TIME); } 144<S_CNF>renew-time { DECHO; return (RENEW_TIME); } 145<S_CNF>rebind-time { DECHO; return (REBIND_TIME); } 146<S_CNF>prefix-delegation-interface { DECHO; return (PREFIX_DELEGATION_INTERFACE); } 147 /* request */ 148<S_CNF>request { DECHO; return (REQUEST); } 149 150 /* send */ 151<S_CNF>send { DECHO; return (SEND); } 152 /* DHCP options */ 153<S_CNF>option { DECHO; return (OPTION); } 154 155<S_CNF>rapid-commit { DECHO; return (RAPID_COMMIT); } 156<S_CNF>prefix-delegation { DECHO; return (PREFIX_DELEGATION); } 157<S_CNF>domain-name-servers { DECHO; return (DNS_SERVERS); } 158<S_CNF>sip-servers { DECHO; return (SIP_SERVERS); } 159<S_CNF>ntp-servers { DECHO; return (NTP_SERVERS); } 160 /* generic options */ 161<S_CNF>information-only { DECHO; return (INFO_ONLY); } 162<S_CNF>temp-address { DECHO; return (TEMP_ADDR); } 163 /* duration */ 164<S_CNF>infinity { DECHO; return (INFINITY); } 165 166 /* Foxconn added start pling 08/26/2009 */ 167<S_CNF>solicit-only { DECHO; return (SOLICIT_ONLY); } 168 /* Foxconn added start pling 08/26/2009 */ 169 170 /* Foxconn added start pling 09/07/2010 */ 171<S_CNF>user-class { DECHO; return (USER_CLASS); } 172 /* Foxconn added end pling 09/07/2010 */ 173 174 /* Foxconn added start pling 09/21/2010 */ 175 /* For DHCPv6 readylogo test, to request IANA only or IAPD only */ 176<S_CNF>iana-only { DECHO; return (IANA_ONLY); } 177<S_CNF>iapd-only { DECHO; return (IAPD_ONLY); } 178<S_CNF>domain-list { DECHO; return (DOMAIN_LIST); } 179 /* Foxconn added end pling 09/21/2010 */ 180 181 /* Foxconn added start pling 10/07/2010 */ 182<S_CNF>xid-sol { DECHO; return (XID_SOL); } 183<S_CNF>xid-req { DECHO; return (XID_REQ); } 184<S_CNF>duid-time { DECHO; return (DUID_TIME); } 185 /* Foxconn added end pling 10/07/2010 */ 186 187 /* misc */ 188{ws} { ; } 189{nl} { lineno++; } 190{comment} { DP("comment"); } 191{number} { 192 DECHO; 193 cpyylval.num = strtoll(cpyytext, NULL, 10); 194 return (NUMBER); 195} 196{slash} { DECHO; return (SLASH); } 197{comma} { DECHO; return (COMMA); } 198{semi} { DP("end of sentence"); return (EOS); } 199{bcl} { DP("begin of closure"); return (BCL); } 200{ecl} { DP("end of closure"); return (ECL); } 201 202 /* generic string */ 203{string} { 204 DECHO; 205 cpyylval.str = strdup(cpyytext); 206 return (STRING); 207 } 208 209%% 210static void 211cfdebug_print(w, t, l) 212 char *w, *t; 213 int l; 214{ 215 if (w) 216 dprintf(LOG_DEBUG, "<%d>%s [%s] (%d)", yy_start, w, t, l); 217 else 218 dprintf(LOG_DEBUG, "<%d>[%s] (%d)", yy_start, t, l); 219} 220 221static void 222cpyyerror0(int level, char *s, va_list ap) 223{ 224 char ebuf[BUFSIZ], *bp, *ep; 225 226 bp = ebuf; 227 ep = ebuf + sizeof(ebuf); 228 bp += snprintf(bp, ep - bp, "%s %d: ", configfilename, lineno); 229 if (bp < ep) 230 bp += vsnprintf(bp, ep - bp, s, ap); 231 232 dprintf(level, ebuf); 233} 234 235void 236cpyyerror(char *s, ...) 237{ 238 va_list ap; 239#ifdef HAVE_STDARG_H 240 va_start(ap, s); 241#else 242 va_start(ap); 243#endif 244 cpyyerror0(LOG_ERR, s, ap); 245 va_end(ap); 246 cpyyerrorcount++; 247} 248 249void 250cpyywarn(char *s, ...) 251{ 252 va_list ap; 253#ifdef HAVE_STDARG_H 254 va_start(ap, s); 255#else 256 va_start(ap); 257#endif 258 cpyyerror0(LOG_WARNING, s, ap); 259 va_end(ap); 260} 261 262int 263cfparse(const char *conf) 264{ 265 configfilename = conf; 266 if ((cpyyin = fopen(configfilename, "r")) == NULL) { 267 if (errno == ENOENT) 268 return (0); 269 dprintf(LOG_ERR, "cfparse: fopen(%s): %s", 270 configfilename, strerror(errno)); 271 return (-1); 272 } 273 274 if (cpyyparse() || cpyyerrorcount) { 275 if (cpyyerrorcount) { 276 cpyyerror("fatal parse failure: exiting (%d errors)", 277 cpyyerrorcount); 278 } else 279 cpyyerror("fatal parse failure: exiting"); 280 return (-1); 281 } 282 283 return (cf_post_config()); 284} 285