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"
89 #include "isakmp_unity.h"
90 #include "isakmp_xauth.h"
91 #include "isakmp_cfg.h"
93 #include "ipsec_doi.h"
97 #include "ipsecConfigTracer.h"
98 #include "ipsecMessageTracer.h"
100 static int num2dhgroup[] = {
102 OAKLEY_ATTR_GRP_DESC_MODP768,
103 OAKLEY_ATTR_GRP_DESC_MODP1024,
104 OAKLEY_ATTR_GRP_DESC_EC2N155,
105 OAKLEY_ATTR_GRP_DESC_EC2N185,
106 OAKLEY_ATTR_GRP_DESC_MODP1536,
115 OAKLEY_ATTR_GRP_DESC_MODP2048,
116 OAKLEY_ATTR_GRP_DESC_MODP3072,
117 OAKLEY_ATTR_GRP_DESC_MODP4096,
118 OAKLEY_ATTR_GRP_DESC_MODP6144,
119 OAKLEY_ATTR_GRP_DESC_MODP8192
122 struct remote_index_val {
124 struct sockaddr_storage *addr;
127 static struct remoteconf *cur_rmconf;
128 static int tmpalgtype[MAXALGCLASS];
129 static struct sainfo *cur_sainfo;
130 static int cur_algclass;
132 static struct proposalspec *newprspec (void);
133 static void insprspec (struct proposalspec *, struct proposalspec **);
134 static struct secprotospec *newspspec (void);
135 static void insspspec (struct secprotospec *, struct proposalspec **);
137 static int set_isakmp_proposal (struct remoteconf *, struct proposalspec *);
138 static void clean_tmpalgtype (void);
139 static int expand_isakmpspec (int, int, int *,
140 int, int, time_t, int, int, int, char *, struct remoteconf *);
141 static int listen_addr (struct sockaddr_storage *addr, int udp_encap);
143 void freeetypes (struct etypes **etypes);
146 static int fix_lifebyte (u_long);
153 struct remoteconf *rmconf;
154 struct sockaddr_storage *saddr;
155 struct sainfoalg *alg;
156 struct remote_index_val *rmidx;
163 /* self information */
164 %token IDENTIFIER VENDORID
166 %token LOGGING LOGLEV
168 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
170 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
172 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
173 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
174 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
175 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
176 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
178 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
179 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY
181 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
183 %token SAINFO FROM GROUP
185 %token REMOTE ANONYMOUS INHERIT
186 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
187 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
188 %token VERIFY_CERT SEND_CERT SEND_CR
189 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
190 %token PEERS_IDENTIFIER VERIFY_IDENTIFIER
192 %token SHARED_SECRET SECRETTYPE
193 %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
194 %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
195 %token DNSSEC CERT_X509 CERT_PLAINRSA
196 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
197 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE
198 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
199 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
201 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
202 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
203 %token COMPLEX_BUNDLE
204 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM
205 %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION
206 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
208 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
209 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
211 %token NUMBER SWITCH BOOLEAN
212 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
213 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
214 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
215 %token EOS BOC EOC COMMA
216 %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE
217 %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY IKE_VERSION
219 %type <num> NUMBER BOOLEAN SWITCH keylength
220 %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
221 %type <num> SECRETTYPE
222 %type <num> ALGORITHM_CLASS dh_group_num
223 %type <num> ALGORITHMTYPE STRENGTHTYPE
224 %type <num> PREFIX prefix PORT port ike_port
225 %type <num> ul_proto UL_PROTO
226 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
227 %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL
228 %type <num> VERIFICATION_MODULE VERIFICATION_OPTION
229 %type <num> unittype_time unittype_byte
230 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
231 %type <val> identifierstring
232 %type <saddr> ike_addrinfo_port
233 %type <alg> algorithm
234 %type <num> dpd_algo_type
235 %type <num> idle_dir_type
236 %type <rmidx> remote_index ike_addrinfo_prefix_port
242 | statements statement
247 | identifier_statement
260 : PATH PATHTYPE QUOTEDSTRING
262 if ($2 >= LC_PATHTYPE_MAX) {
263 racoon_yyerror("invalid path type %d", $2);
267 /* free old pathinfo */
268 if (lcconf->pathinfo[$2])
269 racoon_free(lcconf->pathinfo[$2]);
271 /* set new pathinfo */
272 lcconf->pathinfo[$2] = racoon_strdup($3->v);
273 STRDUP_FATAL(lcconf->pathinfo[$2]);
281 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
286 : INCLUDE QUOTEDSTRING EOS
288 char path[MAXPATHLEN];
290 getpathname(path, sizeof(path),
291 LC_PATHTYPE_INCLUDE, $2->v);
293 if (yycf_switch_buffer(path) != 0)
298 /* self information */
300 : IDENTIFIER identifier_stmt
305 /*XXX to be deleted */
308 | IDENTIFIERTYPE QUOTEDSTRING
310 /*XXX to be deleted */
311 $2->l--; /* nuke '\0' */
312 lcconf->ident[$1] = $2;
313 if (lcconf->ident[$1] == NULL) {
314 racoon_yyerror("failed to set my ident: %s",
324 : LOGGING log_level EOS
330 * XXX ignore it because this specification
333 plogsetlevelquotedstr($1->v);
344 : PADDING BOC padding_stmts EOC
348 | padding_stmts padding_stmt
351 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
352 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
353 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
354 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
355 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
360 : LISTEN BOC listen_stmts EOC
364 | listen_stmts listen_stmt
367 : X_ISAKMP ike_addrinfo_port
372 | X_ISAKMP_NATT ike_addrinfo_port
377 racoon_yyerror("NAT-T support not compiled in.");
383 racoon_yyerror("admin directive is obsoleted.");
386 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
388 racoon_yywarn("admin port support not compiled in");
391 | ADMINSOCK QUOTEDSTRING
393 racoon_yywarn("admin port support not compiled in");
398 racoon_yywarn("admin port support not compiled in");
401 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
404 : ADDRSTRING ike_port
408 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
409 $$ = str2saddr($1->v, portbuf);
415 ike_addrinfo_prefix_port
416 : ADDRSTRING prefix ike_port
419 struct remote_index_val *new;
421 new = racoon_calloc(1, sizeof(*new));
423 racoon_yyerror("failed to allocate remote index struct");
427 snprintf(portbuf, sizeof(portbuf), "%ld", $3);
428 new->addr = str2saddr($1->v, portbuf);
431 racoon_yyerror("failed to allocate sockaddr storage");
439 : /* nothing */ { $$ = PORT_ISAKMP; }
444 : MODECFG BOC modecfg_stmts EOC
448 | modecfg_stmts modecfg_stmt
451 : CFG_NET4 ADDRSTRING
454 if (inet_pton(AF_INET, $2->v,
455 &isakmp_cfg_config.network4) != 1)
456 racoon_yyerror("bad IPv4 network address.");
459 racoon_yyerror("racoon not configured with --enable-hybrid");
463 | CFG_MASK4 ADDRSTRING
466 if (inet_pton(AF_INET, $2->v,
467 &isakmp_cfg_config.netmask4) != 1)
468 racoon_yyerror("bad IPv4 netmask address.");
471 racoon_yyerror("racoon not configured with --enable-hybrid");
475 | CFG_DNS4 addrdnslist
477 | CFG_NBNS4 addrwinslist
479 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
482 isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN;
484 racoon_yyerror("racoon not configured with --enable-hybrid");
488 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
491 isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE;
493 racoon_yyerror("racoon not configured with --enable-hybrid");
497 | CFG_SPLIT_DNS splitdnslist
499 #ifndef ENABLE_HYBRID
500 racoon_yyerror("racoon not configured with --enable-hybrid");
504 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
507 strlcpy(&isakmp_cfg_config.default_domain[0],
508 $2->v, sizeof(isakmp_cfg_config.default_domain));
511 racoon_yyerror("racoon not configured with --enable-hybrid");
515 | CFG_AUTH_SOURCE CFG_SYSTEM
518 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM;
520 racoon_yyerror("racoon not configured with --enable-hybrid");
524 | CFG_AUTH_SOURCE CFG_RADIUS
527 racoon_yyerror("racoon not configured with --with-libradius");
528 #else /* ENABLE_HYBRID */
529 racoon_yyerror("racoon not configured with --enable-hybrid");
530 #endif /* ENABLE_HYBRID */
533 | CFG_AUTH_SOURCE CFG_PAM
536 racoon_yyerror("racoon not configured with --with-libpam");
537 #else /* ENABLE_HYBRID */
538 racoon_yyerror("racoon not configured with --enable-hybrid");
539 #endif /* ENABLE_HYBRID */
542 | CFG_AUTH_SOURCE CFG_LDAP
545 racoon_yyerror("racoon not configured with --with-libldap");
546 #else /* ENABLE_HYBRID */
547 racoon_yyerror("racoon not configured with --enable-hybrid");
548 #endif /* ENABLE_HYBRID */
551 | CFG_AUTH_GROUPS authgrouplist
553 #ifndef ENABLE_HYBRID
554 racoon_yyerror("racoon not configured with --enable-hybrid");
558 | CFG_GROUP_SOURCE CFG_SYSTEM
561 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM;
563 racoon_yyerror("racoon not configured with --enable-hybrid");
567 | CFG_GROUP_SOURCE CFG_LDAP
570 racoon_yyerror("racoon not configured with --with-libldap");
571 #else /* ENABLE_HYBRID */
572 racoon_yyerror("racoon not configured with --enable-hybrid");
573 #endif /* ENABLE_HYBRID */
576 | CFG_ACCOUNTING CFG_NONE
579 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE;
581 racoon_yyerror("racoon not configured with --enable-hybrid");
585 | CFG_ACCOUNTING CFG_SYSTEM
588 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM;
590 racoon_yyerror("racoon not configured with --enable-hybrid");
594 | CFG_ACCOUNTING CFG_RADIUS
597 racoon_yyerror("racoon not configured with --with-libradius");
598 #else /* ENABLE_HYBRID */
599 racoon_yyerror("racoon not configured with --enable-hybrid");
600 #endif /* ENABLE_HYBRID */
603 | CFG_ACCOUNTING CFG_PAM
606 racoon_yyerror("racoon not configured with --with-libpam");
607 #else /* ENABLE_HYBRID */
608 racoon_yyerror("racoon not configured with --enable-hybrid");
609 #endif /* ENABLE_HYBRID */
612 | CFG_POOL_SIZE NUMBER
615 if (isakmp_cfg_resize_pool($2) != 0)
616 racoon_yyerror("cannot allocate memory for pool");
617 #else /* ENABLE_HYBRID */
618 racoon_yyerror("racoon not configured with --enable-hybrid");
619 #endif /* ENABLE_HYBRID */
622 | CFG_PFS_GROUP NUMBER
625 isakmp_cfg_config.pfs_group = $2;
626 switch (isakmp_cfg_config.pfs_group)
628 case OAKLEY_ATTR_GRP_DESC_MODP768:
629 case OAKLEY_ATTR_GRP_DESC_MODP1024:
630 case OAKLEY_ATTR_GRP_DESC_MODP1536:
631 case OAKLEY_ATTR_GRP_DESC_MODP2048:
632 case OAKLEY_ATTR_GRP_DESC_MODP3072:
633 case OAKLEY_ATTR_GRP_DESC_MODP4096:
634 case OAKLEY_ATTR_GRP_DESC_MODP6144:
635 case OAKLEY_ATTR_GRP_DESC_MODP8192:
638 racoon_yyerror("Invalid PFS group specified");
642 #else /* ENABLE_HYBRID */
643 racoon_yyerror("racoon not configured with --enable-hybrid");
644 #endif /* ENABLE_HYBRID */
647 | CFG_SAVE_PASSWD SWITCH
650 isakmp_cfg_config.save_passwd = $2;
651 #else /* ENABLE_HYBRID */
652 racoon_yyerror("racoon not configured with --enable-hybrid");
653 #endif /* ENABLE_HYBRID */
656 | CFG_AUTH_THROTTLE NUMBER
659 isakmp_cfg_config.auth_throttle = $2;
660 #else /* ENABLE_HYBRID */
661 racoon_yyerror("racoon not configured with --enable-hybrid");
662 #endif /* ENABLE_HYBRID */
665 | CFG_CONF_SOURCE CFG_LOCAL
668 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL;
669 #else /* ENABLE_HYBRID */
670 racoon_yyerror("racoon not configured with --enable-hybrid");
671 #endif /* ENABLE_HYBRID */
674 | CFG_CONF_SOURCE CFG_RADIUS
677 racoon_yyerror("racoon not configured with --with-libradius");
678 #else /* ENABLE_HYBRID */
679 racoon_yyerror("racoon not configured with --enable-hybrid");
680 #endif /* ENABLE_HYBRID */
683 | CFG_CONF_SOURCE CFG_LDAP
686 racoon_yyerror("racoon not configured with --with-libldap");
687 #else /* ENABLE_HYBRID */
688 racoon_yyerror("racoon not configured with --enable-hybrid");
689 #endif /* ENABLE_HYBRID */
692 | CFG_MOTD QUOTEDSTRING
695 strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd));
698 racoon_yyerror("racoon not configured with --enable-hybrid");
706 | addrdns COMMA addrdnslist
712 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
714 if (icc->dns4_index > MAXNS) {
715 racoon_yyerror("No more than %d DNS", MAXNS);
718 if (inet_pton(AF_INET, $1->v,
719 &icc->dns4[icc->dns4_index++]) != 1)
720 racoon_yyerror("bad IPv4 DNS address.");
724 racoon_yyerror("racoon not configured with --enable-hybrid");
731 | addrwins COMMA addrwinslist
737 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
739 if (icc->nbns4_index > MAXWINS) {
740 racoon_yyerror("No more than %d WINS", MAXWINS);
743 if (inet_pton(AF_INET, $1->v,
744 &icc->nbns4[icc->nbns4_index++]) != 1)
745 racoon_yyerror("bad IPv4 WINS address.");
749 racoon_yyerror("racoon not configured with --enable-hybrid");
756 | splitnetlist COMMA splitnet
762 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
763 struct unity_network network;
765 if (inet_pton(AF_INET, $1->v, &network.addr4) != 1)
766 racoon_yyerror("bad IPv4 SPLIT address.");
768 /* Turn $2 (the prefix) into a subnet mask */
769 network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0;
771 /* add the network to our list */
772 if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count))
773 racoon_yyerror("Unable to allocate split network");
777 racoon_yyerror("racoon not configured with --enable-hybrid");
784 | authgroup COMMA authgrouplist
790 char * groupname = NULL;
791 char ** grouplist = NULL;
792 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
794 grouplist = racoon_realloc(icc->grouplist,
795 sizeof(char**)*(icc->groupcount+1));
796 if (grouplist == NULL)
797 racoon_yyerror("unable to allocate auth group list");
799 groupname = racoon_malloc($1->l+1);
800 if (groupname == NULL)
801 racoon_yyerror("unable to allocate auth group name");
803 memcpy(groupname,$1->v,$1->l);
805 grouplist[icc->groupcount]=groupname;
806 icc->grouplist = grouplist;
811 racoon_yyerror("racoon not configured with --enable-hybrid");
818 | splitdns COMMA splitdnslist
824 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
826 if (!icc->splitdns_len)
828 icc->splitdns_list = racoon_malloc($1->l);
829 if(icc->splitdns_list == NULL)
830 racoon_yyerror("error allocating splitdns list buffer");
831 memcpy(icc->splitdns_list,$1->v,$1->l);
832 icc->splitdns_len = $1->l;
836 int len = icc->splitdns_len + $1->l + 1;
837 icc->splitdns_list = racoon_realloc(icc->splitdns_list,len);
838 if(icc->splitdns_list == NULL)
839 racoon_yyerror("error allocating splitdns list buffer");
840 icc->splitdns_list[icc->splitdns_len] = ',';
841 memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l);
842 icc->splitdns_len = len;
846 racoon_yyerror("racoon not configured with --enable-hybrid");
854 : RETRY BOC timer_stmts EOC
858 | timer_stmts timer_stmt
861 : RETRY_COUNTER NUMBER
863 lcconf->retry_counter = $2;
866 | RETRY_INTERVAL NUMBER unittype_time
868 lcconf->retry_interval = $2 * $3;
871 | RETRY_PERSEND NUMBER
873 lcconf->count_persend = $2;
876 | RETRY_PHASE1 NUMBER unittype_time
878 lcconf->retry_checkph1 = $2 * $3;
881 | RETRY_PHASE2 NUMBER unittype_time
883 lcconf->wait_ph2complete = $2 * $3;
886 | AUTO_EXIT_DELAY NUMBER unittype_time
888 lcconf->auto_exit_delay = $2 * $3;
889 lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET;
893 | NATT_KA NUMBER unittype_time
896 lcconf->natt_ka_interval = $2 * $3;
898 racoon_yyerror("NAT-T support not compiled in.");
908 cur_sainfo = create_sainfo();
909 if (cur_sainfo == NULL) {
910 racoon_yyerror("failed to allocate sainfo");
914 sainfo_name sainfo_param BOC sainfo_specs
916 struct sainfo *check;
919 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
920 racoon_yyerror("no encryption algorithm at %s",
921 sainfo2str(cur_sainfo));
924 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
925 racoon_yyerror("no authentication algorithm at %s",
926 sainfo2str(cur_sainfo));
929 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
930 racoon_yyerror("no compression algorithm at %s",
931 sainfo2str(cur_sainfo));
935 /* duplicate check */
936 check = getsainfo(cur_sainfo->idsrc,
938 cur_sainfo->id_i, 0);
939 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
940 racoon_yyerror("duplicated sainfo: %s",
941 sainfo2str(cur_sainfo));
944 inssainfo(cur_sainfo);
951 cur_sainfo->idsrc = NULL;
952 cur_sainfo->iddst = NULL;
954 | ANONYMOUS sainfo_id
956 cur_sainfo->idsrc = NULL;
957 cur_sainfo->iddst = $2;
959 | sainfo_id ANONYMOUS
961 cur_sainfo->idsrc = $1;
962 cur_sainfo->iddst = NULL;
964 | sainfo_id sainfo_id
966 cur_sainfo->idsrc = $1;
967 cur_sainfo->iddst = $2;
971 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
974 struct sockaddr_storage *saddr;
976 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
977 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
978 racoon_yyerror("port number must be \"any\".");
982 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
983 saddr = str2saddr($2->v, portbuf);
988 switch (saddr->ss_family) {
990 if ($5 == IPPROTO_ICMPV6) {
991 racoon_yyerror("upper layer protocol mismatched.\n");
995 $$ = ipsecdoi_sockaddr2id(saddr,
996 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
1001 if ($5 == IPPROTO_ICMP) {
1002 racoon_yyerror("upper layer protocol mismatched.\n");
1006 $$ = ipsecdoi_sockaddr2id(saddr,
1007 $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3,
1012 racoon_yyerror("invalid family: %d", saddr->ss_family);
1020 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1023 struct sockaddr_storage *laddr = NULL, *haddr = NULL;
1025 if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6)
1026 && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) {
1027 racoon_yyerror("port number must be \"any\".");
1031 snprintf(portbuf, sizeof(portbuf), "%lu", $5);
1033 laddr = str2saddr($2->v, portbuf);
1034 if (laddr == NULL) {
1038 haddr = str2saddr($3->v, portbuf);
1039 if (haddr == NULL) {
1045 switch (laddr->ss_family) {
1047 if ($6 == IPPROTO_ICMPV6) {
1048 racoon_yyerror("upper layer protocol mismatched.\n");
1055 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1060 if ($6 == IPPROTO_ICMP) {
1061 racoon_yyerror("upper layer protocol mismatched.\n");
1068 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1073 racoon_yyerror("invalid family: %d", laddr->ss_family);
1084 | IDENTIFIERTYPE QUOTEDSTRING
1086 struct ipsecdoi_id_b *id_b;
1088 if ($1 == IDTYPE_ASN1DN) {
1089 racoon_yyerror("id type forbidden: %d", $1);
1096 $$ = vmalloc(sizeof(*id_b) + $2->l);
1098 racoon_yyerror("failed to allocate identifier");
1102 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)$$->v;
1103 id_b->type = idtype2doi($1);
1108 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
1114 cur_sainfo->id_i = NULL;
1117 | FROM IDENTIFIERTYPE identifierstring
1119 struct ipsecdoi_id_b *id_b;
1122 if (set_identifier(&idv, $2, $3) != 0) {
1123 racoon_yyerror("failed to set identifer.\n");
1126 cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l);
1127 if (cur_sainfo->id_i == NULL) {
1128 racoon_yyerror("failed to allocate identifier");
1132 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)cur_sainfo->id_i->v;
1133 id_b->type = idtype2doi($2);
1138 memcpy(cur_sainfo->id_i->v + sizeof(*id_b),
1142 | GROUP QUOTEDSTRING
1144 #ifdef ENABLE_HYBRID
1145 if ((cur_sainfo->group = vdup($2)) == NULL) {
1146 racoon_yyerror("failed to set sainfo xauth group.\n");
1150 racoon_yyerror("racoon not configured with --enable-hybrid");
1157 | sainfo_specs sainfo_spec
1160 : PFS_GROUP dh_group_num
1162 cur_sainfo->pfs_group = $2;
1163 switch (cur_sainfo->pfs_group)
1165 case OAKLEY_ATTR_GRP_DESC_MODP768:
1166 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1167 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1168 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1169 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1170 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1171 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1172 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1175 racoon_yyerror("Invalid PFS group specified");
1181 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1183 cur_sainfo->lifetime = $3 * $4;
1186 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1189 racoon_yyerror("byte lifetime support is deprecated");
1192 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
1193 if (cur_sainfo->lifebyte == 0)
1202 | IDENTIFIER IDENTIFIERTYPE
1204 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1207 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
1209 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1217 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1221 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1226 : ALGORITHMTYPE keylength
1230 $$ = newsainfoalg();
1232 racoon_yyerror("failed to get algorithm allocation");
1236 $$->alg = algtype2doi(cur_algclass, $1);
1237 if ($$->alg == -1) {
1238 racoon_yyerror("algorithm mismatched");
1244 defklen = default_keylen(cur_algclass, $1);
1247 racoon_yyerror("keylen not allowed");
1253 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
1254 racoon_yyerror("invalid keylen %d", $2);
1264 $$->encklen = defklen;
1266 /* check if it's supported algorithm by kernel */
1267 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
1268 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
1269 int a = algclass2doi(cur_algclass);
1270 int b = algtype2doi(cur_algclass, $1);
1271 if (a == IPSECDOI_ATTR_AUTH)
1272 a = IPSECDOI_PROTO_IPSEC_AH;
1273 racoon_yyerror("algorithm %s not supported by the kernel (missing module?)",
1274 s_ipsecdoi_trns(a, b));
1282 : /* nothing */ { $$ = ~0; }
1283 | PREFIX { $$ = $1; }
1286 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
1288 | PORTANY { $$ = IPSEC_PORT_ANY; }
1291 : NUMBER { $$ = $1; }
1292 | UL_PROTO { $$ = $1; }
1293 | ANY { $$ = IPSEC_ULPROTO_ANY; }
1296 : /* nothing */ { $$ = 0; }
1297 | NUMBER { $$ = $1; }
1302 : REMOTE remote_index INHERIT remote_index
1304 struct remoteconf *new;
1305 struct proposalspec *prspec;
1307 new = copyrmconf($4->addr);
1309 racoon_yyerror("failed to get remoteconf for %s.", saddr2str((struct sockaddr *)$4));
1310 racoon_free($2->addr);
1312 racoon_free($4->addr);
1317 new->remote = $2->addr;
1318 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1319 new->inherited_from = getrmconf_strict($4->addr, 1);
1320 new->proposal = NULL;
1324 racoon_free($4->addr);
1327 prspec = newprspec();
1328 if (prspec == NULL || !cur_rmconf->inherited_from
1329 || !cur_rmconf->inherited_from->proposal)
1331 prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime;
1332 prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte;
1333 insprspec(prspec, &cur_rmconf->prhead);
1336 | REMOTE remote_index
1338 struct remoteconf *new;
1339 struct proposalspec *prspec;
1341 new = create_rmconf();
1343 racoon_yyerror("failed to get new remoteconf.");
1344 racoon_free($2->addr);
1348 new->remote = $2->addr;
1349 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1353 prspec = newprspec();
1356 prspec->lifetime = oakley_get_defaultlifetime();
1357 insprspec(prspec, &cur_rmconf->prhead);
1363 : BOC remote_specs EOC
1365 /* check a exchange mode */
1366 if (cur_rmconf->etypes == NULL) {
1367 racoon_yyerror("no exchange mode specified.\n");
1371 if (cur_rmconf->idvtype == IDTYPE_UNDEFINED)
1372 cur_rmconf->idvtype = IDTYPE_ADDRESS;
1375 if (cur_rmconf->idvtype == IDTYPE_ASN1DN) {
1376 if (cur_rmconf->identity_in_keychain)
1378 if (cur_rmconf->idv)
1379 racoon_yywarn("Both CERT and ASN1 ID "
1380 "are set. Hope this is OK.\n");
1381 /* TODO: Preparse the DN here */
1382 } else if (cur_rmconf->idv) {
1383 /* OK, using asn1dn without X.509. */
1385 racoon_yyerror("ASN1 ID not specified "
1386 "and no CERT defined!\n");
1391 if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
1392 struct genlist_entry *gpb;
1393 if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) {
1394 racoon_yyerror("peers_identifier required for specified certificate "
1395 "verification option.\n");
1400 if (cur_rmconf->prhead->spspec == NULL
1401 && cur_rmconf->inherited_from
1402 && cur_rmconf->inherited_from->prhead) {
1403 cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec;
1405 if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0)
1408 /* DH group setting if aggressive mode or IKEv2. */
1409 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
1414 for (p = cur_rmconf->proposal; p; p = p->next) {
1415 if (b == 0 || (b && b == p->dh_group)) {
1419 racoon_yyerror("DH group must be equal "
1421 "when aggressive mode is "
1425 cur_rmconf->dh_group = b;
1427 if (cur_rmconf->dh_group == 0) {
1428 racoon_yyerror("DH group must be set in the proposal.\n");
1432 /* DH group settting if PFS is required. */
1433 if (oakley_setdhgroup(cur_rmconf->dh_group,
1434 &cur_rmconf->dhgrp) < 0) {
1435 racoon_yyerror("failed to set DH value.\n");
1440 insrmconf(cur_rmconf);
1444 : ANONYMOUS ike_port
1447 struct remote_index_val *new;
1449 new = racoon_calloc(1, sizeof(*new));
1451 racoon_yyerror("failed to allocate remote index struct");
1454 new->addr = newsaddr(sizeof(struct sockaddr_storage));
1455 if (new->addr == NULL) {
1456 racoon_yyerror("failed to allocate sockaddr storage");
1460 new->addr->ss_family = AF_UNSPEC;
1461 (ALIGNED_CAST(struct sockaddr_in *)new->addr)->sin_port = htons($2);
1465 | ike_addrinfo_prefix_port
1469 racoon_yyerror("failed to allocate sockaddr_storage");
1476 | remote_specs remote_spec
1481 cur_rmconf->etypes = NULL;
1484 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1485 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1486 | IKE_VERSION NUMBER
1489 cur_rmconf->ike_version = ISAKMP_VERSION_NUMBER_IKEV1;
1491 racoon_yyerror("invalid IKE version specified.\n");
1495 | CERTIFICATE_TYPE cert_spec
1496 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1497 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1498 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1499 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1501 cur_rmconf->cert_verification = $2;
1503 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1505 cur_rmconf->cert_verification = $2;
1506 cur_rmconf->cert_verification_option = $3;
1509 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1512 cur_rmconf->open_dir_auth_group = $2;
1514 racoon_yyerror("Apple specific features not compiled in.");
1518 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1520 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1521 racoon_yyerror("failed to set identifer.\n");
1522 vfree($3); //%%% BUG FIX - memory leak
1525 vfree($3); //%%% BUG FIX - memory leak
1526 cur_rmconf->idvtype = $2;
1529 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1531 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1532 racoon_yyerror("failed to set identifer.\n");
1535 cur_rmconf->idvtype = $2;
1538 | XAUTH_LOGIN identifierstring
1540 #ifdef ENABLE_HYBRID
1541 /* formerly identifier type login */
1542 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1543 racoon_yyerror("failed to allocate xauth state\n");
1546 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1547 racoon_yyerror("failed to set identifer.\n");
1550 vfree($2); //%%% BUG FIX - memory leak
1552 racoon_yyerror("racoon not configured with --enable-hybrid");
1556 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1561 racoon_yyerror("failed to allocate idspec");
1564 if (set_identifier(&id->id, $2, $3) != 0) {
1565 racoon_yyerror("failed to set identifer.\n");
1567 vfree($3); //%%% BUG FIX - memory leak
1570 vfree($3); //%%% BUG FIX - memory leak
1572 genlist_append (cur_rmconf->idvl_p, id);
1575 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1580 racoon_yyerror("failed to allocate idspec");
1583 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1584 racoon_yyerror("failed to set identifer.\n");
1589 genlist_append (cur_rmconf->idvl_p, id);
1592 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1593 | LOCAL_ADDRESS ADDRSTRING
1595 struct sockaddr_storage *saddr;
1596 saddr = str2saddr($2->v, NULL);
1600 cur_rmconf->forced_local = saddr;
1602 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1604 cur_rmconf->secrettype = $2;
1605 cur_rmconf->shared_secret = $3;
1607 | SHARED_SECRET SECRETTYPE
1609 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1610 racoon_yyerror("shared secret value missing.\n");
1613 cur_rmconf->secrettype = $2;
1615 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1618 racoon_yyerror("dh_group cannot be defined here.");
1622 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1623 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1624 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1626 #ifdef SADB_X_EXT_NAT_T_FRAG
1627 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1628 cur_rmconf->esp_frag = $2;
1630 racoon_yywarn("libipsec lacks IKE frag support");
1632 racoon_yywarn("Your kernel does not support esp_frag");
1635 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1636 | WEAK_PHASE1_CHECK SWITCH {
1637 cur_rmconf->weak_phase1_check = $2;
1639 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1640 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1641 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1642 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1643 | NAT_TRAVERSAL SWITCH
1646 cur_rmconf->nat_traversal = $2;
1648 racoon_yyerror("NAT-T support not compiled in.");
1651 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1654 cur_rmconf->nat_traversal = $2;
1656 racoon_yyerror("NAT-T support not compiled in.");
1659 | NAT_TRAVERSAL_MULTI_USER SWITCH
1662 cur_rmconf->natt_multiple_user = $2;
1664 racoon_yyerror("NAT-T support not compiled in.");
1667 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1670 cur_rmconf->natt_keepalive = $2;
1672 racoon_yyerror("NAT-T support not compiled in.");
1678 cur_rmconf->dpd = $2;
1680 racoon_yyerror("DPD support not compiled in.");
1686 cur_rmconf->dpd_interval = $2;
1688 racoon_yyerror("DPD support not compiled in.");
1695 cur_rmconf->dpd_retry = $2;
1697 racoon_yyerror("DPD support not compiled in.");
1701 | DPD_MAXFAIL NUMBER
1704 cur_rmconf->dpd_maxfails = $2;
1706 racoon_yyerror("DPD support not compiled in.");
1710 | DPD_ALGORITHM dpd_algo_type
1713 cur_rmconf->dpd_algo = $2;
1715 racoon_yyerror("DPD support not compiled in.");
1719 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1721 cur_rmconf->idle_timeout = $3;
1722 cur_rmconf->idle_timeout_dir = $5;
1725 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1727 cur_rmconf->prhead->lifetime = $3 * $4;
1730 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1731 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1734 racoon_yyerror("byte lifetime support is deprecated in Phase 1");
1737 racoon_yywarn("the lifetime of bytes in phase 1 "
1738 "will be ignored at the moment.");
1739 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1740 if (cur_rmconf->prhead->lifebyte == 0)
1747 struct secprotospec *spspec;
1749 spspec = newspspec();
1752 insspspec(spspec, &cur_rmconf->prhead);
1754 BOC isakmpproposal_specs EOC
1758 | exchange_types EXCHANGETYPE
1761 new = racoon_malloc(sizeof(struct etypes));
1763 racoon_yyerror("failed to allocate etypes");
1768 if (cur_rmconf->etypes == NULL)
1769 cur_rmconf->etypes = new;
1772 for (p = cur_rmconf->etypes;
1781 : CERT_X509 IN_KEYCHAIN
1783 cur_rmconf->certtype = $1;
1784 cur_rmconf->identity_in_keychain = 1;
1785 cur_rmconf->keychainCertRef = NULL;
1789 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1791 cur_rmconf->certtype = $1;
1792 cur_rmconf->identity_in_keychain = 1;
1793 cur_rmconf->keychainCertRef = $3;
1800 $$ = algtype2doi(algclass_isakmp_dh, $1);
1802 racoon_yyerror("must be DH group");
1807 case OAKLEY_ATTR_GRP_DESC_MODP768:
1808 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1809 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1810 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1811 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1812 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1813 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1814 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1817 racoon_yyerror("Invalid DH group specified");
1824 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1825 $$ = num2dhgroup[$1];
1827 racoon_yyerror("must be DH group");
1833 case OAKLEY_ATTR_GRP_DESC_MODP768:
1834 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1835 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1836 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1837 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1838 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1839 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1840 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1843 racoon_yyerror("Invalid DH group specified");
1850 : /* nothing */ { $$ = NULL; }
1851 | ADDRSTRING { $$ = $1; }
1852 | QUOTEDSTRING { $$ = $1; }
1854 isakmpproposal_specs
1856 | isakmpproposal_specs isakmpproposal_spec
1861 racoon_yyerror("strength directive is obsoleted.");
1863 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1865 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
1868 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1871 racoon_yyerror("byte lifetime support is deprecated");
1874 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
1875 if (cur_rmconf->prhead->spspec->lifebyte == 0)
1880 | DH_GROUP dh_group_num
1882 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
1885 | GSS_ID QUOTEDSTRING
1887 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
1888 racoon_yyerror("wrong Vendor ID for gssapi_id");
1891 if (cur_rmconf->prhead->spspec->gssid != NULL)
1892 racoon_free(cur_rmconf->prhead->spspec->gssid);
1893 cur_rmconf->prhead->spspec->gssid =
1894 racoon_strdup($2->v);
1895 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
1898 | ALGORITHM_CLASS ALGORITHMTYPE keylength
1903 doi = algtype2doi($1, $2);
1905 racoon_yyerror("algorithm mismatched 1");
1911 case algclass_isakmp_enc:
1912 /* reject suppressed algorithms */
1913 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
1914 defklen = default_keylen($1, $2);
1917 racoon_yyerror("keylen not allowed");
1921 if ($3 && check_keylen($1, $2, $3) < 0) {
1922 racoon_yyerror("invalid keylen %d", $3);
1927 cur_rmconf->prhead->spspec->encklen = $3;
1929 cur_rmconf->prhead->spspec->encklen = defklen;
1931 case algclass_isakmp_hash:
1932 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
1934 case algclass_isakmp_ameth:
1935 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
1937 * We may have to set the Vendor ID for the
1938 * authentication method we're using.
1941 case algtype_gssapikrb:
1942 if (cur_rmconf->prhead->spspec->vendorid !=
1944 racoon_yyerror("Vendor ID mismatch "
1949 * For interoperability with Win2k,
1950 * we set the Vendor ID to "GSSAPI".
1952 cur_rmconf->prhead->spspec->vendorid =
1960 racoon_yyerror("algorithm mismatched 2");
1968 : UNITTYPE_SEC { $$ = 1; }
1969 | UNITTYPE_MIN { $$ = 60; }
1970 | UNITTYPE_HOUR { $$ = (60 * 60); }
1973 : UNITTYPE_BYTE { $$ = 1; }
1974 | UNITTYPE_KBYTES { $$ = 1024; }
1975 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
1976 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
1979 : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; }
1980 | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; }
1981 | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; }
1984 : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; }
1985 | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; }
1986 | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; }
1990 static struct proposalspec *
1993 struct proposalspec *new;
1995 new = racoon_calloc(1, sizeof(*new));
1997 racoon_yyerror("failed to allocate proposal");
2003 * insert into head of list.
2006 insprspec(prspec, head)
2007 struct proposalspec *prspec;
2008 struct proposalspec **head;
2011 (*head)->prev = prspec;
2012 prspec->next = *head;
2016 static struct secprotospec *
2019 struct secprotospec *new;
2021 new = racoon_calloc(1, sizeof(*new));
2023 racoon_yyerror("failed to allocate spproto");
2027 new->encklen = 0; /*XXX*/
2030 * Default to "uknown" vendor -- we will override this
2031 * as necessary. When we send a Vendor ID payload, an
2032 * "unknown" will be translated to a KAME/racoon ID.
2034 new->vendorid = VENDORID_UNKNOWN;
2040 * insert into head of list.
2043 insspspec(spspec, head)
2044 struct secprotospec *spspec;
2045 struct proposalspec **head;
2047 spspec->back = *head;
2049 if ((*head)->spspec != NULL)
2050 (*head)->spspec->prev = spspec;
2051 spspec->next = (*head)->spspec;
2052 (*head)->spspec = spspec;
2055 /* set final acceptable proposal */
2057 set_isakmp_proposal(rmconf, prspec)
2058 struct remoteconf *rmconf;
2059 struct proposalspec *prspec;
2061 struct proposalspec *p;
2062 struct secprotospec *s;
2065 int32_t types[MAXALGCLASS];
2070 "multiple proposal definition.\n");
2074 /* mandatory check */
2075 if (p->spspec == NULL) {
2076 racoon_yyerror("no remote specification found: %s.\n",
2077 saddr2str((struct sockaddr *)rmconf->remote));
2080 for (s = p->spspec; s != NULL; s = s->next) {
2081 /* XXX need more to check */
2082 if (s->algclass[algclass_isakmp_enc] == 0) {
2083 racoon_yyerror("encryption algorithm required.");
2086 if (s->algclass[algclass_isakmp_hash] == 0) {
2087 racoon_yyerror("hash algorithm required.");
2090 if (s->algclass[algclass_isakmp_dh] == 0) {
2091 racoon_yyerror("DH group required.");
2094 if (s->algclass[algclass_isakmp_ameth] == 0) {
2095 racoon_yyerror("authentication method required.");
2100 /* skip to last part */
2101 for (s = p->spspec; s->next != NULL; s = s->next)
2105 plog(ASL_LEVEL_DEBUG,
2106 "lifetime = %ld\n", (long)
2107 (s->lifetime ? s->lifetime : p->lifetime));
2108 plog(ASL_LEVEL_DEBUG,
2110 s->lifebyte ? s->lifebyte : p->lifebyte);
2111 plog(ASL_LEVEL_DEBUG,
2112 "encklen=%d\n", s->encklen);
2114 memset(types, 0, ARRAYLEN(types));
2115 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
2116 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
2117 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
2118 types[algclass_isakmp_ameth] =
2119 s->algclass[algclass_isakmp_ameth];
2121 /* expanding spspec */
2123 trns_no = expand_isakmpspec(prop_no, trns_no, types,
2124 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
2125 s->lifetime ? s->lifetime : p->lifetime,
2126 s->lifebyte ? s->lifebyte : p->lifebyte,
2127 s->encklen, s->vendorid, s->gssid,
2129 if (trns_no == -1) {
2131 "failed to expand isakmp proposal.\n");
2138 if (rmconf->proposal == NULL) {
2140 "no proposal found.\n");
2151 for (i = 0; i < MAXALGCLASS; i++)
2152 tmpalgtype[i] = 0; /* means algorithm undefined. */
2156 expand_isakmpspec(prop_no, trns_no, types,
2157 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
2159 int prop_no, trns_no;
2160 int *types, class, last;
2166 struct remoteconf *rmconf;
2168 struct isakmpsa *new;
2174 plog(ASL_LEVEL_DEBUG,
2175 "p:%d t:%d\n", prop_no, trns_no);
2176 for (j = class; j < MAXALGCLASS; j++) {
2177 snprintf(tb, sizeof(tb), "%d", types[j]);
2178 plog(ASL_LEVEL_DEBUG,
2180 s_algtype(j, types[j]),
2181 types[j] ? "(" : "",
2182 tb[0] == '0' ? "" : tb,
2183 types[j] ? ")" : "");
2185 plog(ASL_LEVEL_DEBUG, "\n");
2188 #define TMPALGTYPE2STR(n) \
2189 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
2190 /* check mandatory values */
2191 if (types[algclass_isakmp_enc] == 0
2192 || types[algclass_isakmp_ameth] == 0
2193 || types[algclass_isakmp_dh] == 0) {
2194 racoon_yyerror("few definition of algorithm "
2195 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2196 TMPALGTYPE2STR(enc),
2197 TMPALGTYPE2STR(ameth),
2198 TMPALGTYPE2STR(hash),
2199 TMPALGTYPE2STR(dh));
2202 #undef TMPALGTYPE2STR
2205 new = newisakmpsa();
2207 racoon_yyerror("failed to allocate isakmp sa");
2210 new->prop_no = prop_no;
2211 new->trns_no = trns_no++;
2212 new->lifetime = lifetime;
2213 new->lifebyte = lifebyte;
2214 new->enctype = types[algclass_isakmp_enc];
2215 new->encklen = encklen;
2216 new->authmethod = types[algclass_isakmp_ameth];
2217 new->hashtype = types[algclass_isakmp_hash];
2218 new->prf = types[algclass_isakmp_hash];
2219 new->dh_group = types[algclass_isakmp_dh];
2220 new->vendorid = vendorid;
2221 insisakmpsa(new, rmconf);
2227 listen_addr (struct sockaddr_storage *addr, int udp_encap)
2233 racoon_yyerror("failed to allocate myaddrs");
2237 if (p->addr == NULL) {
2238 racoon_yyerror("failed to copy sockaddr_storage ");
2242 p->udp_encap = udp_encap;
2243 /* These need to be initialized for Apple modifications
2244 * to open code for isakmp sockets
2249 insmyaddr(p, &lcconf->myaddrs);
2251 lcconf->autograbaddr = 0;
2258 * Must be more than 1024B because its unit is kilobytes.
2259 * That is defined RFC2407.
2266 racoon_yyerror("byte size should be more than 1024B.");
2279 plog(ASL_LEVEL_DEBUG, "===== parsing configuration\n");
2283 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2284 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2285 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2286 CONSTSTR("could not read configuration file"),
2287 CONSTSTR("cfparse: yycf_switch_buffer erred"));
2289 "could not read configuration file \"%s\"\n",
2290 lcconf->racoon_conf);
2298 "fatal parse failure (%d errors)\n",
2302 "fatal parse failure.\n");
2304 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2305 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2306 CONSTSTR("fatal parse failure"),
2307 CONSTSTR("cfparse: yyparse erred"));
2308 yycf_clean_buffer();
2312 if (error == 0 && yyerrorcount) {
2314 "parse error is nothing, but yyerrorcount is %d.\n",
2316 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2317 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2318 CONSTSTR("ambivalent error code"),
2319 CONSTSTR("cfparse: error == 0 && yerrorcount"));
2320 yycf_clean_buffer();
2324 yycf_clean_buffer();
2326 plog(ASL_LEVEL_DEBUG, "parse succeeded.\n");
2335 int ignore_estab_or_assert_handles = (sig == SIGUSR1);
2337 if (sig >= 0 && sig < NSIG) {
2338 plog(ASL_LEVEL_DEBUG, "==== Got %s signal - re-parsing configuration.\n", sys_signame[sig]);
2340 plog(ASL_LEVEL_ERR, "==== Got Unknown signal - re-parsing configuration.\n");
2341 IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"),
2342 IPSECCONFIGEVENTCODE_REPARSE_ERROR,
2343 CONSTSTR("Unknown signal"),
2344 CONSTSTR("cfreparse: triggered by unknown signal"));
2346 plog(ASL_LEVEL_DEBUG, "==== %s sessions.\n", ignore_estab_or_assert_handles? "flush negotiating" : "flush all");
2348 ike_session_flush_all_phase2(ignore_estab_or_assert_handles);
2349 ike_session_flush_all_phase1(ignore_estab_or_assert_handles);
2352 check_auto_exit(); /* check/change state of auto exit */