1/* $Id: server6_token.l,v 1.1.1.1 2006/12/04 00:45:34 Exp $ */ 2 3/* 4 * Copyright (C) International Business Machines Corp., 2003 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 18 * 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 29 * SUCH DAMAGE. 30 */ 31 32/* Author: Shirley Ma, xma@us.ibm.com */ 33 34%option noyywrap 35 36%{ 37#include <stdio.h> 38#include <string.h> 39#include <syslog.h> 40#include <errno.h> 41#include <sys/types.h> 42#include <sys/socket.h> 43#include <arpa/inet.h> 44#include <net/if.h> 45 46#include "queue.h" 47#include "dhcp6.h" 48#include "config.h" 49#include "common.h" 50#include <server6_conf.h> 51#include "sf.tab.h" 52 53int num_lines = 1; 54int sfyyerrorcount = 0; 55int sfparse(char *filename); 56extern void sfyyerror(char *msg); 57extern struct rootgroup *globalgroup; 58 59extern int sfyyparse(void); 60 61%} 62 63whitespace ([ \t])+ 64digit [0-9] 65number ({digit})+ 66snum -?({digit})+ 67decimal ({number}"."{number}) 68hexdigit ([a-f]|[A-F]|[0-9]) 69hexpair {hexdigit}{hexdigit} 70duid_id {hexpair}(":"{hexpair})* 71ipv4addr ({digit}{1,3}"."{digit}{1,3}"."{digit}{1,3}"."{digit}{1,3}) 72addr_head ("::"|{hexdigit}{1,4}(":"|"::")) 73addr_tail ({hexdigit}{1,4}|({hexdigit}{1,4}"::")|{ipv4addr})? 74addr_body ({hexdigit}{1,4}(":"|"::"))* 75ipv6addr {addr_head}{addr_body}{addr_tail} 76string [a-zA-Z0-9:\._-][a-zA-Z0-9:\._-]* 77ifname [a-zA-Z]+[0-9]+ 78 79%s S_IFACE 80%s S_DUID 81%s S_OPTION 82 83%% 84 85group { return GROUP; } 86 87interface { BEGIN S_IFACE; return INTERFACE; } 88<S_IFACE>{ifname} { BEGIN INITIAL; sfyylval.str = strdup(sfyytext); return IFNAME;} 89 90link { return LINK; } 91relay { return RELAY; } 92host { return HOST; } 93 94pool { return POOL; } 95range { return RANGE; } 96 97iaid { return IAID; } 98iaidinfo { return IAIDINFO; } 99 100duid { BEGIN S_DUID; return DUID; } 101<S_DUID>{duid_id} { BEGIN INITIAL; sfyylval.str = strdup(sfyytext); return DUID_ID; } 102 103prefix { return PREFIX; } 104address { return ADDRESS;} 105 106allow { BEGIN S_OPTION; return ALLOW; } 107send { BEGIN S_OPTION; return SEND; } 108option { BEGIN S_OPTION; return OPTION; } 109 110<S_OPTION>unicast { BEGIN INITIAL; return UNICAST; } 111<S_OPTION>rapid-commit { BEGIN INITIAL; return RAPIDCOMMIT; } 112<S_OPTION>temp-address { BEGIN INITIAL; return TEMPIPV6ADDR; } 113<S_OPTION>information-only { BEGIN INITIAL; return INFO_ONLY; } 114<S_OPTION>dns_servers { BEGIN INITIAL; return DNS_SERVERS;} 115<S_OPTION>sip_servers { BEGIN INITIAL; return SIP_SERVERS;} 116<S_OPTION>ntp_servers { BEGIN INITIAL; return NTP_SERVERS;} 117 118renew-time { return RENEWTIME; } 119rebind-time { return REBINDTIME; } 120valid-life-time { return VALIDLIFETIME; } 121prefer-life-time { return PREFERLIFETIME; } 122server-preference { return PREFERENCE; } 123 124to { return TO; } 125infinity { return INFINITY; } 126 127#.*$ {/* ignore comments */} 128\n {num_lines++;} 129{whitespace} {} 130{ipv6addr} { 131 struct in6_addr addr; 132 int i; 133 134 i = inet_pton(AF_INET6, sfyytext, &addr); 135 if (i < 1) { 136 dprintf(LOG_ERR, "invalid address in line %d", num_lines); 137 return BAD_TOKEN; 138 } 139 140 sfyylval.addr = addr; 141 return IPV6ADDR; 142 } 143 144{number} { sfyylval.num = strtoll(sfyytext, NULL, 10); return NUMBER; } 145{snum} { sfyylval.snum = strtoll(sfyytext, NULL, 10); return SIGNEDNUMBER; } 146{decimal} { sfyylval.dec = atof(sfyytext); return DECIMAL; } 147{string} { 148 static char name[MAXDNAME]; 149 strncpy(name, sfyytext, MAXDNAME-1); 150 name[MAXDNAME-1] = '\0'; 151 sfyylval.str = name; 152 return STRING; 153 } 154"{"|"}"|";"|"/" { return *sfyytext; } 155. { return BAD_TOKEN; } 156 157%% 158 159int 160sfparse(conf) 161 char *conf; 162{ 163 if ((sfyyin = fopen(conf, "r")) == NULL) { 164 if (errno == ENOENT) 165 return(0); 166 dprintf(LOG_ERR, "sfparse: fopen(%s): %s", 167 conf, strerror(errno)); 168 printf("open error\n"); 169 return(-1); 170 } 171 172 if (sfyyparse() || sfyyerrorcount) { 173 sfyyerror("fatal parse failure: exiting"); 174 return(-1); 175 } 176 post_config(globalgroup); 177 178 return (0); 179} 180