1 /* $NetBSD: cfparse.y,v 1.18.4.3 2007/08/01 11:52:19 vanhu Exp $ */
3 /* Id: cfparse.y,v 1.66 2006/08/22 18:17:17 manubsd Exp */
7 * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 and 2003 WIDE Project.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the project nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #ifdef HAVE_NETINET6_IPSEC
44 # include <netinet6/ipsec.h>
46 # include <netinet/ipsec.h>
50 #include <arpa/inet.h>
71 #include "cfparse_proto.h"
72 #include "cftoken_proto.h"
73 #include "algorithm.h"
74 #include "localconf.h"
79 #include "remoteconf.h"
80 #include "grabmyaddr.h"
81 #include "isakmp_var.h"
84 #include "nattraversal.h"
85 #include "isakmp_frag.h"
88 #include "isakmp_unity.h"
89 #include "isakmp_xauth.h"
90 #include "isakmp_cfg.h"
92 #include "ipsec_doi.h"
97 static int num2dhgroup[] = {
99 OAKLEY_ATTR_GRP_DESC_MODP768,
100 OAKLEY_ATTR_GRP_DESC_MODP1024,
101 OAKLEY_ATTR_GRP_DESC_EC2N155,
102 OAKLEY_ATTR_GRP_DESC_EC2N185,
103 OAKLEY_ATTR_GRP_DESC_MODP1536,
112 OAKLEY_ATTR_GRP_DESC_MODP2048,
113 OAKLEY_ATTR_GRP_DESC_MODP3072,
114 OAKLEY_ATTR_GRP_DESC_MODP4096,
115 OAKLEY_ATTR_GRP_DESC_MODP6144,
116 OAKLEY_ATTR_GRP_DESC_MODP8192
119 struct remote_index_val {
121 struct sockaddr_storage *addr;
124 static struct remoteconf *cur_rmconf;
125 static int tmpalgtype[MAXALGCLASS];
126 static struct sainfo *cur_sainfo;
127 static int cur_algclass;
129 static struct proposalspec *newprspec (void);
130 static void insprspec (struct proposalspec *, struct proposalspec **);
131 static struct secprotospec *newspspec (void);
132 static void insspspec (struct secprotospec *, struct proposalspec **);
134 static int set_isakmp_proposal (struct remoteconf *, struct proposalspec *);
135 static void clean_tmpalgtype (void);
136 static int expand_isakmpspec (int, int, int *,
137 int, int, time_t, int, int, int, char *, struct remoteconf *);
138 static int listen_addr (struct sockaddr_storage *addr, int udp_encap);
140 void freeetypes (struct etypes **etypes);
143 static int fix_lifebyte (u_long);
150 struct remoteconf *rmconf;
151 struct sockaddr_storage *saddr;
152 struct sainfoalg *alg;
153 struct remote_index_val *rmidx;
160 /* self information */
161 %token IDENTIFIER VENDORID
163 %token LOGGING LOGLEV
165 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
167 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
169 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
170 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
171 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
172 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
173 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
175 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
176 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY
178 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
180 %token SAINFO FROM GROUP
182 %token REMOTE ANONYMOUS INHERIT
183 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
184 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
185 %token VERIFY_CERT SEND_CERT SEND_CR
186 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
187 %token PEERS_IDENTIFIER VERIFY_IDENTIFIER
189 %token SHARED_SECRET SECRETTYPE
190 %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
191 %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
192 %token DNSSEC CERT_X509 CERT_PLAINRSA
193 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
194 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE
195 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
196 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
198 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
199 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
200 %token COMPLEX_BUNDLE
201 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM
202 %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION
203 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
205 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
206 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
208 %token NUMBER SWITCH BOOLEAN
209 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
210 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
211 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
212 %token EOS BOC EOC COMMA
213 %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE
214 %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY IKE_VERSION
216 %type <num> NUMBER BOOLEAN SWITCH keylength
217 %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
218 %type <num> SECRETTYPE
219 %type <num> ALGORITHM_CLASS dh_group_num
220 %type <num> ALGORITHMTYPE STRENGTHTYPE
221 %type <num> PREFIX prefix PORT port ike_port
222 %type <num> ul_proto UL_PROTO
223 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
224 %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL
225 %type <num> VERIFICATION_MODULE VERIFICATION_OPTION
226 %type <num> unittype_time unittype_byte
227 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
228 %type <val> identifierstring
229 %type <saddr> ike_addrinfo_port
230 %type <alg> algorithm
231 %type <num> dpd_algo_type
232 %type <num> idle_dir_type
233 %type <rmidx> remote_index ike_addrinfo_prefix_port
239 | statements statement
244 | identifier_statement
257 : PATH PATHTYPE QUOTEDSTRING
259 if ($2 >= LC_PATHTYPE_MAX) {
260 racoon_yyerror("invalid path type %d", $2);
264 /* free old pathinfo */
265 if (lcconf->pathinfo[$2])
266 racoon_free(lcconf->pathinfo[$2]);
268 /* set new pathinfo */
269 lcconf->pathinfo[$2] = racoon_strdup($3->v);
270 STRDUP_FATAL(lcconf->pathinfo[$2]);
278 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
283 : INCLUDE QUOTEDSTRING EOS
285 char path[MAXPATHLEN];
287 getpathname(path, sizeof(path),
288 LC_PATHTYPE_INCLUDE, $2->v);
290 if (yycf_switch_buffer(path) != 0)
295 /* self information */
297 : IDENTIFIER identifier_stmt
302 /*XXX to be deleted */
305 | IDENTIFIERTYPE QUOTEDSTRING
307 /*XXX to be deleted */
308 $2->l--; /* nuke '\0' */
309 lcconf->ident[$1] = $2;
310 if (lcconf->ident[$1] == NULL) {
311 racoon_yyerror("failed to set my ident: %s",
321 : LOGGING log_level EOS
327 * XXX ignore it because this specification
330 plogsetlevelquotedstr($1->v);
341 : PADDING BOC padding_stmts EOC
345 | padding_stmts padding_stmt
348 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
349 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
350 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
351 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
352 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
357 : LISTEN BOC listen_stmts EOC
361 | listen_stmts listen_stmt
364 : X_ISAKMP ike_addrinfo_port
369 | X_ISAKMP_NATT ike_addrinfo_port
374 racoon_yyerror("NAT-T support not compiled in.");
380 racoon_yyerror("admin directive is obsoleted.");
383 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
385 racoon_yywarn("admin port support not compiled in");
388 | ADMINSOCK QUOTEDSTRING
390 racoon_yywarn("admin port support not compiled in");
395 racoon_yywarn("admin port support not compiled in");
398 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
401 : ADDRSTRING ike_port
405 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
406 $$ = str2saddr($1->v, portbuf);
412 ike_addrinfo_prefix_port
413 : ADDRSTRING prefix ike_port
416 struct remote_index_val *new;
418 new = racoon_calloc(1, sizeof(*new));
420 racoon_yyerror("failed to allocate remote index struct");
424 snprintf(portbuf, sizeof(portbuf), "%ld", $3);
425 new->addr = str2saddr($1->v, portbuf);
428 racoon_yyerror("failed to allocate sockaddr storage");
436 : /* nothing */ { $$ = PORT_ISAKMP; }
441 : MODECFG BOC modecfg_stmts EOC
445 | modecfg_stmts modecfg_stmt
448 : CFG_NET4 ADDRSTRING
451 if (inet_pton(AF_INET, $2->v,
452 &isakmp_cfg_config.network4) != 1)
453 racoon_yyerror("bad IPv4 network address.");
456 racoon_yyerror("racoon not configured with --enable-hybrid");
460 | CFG_MASK4 ADDRSTRING
463 if (inet_pton(AF_INET, $2->v,
464 &isakmp_cfg_config.netmask4) != 1)
465 racoon_yyerror("bad IPv4 netmask address.");
468 racoon_yyerror("racoon not configured with --enable-hybrid");
472 | CFG_DNS4 addrdnslist
474 | CFG_NBNS4 addrwinslist
476 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
479 isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN;
481 racoon_yyerror("racoon not configured with --enable-hybrid");
485 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
488 isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE;
490 racoon_yyerror("racoon not configured with --enable-hybrid");
494 | CFG_SPLIT_DNS splitdnslist
496 #ifndef ENABLE_HYBRID
497 racoon_yyerror("racoon not configured with --enable-hybrid");
501 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
504 strlcpy(&isakmp_cfg_config.default_domain[0],
505 $2->v, sizeof(isakmp_cfg_config.default_domain));
508 racoon_yyerror("racoon not configured with --enable-hybrid");
512 | CFG_AUTH_SOURCE CFG_SYSTEM
515 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM;
517 racoon_yyerror("racoon not configured with --enable-hybrid");
521 | CFG_AUTH_SOURCE CFG_RADIUS
524 racoon_yyerror("racoon not configured with --with-libradius");
525 #else /* ENABLE_HYBRID */
526 racoon_yyerror("racoon not configured with --enable-hybrid");
527 #endif /* ENABLE_HYBRID */
530 | CFG_AUTH_SOURCE CFG_PAM
533 racoon_yyerror("racoon not configured with --with-libpam");
534 #else /* ENABLE_HYBRID */
535 racoon_yyerror("racoon not configured with --enable-hybrid");
536 #endif /* ENABLE_HYBRID */
539 | CFG_AUTH_SOURCE CFG_LDAP
542 racoon_yyerror("racoon not configured with --with-libldap");
543 #else /* ENABLE_HYBRID */
544 racoon_yyerror("racoon not configured with --enable-hybrid");
545 #endif /* ENABLE_HYBRID */
548 | CFG_AUTH_GROUPS authgrouplist
550 #ifndef ENABLE_HYBRID
551 racoon_yyerror("racoon not configured with --enable-hybrid");
555 | CFG_GROUP_SOURCE CFG_SYSTEM
558 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM;
560 racoon_yyerror("racoon not configured with --enable-hybrid");
564 | CFG_GROUP_SOURCE CFG_LDAP
567 racoon_yyerror("racoon not configured with --with-libldap");
568 #else /* ENABLE_HYBRID */
569 racoon_yyerror("racoon not configured with --enable-hybrid");
570 #endif /* ENABLE_HYBRID */
573 | CFG_ACCOUNTING CFG_NONE
576 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE;
578 racoon_yyerror("racoon not configured with --enable-hybrid");
582 | CFG_ACCOUNTING CFG_SYSTEM
585 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM;
587 racoon_yyerror("racoon not configured with --enable-hybrid");
591 | CFG_ACCOUNTING CFG_RADIUS
594 racoon_yyerror("racoon not configured with --with-libradius");
595 #else /* ENABLE_HYBRID */
596 racoon_yyerror("racoon not configured with --enable-hybrid");
597 #endif /* ENABLE_HYBRID */
600 | CFG_ACCOUNTING CFG_PAM
603 racoon_yyerror("racoon not configured with --with-libpam");
604 #else /* ENABLE_HYBRID */
605 racoon_yyerror("racoon not configured with --enable-hybrid");
606 #endif /* ENABLE_HYBRID */
609 | CFG_POOL_SIZE NUMBER
612 if (isakmp_cfg_resize_pool($2) != 0)
613 racoon_yyerror("cannot allocate memory for pool");
614 #else /* ENABLE_HYBRID */
615 racoon_yyerror("racoon not configured with --enable-hybrid");
616 #endif /* ENABLE_HYBRID */
619 | CFG_PFS_GROUP NUMBER
622 isakmp_cfg_config.pfs_group = $2;
623 switch (isakmp_cfg_config.pfs_group)
625 case OAKLEY_ATTR_GRP_DESC_MODP768:
626 case OAKLEY_ATTR_GRP_DESC_MODP1024:
627 case OAKLEY_ATTR_GRP_DESC_MODP1536:
628 case OAKLEY_ATTR_GRP_DESC_MODP2048:
629 case OAKLEY_ATTR_GRP_DESC_MODP3072:
630 case OAKLEY_ATTR_GRP_DESC_MODP4096:
631 case OAKLEY_ATTR_GRP_DESC_MODP6144:
632 case OAKLEY_ATTR_GRP_DESC_MODP8192:
635 racoon_yyerror("Invalid PFS group specified");
639 #else /* ENABLE_HYBRID */
640 racoon_yyerror("racoon not configured with --enable-hybrid");
641 #endif /* ENABLE_HYBRID */
644 | CFG_SAVE_PASSWD SWITCH
647 isakmp_cfg_config.save_passwd = $2;
648 #else /* ENABLE_HYBRID */
649 racoon_yyerror("racoon not configured with --enable-hybrid");
650 #endif /* ENABLE_HYBRID */
653 | CFG_AUTH_THROTTLE NUMBER
656 isakmp_cfg_config.auth_throttle = $2;
657 #else /* ENABLE_HYBRID */
658 racoon_yyerror("racoon not configured with --enable-hybrid");
659 #endif /* ENABLE_HYBRID */
662 | CFG_CONF_SOURCE CFG_LOCAL
665 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL;
666 #else /* ENABLE_HYBRID */
667 racoon_yyerror("racoon not configured with --enable-hybrid");
668 #endif /* ENABLE_HYBRID */
671 | CFG_CONF_SOURCE CFG_RADIUS
674 racoon_yyerror("racoon not configured with --with-libradius");
675 #else /* ENABLE_HYBRID */
676 racoon_yyerror("racoon not configured with --enable-hybrid");
677 #endif /* ENABLE_HYBRID */
680 | CFG_CONF_SOURCE CFG_LDAP
683 racoon_yyerror("racoon not configured with --with-libldap");
684 #else /* ENABLE_HYBRID */
685 racoon_yyerror("racoon not configured with --enable-hybrid");
686 #endif /* ENABLE_HYBRID */
689 | CFG_MOTD QUOTEDSTRING
692 strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd));
695 racoon_yyerror("racoon not configured with --enable-hybrid");
703 | addrdns COMMA addrdnslist
709 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
711 if (icc->dns4_index >= MAXNS) {
712 racoon_yyerror("No more than %d DNS", MAXNS);
715 if (inet_pton(AF_INET, $1->v,
716 &icc->dns4[icc->dns4_index++]) != 1)
717 racoon_yyerror("bad IPv4 DNS address.");
721 racoon_yyerror("racoon not configured with --enable-hybrid");
728 | addrwins COMMA addrwinslist
734 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
736 if (icc->nbns4_index >= MAXWINS) {
737 racoon_yyerror("No more than %d WINS", MAXWINS);
740 if (inet_pton(AF_INET, $1->v,
741 &icc->nbns4[icc->nbns4_index++]) != 1)
742 racoon_yyerror("bad IPv4 WINS address.");
746 racoon_yyerror("racoon not configured with --enable-hybrid");
753 | splitnetlist COMMA splitnet
759 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
760 struct unity_network network;
762 if (inet_pton(AF_INET, $1->v, &network.addr4) != 1)
763 racoon_yyerror("bad IPv4 SPLIT address.");
765 /* Turn $2 (the prefix) into a subnet mask */
766 network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0;
768 /* add the network to our list */
769 if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count))
770 racoon_yyerror("Unable to allocate split network");
774 racoon_yyerror("racoon not configured with --enable-hybrid");
781 | authgroup COMMA authgrouplist
787 char * groupname = NULL;
788 char ** grouplist = NULL;
789 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
791 grouplist = racoon_realloc(icc->grouplist,
792 sizeof(char**)*(icc->groupcount+1));
793 if (grouplist == NULL)
794 racoon_yyerror("unable to allocate auth group list");
796 groupname = racoon_malloc($1->l+1);
797 if (groupname == NULL)
798 racoon_yyerror("unable to allocate auth group name");
800 memcpy(groupname,$1->v,$1->l);
802 grouplist[icc->groupcount]=groupname;
803 icc->grouplist = grouplist;
808 racoon_yyerror("racoon not configured with --enable-hybrid");
815 | splitdns COMMA splitdnslist
821 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
823 if (!icc->splitdns_len)
825 icc->splitdns_list = racoon_malloc($1->l);
826 if(icc->splitdns_list == NULL)
827 racoon_yyerror("error allocating splitdns list buffer");
828 memcpy(icc->splitdns_list,$1->v,$1->l);
829 icc->splitdns_len = $1->l;
833 int len = icc->splitdns_len + $1->l + 1;
834 icc->splitdns_list = racoon_realloc(icc->splitdns_list,len);
835 if(icc->splitdns_list == NULL)
836 racoon_yyerror("error allocating splitdns list buffer");
837 icc->splitdns_list[icc->splitdns_len] = ',';
838 memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l);
839 icc->splitdns_len = len;
843 racoon_yyerror("racoon not configured with --enable-hybrid");
851 : RETRY BOC timer_stmts EOC
855 | timer_stmts timer_stmt
858 : RETRY_COUNTER NUMBER
860 lcconf->retry_counter = $2;
863 | RETRY_INTERVAL NUMBER unittype_time
865 lcconf->retry_interval = $2 * $3;
868 | RETRY_PERSEND NUMBER
870 lcconf->count_persend = $2;
873 | RETRY_PHASE1 NUMBER unittype_time
875 lcconf->retry_checkph1 = $2 * $3;
878 | RETRY_PHASE2 NUMBER unittype_time
880 lcconf->wait_ph2complete = $2 * $3;
883 | AUTO_EXIT_DELAY NUMBER unittype_time
885 lcconf->auto_exit_delay = $2 * $3;
886 lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET;
890 | NATT_KA NUMBER unittype_time
893 lcconf->natt_ka_interval = $2 * $3;
895 racoon_yyerror("NAT-T support not compiled in.");
905 cur_sainfo = create_sainfo();
906 if (cur_sainfo == NULL) {
907 racoon_yyerror("failed to allocate sainfo");
911 sainfo_name sainfo_param BOC sainfo_specs
913 struct sainfo *check;
916 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
917 racoon_yyerror("no encryption algorithm at %s",
918 sainfo2str(cur_sainfo));
921 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
922 racoon_yyerror("no authentication algorithm at %s",
923 sainfo2str(cur_sainfo));
926 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
927 racoon_yyerror("no compression algorithm at %s",
928 sainfo2str(cur_sainfo));
932 /* duplicate check */
933 check = getsainfo(cur_sainfo->idsrc,
935 cur_sainfo->id_i, 0);
936 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
937 racoon_yyerror("duplicated sainfo: %s",
938 sainfo2str(cur_sainfo));
941 inssainfo(cur_sainfo);
948 cur_sainfo->idsrc = NULL;
949 cur_sainfo->iddst = NULL;
951 | ANONYMOUS sainfo_id
953 cur_sainfo->idsrc = NULL;
954 cur_sainfo->iddst = $2;
956 | sainfo_id ANONYMOUS
958 cur_sainfo->idsrc = $1;
959 cur_sainfo->iddst = NULL;
961 | sainfo_id sainfo_id
963 cur_sainfo->idsrc = $1;
964 cur_sainfo->iddst = $2;
968 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
971 struct sockaddr_storage *saddr;
973 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
974 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
975 racoon_yyerror("port number must be \"any\".");
979 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
980 saddr = str2saddr($2->v, portbuf);
985 switch (saddr->ss_family) {
987 if ($5 == IPPROTO_ICMPV6) {
988 racoon_yyerror("upper layer protocol mismatched.\n");
992 $$ = ipsecdoi_sockaddr2id(saddr,
993 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
998 if ($5 == IPPROTO_ICMP) {
999 racoon_yyerror("upper layer protocol mismatched.\n");
1003 $$ = ipsecdoi_sockaddr2id(saddr,
1004 $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3,
1009 racoon_yyerror("invalid family: %d", saddr->ss_family);
1017 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1020 struct sockaddr_storage *laddr = NULL, *haddr = NULL;
1022 if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6)
1023 && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) {
1024 racoon_yyerror("port number must be \"any\".");
1028 snprintf(portbuf, sizeof(portbuf), "%lu", $5);
1030 laddr = str2saddr($2->v, portbuf);
1031 if (laddr == NULL) {
1035 haddr = str2saddr($3->v, portbuf);
1036 if (haddr == NULL) {
1042 switch (laddr->ss_family) {
1044 if ($6 == IPPROTO_ICMPV6) {
1045 racoon_yyerror("upper layer protocol mismatched.\n");
1052 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1057 if ($6 == IPPROTO_ICMP) {
1058 racoon_yyerror("upper layer protocol mismatched.\n");
1065 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1070 racoon_yyerror("invalid family: %d", laddr->ss_family);
1081 | IDENTIFIERTYPE QUOTEDSTRING
1083 struct ipsecdoi_id_b *id_b;
1085 if ($1 == IDTYPE_ASN1DN) {
1086 racoon_yyerror("id type forbidden: %d", $1);
1093 $$ = vmalloc(sizeof(*id_b) + $2->l);
1095 racoon_yyerror("failed to allocate identifier");
1099 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)$$->v;
1100 id_b->type = idtype2doi($1);
1105 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
1111 cur_sainfo->id_i = NULL;
1114 | FROM IDENTIFIERTYPE identifierstring
1116 struct ipsecdoi_id_b *id_b;
1119 if (set_identifier(&idv, $2, $3) != 0) {
1120 racoon_yyerror("failed to set identifer.\n");
1123 cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l);
1124 if (cur_sainfo->id_i == NULL) {
1125 racoon_yyerror("failed to allocate identifier");
1129 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)cur_sainfo->id_i->v;
1130 id_b->type = idtype2doi($2);
1135 memcpy(cur_sainfo->id_i->v + sizeof(*id_b),
1139 | GROUP QUOTEDSTRING
1141 #ifdef ENABLE_HYBRID
1142 if ((cur_sainfo->group = vdup($2)) == NULL) {
1143 racoon_yyerror("failed to set sainfo xauth group.\n");
1147 racoon_yyerror("racoon not configured with --enable-hybrid");
1154 | sainfo_specs sainfo_spec
1157 : PFS_GROUP dh_group_num
1159 cur_sainfo->pfs_group = $2;
1160 switch (cur_sainfo->pfs_group)
1162 case OAKLEY_ATTR_GRP_DESC_MODP768:
1163 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1164 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1165 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1166 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1167 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1168 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1169 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1172 racoon_yyerror("Invalid PFS group specified");
1178 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1180 cur_sainfo->lifetime = $3 * $4;
1183 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1186 racoon_yyerror("byte lifetime support is deprecated");
1189 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
1190 if (cur_sainfo->lifebyte == 0)
1199 | IDENTIFIER IDENTIFIERTYPE
1201 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1204 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
1206 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1214 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1218 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1223 : ALGORITHMTYPE keylength
1227 $$ = newsainfoalg();
1229 racoon_yyerror("failed to get algorithm allocation");
1233 $$->alg = algtype2doi(cur_algclass, $1);
1234 if ($$->alg == -1) {
1235 racoon_yyerror("algorithm mismatched");
1241 defklen = default_keylen(cur_algclass, $1);
1244 racoon_yyerror("keylen not allowed");
1250 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
1251 racoon_yyerror("invalid keylen %d", $2);
1261 $$->encklen = defklen;
1263 /* check if it's supported algorithm by kernel */
1264 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
1265 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
1266 int a = algclass2doi(cur_algclass);
1267 int b = algtype2doi(cur_algclass, $1);
1268 if (a == IPSECDOI_ATTR_AUTH)
1269 a = IPSECDOI_PROTO_IPSEC_AH;
1270 racoon_yyerror("algorithm %s not supported by the kernel (missing module?)",
1271 s_ipsecdoi_trns(a, b));
1279 : /* nothing */ { $$ = ~0; }
1280 | PREFIX { $$ = $1; }
1283 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
1285 | PORTANY { $$ = IPSEC_PORT_ANY; }
1288 : NUMBER { $$ = $1; }
1289 | UL_PROTO { $$ = $1; }
1290 | ANY { $$ = IPSEC_ULPROTO_ANY; }
1293 : /* nothing */ { $$ = 0; }
1294 | NUMBER { $$ = $1; }
1299 : REMOTE remote_index INHERIT remote_index
1301 struct remoteconf *new;
1302 struct proposalspec *prspec;
1304 new = copyrmconf($4->addr);
1306 racoon_yyerror("failed to get remoteconf for %s.", saddr2str((struct sockaddr *)$4));
1307 racoon_free($2->addr);
1309 racoon_free($4->addr);
1314 new->remote = $2->addr;
1315 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1316 new->inherited_from = getrmconf_strict($4->addr, 1);
1317 new->proposal = NULL;
1321 racoon_free($4->addr);
1324 prspec = newprspec();
1325 if (prspec == NULL || !cur_rmconf->inherited_from
1326 || !cur_rmconf->inherited_from->proposal)
1328 prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime;
1329 prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte;
1330 insprspec(prspec, &cur_rmconf->prhead);
1333 | REMOTE remote_index
1335 struct remoteconf *new;
1336 struct proposalspec *prspec;
1338 new = create_rmconf();
1340 racoon_yyerror("failed to get new remoteconf.");
1341 racoon_free($2->addr);
1345 new->remote = $2->addr;
1346 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1350 prspec = newprspec();
1353 prspec->lifetime = oakley_get_defaultlifetime();
1354 insprspec(prspec, &cur_rmconf->prhead);
1360 : BOC remote_specs EOC
1362 /* check a exchange mode */
1363 if (cur_rmconf->etypes == NULL) {
1364 racoon_yyerror("no exchange mode specified.\n");
1368 if (cur_rmconf->idvtype == IDTYPE_UNDEFINED)
1369 cur_rmconf->idvtype = IDTYPE_ADDRESS;
1372 if (cur_rmconf->idvtype == IDTYPE_ASN1DN) {
1373 if (cur_rmconf->identity_in_keychain)
1375 if (cur_rmconf->idv)
1376 racoon_yywarn("Both CERT and ASN1 ID "
1377 "are set. Hope this is OK.\n");
1378 /* TODO: Preparse the DN here */
1379 } else if (cur_rmconf->idv) {
1380 /* OK, using asn1dn without X.509. */
1382 racoon_yyerror("ASN1 ID not specified "
1383 "and no CERT defined!\n");
1388 if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
1389 struct genlist_entry *gpb;
1390 if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) {
1391 racoon_yyerror("peers_identifier required for specified certificate "
1392 "verification option.\n");
1397 if (cur_rmconf->prhead->spspec == NULL
1398 && cur_rmconf->inherited_from
1399 && cur_rmconf->inherited_from->prhead) {
1400 cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec;
1402 if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0)
1405 /* DH group setting if aggressive mode or IKEv2. */
1406 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
1411 for (p = cur_rmconf->proposal; p; p = p->next) {
1412 if (b == 0 || (b && b == p->dh_group)) {
1416 racoon_yyerror("DH group must be equal "
1418 "when aggressive mode is "
1422 cur_rmconf->dh_group = b;
1424 if (cur_rmconf->dh_group == 0) {
1425 racoon_yyerror("DH group must be set in the proposal.\n");
1429 /* DH group settting if PFS is required. */
1430 if (oakley_setdhgroup(cur_rmconf->dh_group,
1431 &cur_rmconf->dhgrp) < 0) {
1432 racoon_yyerror("failed to set DH value.\n");
1437 insrmconf(cur_rmconf);
1441 : ANONYMOUS ike_port
1444 struct remote_index_val *new;
1446 new = racoon_calloc(1, sizeof(*new));
1448 racoon_yyerror("failed to allocate remote index struct");
1451 new->addr = newsaddr(sizeof(struct sockaddr_storage));
1452 if (new->addr == NULL) {
1453 racoon_yyerror("failed to allocate sockaddr storage");
1457 new->addr->ss_family = AF_UNSPEC;
1458 (ALIGNED_CAST(struct sockaddr_in *)new->addr)->sin_port = htons($2);
1462 | ike_addrinfo_prefix_port
1466 racoon_yyerror("failed to allocate sockaddr_storage");
1473 | remote_specs remote_spec
1478 cur_rmconf->etypes = NULL;
1481 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1482 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1483 | IKE_VERSION NUMBER
1486 cur_rmconf->ike_version = ISAKMP_VERSION_NUMBER_IKEV1;
1488 racoon_yyerror("invalid IKE version specified.\n");
1492 | CERTIFICATE_TYPE cert_spec
1493 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1494 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1495 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1496 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1498 cur_rmconf->cert_verification = $2;
1500 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1502 cur_rmconf->cert_verification = $2;
1503 cur_rmconf->cert_verification_option = $3;
1506 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1509 cur_rmconf->open_dir_auth_group = $2;
1511 racoon_yyerror("Apple specific features not compiled in.");
1515 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1517 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1518 racoon_yyerror("failed to set identifer.\n");
1519 vfree($3); //%%% BUG FIX - memory leak
1522 vfree($3); //%%% BUG FIX - memory leak
1523 cur_rmconf->idvtype = $2;
1526 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1528 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1529 racoon_yyerror("failed to set identifer.\n");
1532 cur_rmconf->idvtype = $2;
1535 | XAUTH_LOGIN identifierstring
1537 #ifdef ENABLE_HYBRID
1538 /* formerly identifier type login */
1539 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1540 racoon_yyerror("failed to allocate xauth state\n");
1543 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1544 racoon_yyerror("failed to set identifer.\n");
1547 vfree($2); //%%% BUG FIX - memory leak
1549 racoon_yyerror("racoon not configured with --enable-hybrid");
1553 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1558 racoon_yyerror("failed to allocate idspec");
1561 if (set_identifier(&id->id, $2, $3) != 0) {
1562 racoon_yyerror("failed to set identifer.\n");
1564 vfree($3); //%%% BUG FIX - memory leak
1567 vfree($3); //%%% BUG FIX - memory leak
1569 genlist_append (cur_rmconf->idvl_p, id);
1572 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1577 racoon_yyerror("failed to allocate idspec");
1580 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1581 racoon_yyerror("failed to set identifer.\n");
1586 genlist_append (cur_rmconf->idvl_p, id);
1589 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1590 | LOCAL_ADDRESS ADDRSTRING
1592 struct sockaddr_storage *saddr;
1593 saddr = str2saddr($2->v, NULL);
1597 cur_rmconf->forced_local = saddr;
1599 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1601 cur_rmconf->secrettype = $2;
1602 cur_rmconf->shared_secret = $3;
1604 | SHARED_SECRET SECRETTYPE
1606 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1607 racoon_yyerror("shared secret value missing.\n");
1610 cur_rmconf->secrettype = $2;
1612 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1615 racoon_yyerror("dh_group cannot be defined here.");
1619 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1620 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1621 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1623 #ifdef SADB_X_EXT_NAT_T_FRAG
1624 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1625 cur_rmconf->esp_frag = $2;
1627 racoon_yywarn("libipsec lacks IKE frag support");
1629 racoon_yywarn("Your kernel does not support esp_frag");
1632 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1633 | WEAK_PHASE1_CHECK SWITCH {
1634 cur_rmconf->weak_phase1_check = $2;
1636 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1637 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1638 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1639 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1640 | NAT_TRAVERSAL SWITCH
1643 cur_rmconf->nat_traversal = $2;
1645 racoon_yyerror("NAT-T support not compiled in.");
1648 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1651 cur_rmconf->nat_traversal = $2;
1653 racoon_yyerror("NAT-T support not compiled in.");
1656 | NAT_TRAVERSAL_MULTI_USER SWITCH
1659 cur_rmconf->natt_multiple_user = $2;
1661 racoon_yyerror("NAT-T support not compiled in.");
1664 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1667 cur_rmconf->natt_keepalive = $2;
1669 racoon_yyerror("NAT-T support not compiled in.");
1675 cur_rmconf->dpd = $2;
1677 racoon_yyerror("DPD support not compiled in.");
1683 cur_rmconf->dpd_interval = $2;
1685 racoon_yyerror("DPD support not compiled in.");
1692 cur_rmconf->dpd_retry = $2;
1694 racoon_yyerror("DPD support not compiled in.");
1698 | DPD_MAXFAIL NUMBER
1701 cur_rmconf->dpd_maxfails = $2;
1703 racoon_yyerror("DPD support not compiled in.");
1707 | DPD_ALGORITHM dpd_algo_type
1710 cur_rmconf->dpd_algo = $2;
1712 racoon_yyerror("DPD support not compiled in.");
1716 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1718 cur_rmconf->idle_timeout = $3;
1719 cur_rmconf->idle_timeout_dir = $5;
1722 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1724 cur_rmconf->prhead->lifetime = $3 * $4;
1727 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1728 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1731 racoon_yyerror("byte lifetime support is deprecated in Phase 1");
1734 racoon_yywarn("the lifetime of bytes in phase 1 "
1735 "will be ignored at the moment.");
1736 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1737 if (cur_rmconf->prhead->lifebyte == 0)
1744 struct secprotospec *spspec;
1746 spspec = newspspec();
1749 insspspec(spspec, &cur_rmconf->prhead);
1751 BOC isakmpproposal_specs EOC
1755 | exchange_types EXCHANGETYPE
1758 new = racoon_malloc(sizeof(struct etypes));
1760 racoon_yyerror("failed to allocate etypes");
1765 if (cur_rmconf->etypes == NULL)
1766 cur_rmconf->etypes = new;
1769 for (p = cur_rmconf->etypes;
1778 : CERT_X509 IN_KEYCHAIN
1780 cur_rmconf->certtype = $1;
1781 cur_rmconf->identity_in_keychain = 1;
1782 cur_rmconf->keychainCertRef = NULL;
1786 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1788 cur_rmconf->certtype = $1;
1789 cur_rmconf->identity_in_keychain = 1;
1790 cur_rmconf->keychainCertRef = $3;
1797 $$ = algtype2doi(algclass_isakmp_dh, $1);
1799 racoon_yyerror("must be DH group");
1804 case OAKLEY_ATTR_GRP_DESC_MODP768:
1805 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1806 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1807 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1808 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1809 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1810 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1811 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1814 racoon_yyerror("Invalid DH group specified");
1821 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1822 $$ = num2dhgroup[$1];
1824 racoon_yyerror("must be DH group");
1830 case OAKLEY_ATTR_GRP_DESC_MODP768:
1831 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1832 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1833 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1834 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1835 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1836 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1837 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1840 racoon_yyerror("Invalid DH group specified");
1847 : /* nothing */ { $$ = NULL; }
1848 | ADDRSTRING { $$ = $1; }
1849 | QUOTEDSTRING { $$ = $1; }
1851 isakmpproposal_specs
1853 | isakmpproposal_specs isakmpproposal_spec
1858 racoon_yyerror("strength directive is obsoleted.");
1860 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1862 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
1865 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1868 racoon_yyerror("byte lifetime support is deprecated");
1871 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
1872 if (cur_rmconf->prhead->spspec->lifebyte == 0)
1877 | DH_GROUP dh_group_num
1879 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
1882 | GSS_ID QUOTEDSTRING
1884 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
1885 racoon_yyerror("wrong Vendor ID for gssapi_id");
1888 if (cur_rmconf->prhead->spspec->gssid != NULL)
1889 racoon_free(cur_rmconf->prhead->spspec->gssid);
1890 cur_rmconf->prhead->spspec->gssid =
1891 racoon_strdup($2->v);
1892 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
1895 | ALGORITHM_CLASS ALGORITHMTYPE keylength
1900 doi = algtype2doi($1, $2);
1902 racoon_yyerror("algorithm mismatched 1");
1908 case algclass_isakmp_enc:
1909 /* reject suppressed algorithms */
1910 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
1911 defklen = default_keylen($1, $2);
1914 racoon_yyerror("keylen not allowed");
1918 if ($3 && check_keylen($1, $2, $3) < 0) {
1919 racoon_yyerror("invalid keylen %d", $3);
1924 cur_rmconf->prhead->spspec->encklen = $3;
1926 cur_rmconf->prhead->spspec->encklen = defklen;
1928 case algclass_isakmp_hash:
1929 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
1931 case algclass_isakmp_ameth:
1932 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
1934 * We may have to set the Vendor ID for the
1935 * authentication method we're using.
1938 case algtype_gssapikrb:
1939 if (cur_rmconf->prhead->spspec->vendorid !=
1941 racoon_yyerror("Vendor ID mismatch "
1946 * For interoperability with Win2k,
1947 * we set the Vendor ID to "GSSAPI".
1949 cur_rmconf->prhead->spspec->vendorid =
1957 racoon_yyerror("algorithm mismatched 2");
1965 : UNITTYPE_SEC { $$ = 1; }
1966 | UNITTYPE_MIN { $$ = 60; }
1967 | UNITTYPE_HOUR { $$ = (60 * 60); }
1970 : UNITTYPE_BYTE { $$ = 1; }
1971 | UNITTYPE_KBYTES { $$ = 1024; }
1972 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
1973 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
1976 : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; }
1977 | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; }
1978 | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; }
1981 : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; }
1982 | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; }
1983 | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; }
1987 static struct proposalspec *
1990 struct proposalspec *new;
1992 new = racoon_calloc(1, sizeof(*new));
1994 racoon_yyerror("failed to allocate proposal");
2000 * insert into head of list.
2003 insprspec(prspec, head)
2004 struct proposalspec *prspec;
2005 struct proposalspec **head;
2008 (*head)->prev = prspec;
2009 prspec->next = *head;
2013 static struct secprotospec *
2016 struct secprotospec *new;
2018 new = racoon_calloc(1, sizeof(*new));
2020 racoon_yyerror("failed to allocate spproto");
2024 new->encklen = 0; /*XXX*/
2027 * Default to "uknown" vendor -- we will override this
2028 * as necessary. When we send a Vendor ID payload, an
2029 * "unknown" will be translated to a KAME/racoon ID.
2031 new->vendorid = VENDORID_UNKNOWN;
2037 * insert into head of list.
2040 insspspec(spspec, head)
2041 struct secprotospec *spspec;
2042 struct proposalspec **head;
2044 spspec->back = *head;
2046 if ((*head)->spspec != NULL)
2047 (*head)->spspec->prev = spspec;
2048 spspec->next = (*head)->spspec;
2049 (*head)->spspec = spspec;
2052 /* set final acceptable proposal */
2054 set_isakmp_proposal(rmconf, prspec)
2055 struct remoteconf *rmconf;
2056 struct proposalspec *prspec;
2058 struct proposalspec *p;
2059 struct secprotospec *s;
2062 int32_t types[MAXALGCLASS];
2067 "multiple proposal definition.\n");
2071 /* mandatory check */
2072 if (p->spspec == NULL) {
2073 racoon_yyerror("no remote specification found: %s.\n",
2074 saddr2str((struct sockaddr *)rmconf->remote));
2077 for (s = p->spspec; s != NULL; s = s->next) {
2078 /* XXX need more to check */
2079 if (s->algclass[algclass_isakmp_enc] == 0) {
2080 racoon_yyerror("encryption algorithm required.");
2083 if (s->algclass[algclass_isakmp_hash] == 0) {
2084 racoon_yyerror("hash algorithm required.");
2087 if (s->algclass[algclass_isakmp_dh] == 0) {
2088 racoon_yyerror("DH group required.");
2091 if (s->algclass[algclass_isakmp_ameth] == 0) {
2092 racoon_yyerror("authentication method required.");
2097 /* skip to last part */
2098 for (s = p->spspec; s->next != NULL; s = s->next)
2102 plog(ASL_LEVEL_DEBUG,
2103 "lifetime = %ld\n", (long)
2104 (s->lifetime ? s->lifetime : p->lifetime));
2105 plog(ASL_LEVEL_DEBUG,
2107 s->lifebyte ? s->lifebyte : p->lifebyte);
2108 plog(ASL_LEVEL_DEBUG,
2109 "encklen=%d\n", s->encklen);
2111 memset(types, 0, ARRAYLEN(types));
2112 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
2113 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
2114 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
2115 types[algclass_isakmp_ameth] =
2116 s->algclass[algclass_isakmp_ameth];
2118 /* expanding spspec */
2120 trns_no = expand_isakmpspec(prop_no, trns_no, types,
2121 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
2122 s->lifetime ? s->lifetime : p->lifetime,
2123 s->lifebyte ? s->lifebyte : p->lifebyte,
2124 s->encklen, s->vendorid, s->gssid,
2126 if (trns_no == -1) {
2128 "failed to expand isakmp proposal.\n");
2135 if (rmconf->proposal == NULL) {
2137 "no proposal found.\n");
2148 for (i = 0; i < MAXALGCLASS; i++)
2149 tmpalgtype[i] = 0; /* means algorithm undefined. */
2153 expand_isakmpspec(prop_no, trns_no, types,
2154 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
2156 int prop_no, trns_no;
2157 int *types, class, last;
2163 struct remoteconf *rmconf;
2165 struct isakmpsa *new;
2171 plog(ASL_LEVEL_DEBUG,
2172 "p:%d t:%d\n", prop_no, trns_no);
2173 for (j = class; j < MAXALGCLASS; j++) {
2174 snprintf(tb, sizeof(tb), "%d", types[j]);
2175 plog(ASL_LEVEL_DEBUG,
2177 s_algtype(j, types[j]),
2178 types[j] ? "(" : "",
2179 tb[0] == '0' ? "" : tb,
2180 types[j] ? ")" : "");
2182 plog(ASL_LEVEL_DEBUG, "\n");
2185 #define TMPALGTYPE2STR(n) \
2186 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
2187 /* check mandatory values */
2188 if (types[algclass_isakmp_enc] == 0
2189 || types[algclass_isakmp_ameth] == 0
2190 || types[algclass_isakmp_dh] == 0) {
2191 racoon_yyerror("few definition of algorithm "
2192 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2193 TMPALGTYPE2STR(enc),
2194 TMPALGTYPE2STR(ameth),
2195 TMPALGTYPE2STR(hash),
2196 TMPALGTYPE2STR(dh));
2199 #undef TMPALGTYPE2STR
2202 new = newisakmpsa();
2204 racoon_yyerror("failed to allocate isakmp sa");
2207 new->prop_no = prop_no;
2208 new->trns_no = trns_no++;
2209 new->lifetime = lifetime;
2210 new->lifebyte = lifebyte;
2211 new->enctype = types[algclass_isakmp_enc];
2212 new->encklen = encklen;
2213 new->authmethod = types[algclass_isakmp_ameth];
2214 new->hashtype = types[algclass_isakmp_hash];
2215 new->prf = types[algclass_isakmp_hash];
2216 new->dh_group = types[algclass_isakmp_dh];
2217 new->vendorid = vendorid;
2218 insisakmpsa(new, rmconf);
2224 listen_addr (struct sockaddr_storage *addr, int udp_encap)
2230 racoon_yyerror("failed to allocate myaddrs");
2234 if (p->addr == NULL) {
2235 racoon_yyerror("failed to copy sockaddr_storage ");
2239 p->udp_encap = udp_encap;
2240 /* These need to be initialized for Apple modifications
2241 * to open code for isakmp sockets
2246 insmyaddr(p, &lcconf->myaddrs);
2248 lcconf->autograbaddr = 0;
2255 * Must be more than 1024B because its unit is kilobytes.
2256 * That is defined RFC2407.
2263 racoon_yyerror("byte size should be more than 1024B.");
2276 plog(ASL_LEVEL_DEBUG, "===== parsing configuration\n");
2280 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2282 "could not read configuration file \"%s\"\n",
2283 lcconf->racoon_conf);
2291 "fatal parse failure (%d errors)\n",
2295 "fatal parse failure.\n");
2297 yycf_clean_buffer();
2301 if (error == 0 && yyerrorcount) {
2303 "parse error is nothing, but yyerrorcount is %d.\n",
2305 yycf_clean_buffer();
2309 yycf_clean_buffer();
2311 plog(ASL_LEVEL_DEBUG, "parse succeeded.\n");
2320 int ignore_estab_or_assert_handles = (sig == SIGUSR1);
2322 if (sig >= 0 && sig < NSIG) {
2323 plog(ASL_LEVEL_DEBUG, "==== Got %s signal - re-parsing configuration.\n", sys_signame[sig]);
2325 plog(ASL_LEVEL_ERR, "==== Got Unknown signal - re-parsing configuration.\n");
2327 plog(ASL_LEVEL_DEBUG, "==== %s sessions.\n", ignore_estab_or_assert_handles? "flush negotiating" : "flush all");
2329 ike_session_flush_all_phase2(ignore_estab_or_assert_handles);
2330 ike_session_flush_all_phase1(ignore_estab_or_assert_handles);
2333 check_auto_exit(); /* check/change state of auto exit */