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
191 %token SHARED_SECRET SECRETTYPE
192 %token OPEN_DIR_AUTH_GROUP IN_KEYCHAIN
193 %token CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
194 %token DNSSEC CERT_X509 CERT_PLAINRSA
195 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
196 %token NAT_TRAVERSAL REMOTE_FORCE_LEVEL NAT_TRAVERSAL_LEVEL NAT_TRAVERSAL_MULTI_USER NAT_TRAVERSAL_KEEPALIVE
197 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
198 %token GENERATE_POLICY GENERATE_LEVEL SUPPORT_PROXY
200 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
201 %token GSS_ID GSS_ID_ENC GSS_ID_ENCTYPE
202 %token COMPLEX_BUNDLE
203 %token DPD DPD_DELAY DPD_RETRY DPD_MAXFAIL DPD_ALGORITHM
204 %token DISCONNECT_ON_IDLE IDLE_TIMEOUT IDLE_DIRECTION
205 %token XAUTH_LOGIN WEAK_PHASE1_CHECK
206 %token EAP_TYPE EAP_TYPES EAP_OPTIONS
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 EAP_TYPE
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 settting if aggressive mode or IKEv2. */
1409 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL
1415 for (p = cur_rmconf->proposal; p; p = p->next) {
1416 if (b == 0 || (b && b == p->dh_group)) {
1420 racoon_yyerror("DH group must be equal "
1422 "when aggressive mode is "
1426 cur_rmconf->dh_group = b;
1428 if (cur_rmconf->dh_group == 0) {
1429 racoon_yyerror("DH group must be set in the proposal.\n");
1433 /* DH group settting if PFS is required. */
1434 if (oakley_setdhgroup(cur_rmconf->dh_group,
1435 &cur_rmconf->dhgrp) < 0) {
1436 racoon_yyerror("failed to set DH value.\n");
1441 insrmconf(cur_rmconf);
1445 : ANONYMOUS ike_port
1448 struct remote_index_val *new;
1450 new = racoon_calloc(1, sizeof(*new));
1452 racoon_yyerror("failed to allocate remote index struct");
1455 new->addr = newsaddr(sizeof(struct sockaddr_storage));
1456 if (new->addr == NULL) {
1457 racoon_yyerror("failed to allocate sockaddr storage");
1461 new->addr->ss_family = AF_UNSPEC;
1462 (ALIGNED_CAST(struct sockaddr_in *)new->addr)->sin_port = htons($2);
1466 | ike_addrinfo_prefix_port
1470 racoon_yyerror("failed to allocate sockaddr_storage");
1477 | remote_specs remote_spec
1482 cur_rmconf->etypes = NULL;
1485 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1486 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1487 | IKE_VERSION NUMBER
1490 cur_rmconf->ike_version = ISAKMP_VERSION_NUMBER_IKEV1;
1492 racoon_yyerror("invalid IKE version specified.\n");
1496 | CERTIFICATE_TYPE cert_spec
1497 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1498 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1499 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1500 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1502 cur_rmconf->cert_verification = $2;
1504 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1506 cur_rmconf->cert_verification = $2;
1507 cur_rmconf->cert_verification_option = $3;
1510 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1513 cur_rmconf->open_dir_auth_group = $2;
1515 racoon_yyerror("Apple specific features not compiled in.");
1519 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1521 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1522 racoon_yyerror("failed to set identifer.\n");
1523 vfree($3); //%%% BUG FIX - memory leak
1526 vfree($3); //%%% BUG FIX - memory leak
1527 cur_rmconf->idvtype = $2;
1530 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1532 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1533 racoon_yyerror("failed to set identifer.\n");
1536 cur_rmconf->idvtype = $2;
1539 | XAUTH_LOGIN identifierstring
1541 #ifdef ENABLE_HYBRID
1542 /* formerly identifier type login */
1543 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1544 racoon_yyerror("failed to allocate xauth state\n");
1547 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1548 racoon_yyerror("failed to set identifer.\n");
1551 vfree($2); //%%% BUG FIX - memory leak
1553 racoon_yyerror("racoon not configured with --enable-hybrid");
1557 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1562 racoon_yyerror("failed to allocate idspec");
1565 if (set_identifier(&id->id, $2, $3) != 0) {
1566 racoon_yyerror("failed to set identifer.\n");
1568 vfree($3); //%%% BUG FIX - memory leak
1571 vfree($3); //%%% BUG FIX - memory leak
1573 genlist_append (cur_rmconf->idvl_p, id);
1576 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1581 racoon_yyerror("failed to allocate idspec");
1584 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1585 racoon_yyerror("failed to set identifer.\n");
1590 genlist_append (cur_rmconf->idvl_p, id);
1593 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1594 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1596 cur_rmconf->secrettype = $2;
1597 cur_rmconf->shared_secret = $3;
1599 | SHARED_SECRET SECRETTYPE
1601 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1602 racoon_yyerror("shared secret value missing.\n");
1605 cur_rmconf->secrettype = $2;
1607 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1610 racoon_yyerror("dh_group cannot be defined here.");
1614 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1615 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1616 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1618 #ifdef SADB_X_EXT_NAT_T_FRAG
1619 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1620 cur_rmconf->esp_frag = $2;
1622 racoon_yywarn("libipsec lacks IKE frag support");
1624 racoon_yywarn("Your kernel does not support esp_frag");
1627 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1628 | WEAK_PHASE1_CHECK SWITCH {
1629 cur_rmconf->weak_phase1_check = $2;
1631 | EAP_TYPES { cur_rmconf->eap_types = NULL; } eap_types EOS
1632 | EAP_OPTIONS QUOTEDSTRING {
1633 vchar_t *options_path = $2;
1634 cur_rmconf->eap_options = NULL;
1636 CFStringRef option_path_str = CFStringCreateWithCString(kCFAllocatorDefault, options_path->v, kCFStringEncodingASCII);
1637 if (option_path_str) {
1638 CFURLRef plist_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, option_path_str, kCFURLPOSIXPathStyle, false);
1640 CFReadStreamRef read_stream = CFReadStreamCreateWithFile(kCFAllocatorDefault, plist_url);
1642 CFReadStreamOpen (read_stream);
1643 cur_rmconf->eap_options = CFPropertyListCreateWithStream(kCFAllocatorDefault, read_stream, 0, kCFPropertyListImmutable, NULL, NULL);
1644 CFRelease (read_stream);
1646 CFRelease (plist_url);
1648 racoon_yywarn("eap_options must contain a path to a property list");
1650 CFRelease(option_path_str);
1652 racoon_yywarn("eap_options string could not be processed");
1654 vfree(options_path);
1657 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1658 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1659 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1660 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1661 | NAT_TRAVERSAL SWITCH
1664 cur_rmconf->nat_traversal = $2;
1666 racoon_yyerror("NAT-T support not compiled in.");
1669 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1672 cur_rmconf->nat_traversal = $2;
1674 racoon_yyerror("NAT-T support not compiled in.");
1677 | NAT_TRAVERSAL_MULTI_USER SWITCH
1680 cur_rmconf->natt_multiple_user = $2;
1682 racoon_yyerror("NAT-T support not compiled in.");
1685 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1688 cur_rmconf->natt_keepalive = $2;
1690 racoon_yyerror("NAT-T support not compiled in.");
1696 cur_rmconf->dpd = $2;
1698 racoon_yyerror("DPD support not compiled in.");
1704 cur_rmconf->dpd_interval = $2;
1706 racoon_yyerror("DPD support not compiled in.");
1713 cur_rmconf->dpd_retry = $2;
1715 racoon_yyerror("DPD support not compiled in.");
1719 | DPD_MAXFAIL NUMBER
1722 cur_rmconf->dpd_maxfails = $2;
1724 racoon_yyerror("DPD support not compiled in.");
1728 | DPD_ALGORITHM dpd_algo_type
1731 cur_rmconf->dpd_algo = $2;
1733 racoon_yyerror("DPD support not compiled in.");
1737 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1739 cur_rmconf->idle_timeout = $3;
1740 cur_rmconf->idle_timeout_dir = $5;
1743 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1745 cur_rmconf->prhead->lifetime = $3 * $4;
1748 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1749 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1752 racoon_yyerror("byte lifetime support is deprecated in Phase 1");
1755 racoon_yywarn("the lifetime of bytes in phase 1 "
1756 "will be ignored at the moment.");
1757 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1758 if (cur_rmconf->prhead->lifebyte == 0)
1765 struct secprotospec *spspec;
1767 spspec = newspspec();
1770 insspspec(spspec, &cur_rmconf->prhead);
1772 BOC isakmpproposal_specs EOC
1776 | exchange_types EXCHANGETYPE
1779 new = racoon_malloc(sizeof(struct etypes));
1781 racoon_yyerror("failed to allocate etypes");
1786 if (cur_rmconf->etypes == NULL)
1787 cur_rmconf->etypes = new;
1790 for (p = cur_rmconf->etypes;
1800 | eap_types EAP_TYPE
1802 struct etypes *new_eaps;
1803 new_eaps = racoon_malloc(sizeof(struct etypes));
1804 if (new_eaps == NULL) {
1805 racoon_yyerror("failed to allocate etypes");
1808 new_eaps->type = $2;
1809 new_eaps->next = NULL;
1810 if (cur_rmconf->eap_types == NULL)
1811 cur_rmconf->eap_types = new_eaps;
1814 for (p = cur_rmconf->eap_types;
1823 : CERT_X509 IN_KEYCHAIN
1825 cur_rmconf->certtype = $1;
1826 cur_rmconf->identity_in_keychain = 1;
1827 cur_rmconf->keychainCertRef = NULL;
1831 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1833 cur_rmconf->certtype = $1;
1834 cur_rmconf->identity_in_keychain = 1;
1835 cur_rmconf->keychainCertRef = $3;
1842 $$ = algtype2doi(algclass_isakmp_dh, $1);
1844 racoon_yyerror("must be DH group");
1849 case OAKLEY_ATTR_GRP_DESC_MODP768:
1850 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1851 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1852 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1853 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1854 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1855 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1856 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1859 racoon_yyerror("Invalid DH group specified");
1866 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1867 $$ = num2dhgroup[$1];
1869 racoon_yyerror("must be DH group");
1875 case OAKLEY_ATTR_GRP_DESC_MODP768:
1876 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1877 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1878 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1879 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1880 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1881 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1882 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1885 racoon_yyerror("Invalid DH group specified");
1892 : /* nothing */ { $$ = NULL; }
1893 | ADDRSTRING { $$ = $1; }
1894 | QUOTEDSTRING { $$ = $1; }
1896 isakmpproposal_specs
1898 | isakmpproposal_specs isakmpproposal_spec
1903 racoon_yyerror("strength directive is obsoleted.");
1905 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1907 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
1910 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1913 racoon_yyerror("byte lifetime support is deprecated");
1916 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
1917 if (cur_rmconf->prhead->spspec->lifebyte == 0)
1922 | DH_GROUP dh_group_num
1924 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
1927 | GSS_ID QUOTEDSTRING
1929 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
1930 racoon_yyerror("wrong Vendor ID for gssapi_id");
1933 if (cur_rmconf->prhead->spspec->gssid != NULL)
1934 racoon_free(cur_rmconf->prhead->spspec->gssid);
1935 cur_rmconf->prhead->spspec->gssid =
1936 racoon_strdup($2->v);
1937 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
1940 | ALGORITHM_CLASS ALGORITHMTYPE keylength
1945 doi = algtype2doi($1, $2);
1947 racoon_yyerror("algorithm mismatched 1");
1953 case algclass_isakmp_enc:
1954 /* reject suppressed algorithms */
1955 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
1956 defklen = default_keylen($1, $2);
1959 racoon_yyerror("keylen not allowed");
1963 if ($3 && check_keylen($1, $2, $3) < 0) {
1964 racoon_yyerror("invalid keylen %d", $3);
1969 cur_rmconf->prhead->spspec->encklen = $3;
1971 cur_rmconf->prhead->spspec->encklen = defklen;
1973 case algclass_isakmp_hash:
1974 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
1976 case algclass_isakmp_ameth:
1977 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
1979 * We may have to set the Vendor ID for the
1980 * authentication method we're using.
1983 case algtype_gssapikrb:
1984 if (cur_rmconf->prhead->spspec->vendorid !=
1986 racoon_yyerror("Vendor ID mismatch "
1991 * For interoperability with Win2k,
1992 * we set the Vendor ID to "GSSAPI".
1994 cur_rmconf->prhead->spspec->vendorid =
2002 racoon_yyerror("algorithm mismatched 2");
2010 : UNITTYPE_SEC { $$ = 1; }
2011 | UNITTYPE_MIN { $$ = 60; }
2012 | UNITTYPE_HOUR { $$ = (60 * 60); }
2015 : UNITTYPE_BYTE { $$ = 1; }
2016 | UNITTYPE_KBYTES { $$ = 1024; }
2017 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
2018 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
2021 : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; }
2022 | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; }
2023 | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; }
2026 : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; }
2027 | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; }
2028 | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; }
2032 static struct proposalspec *
2035 struct proposalspec *new;
2037 new = racoon_calloc(1, sizeof(*new));
2039 racoon_yyerror("failed to allocate proposal");
2045 * insert into head of list.
2048 insprspec(prspec, head)
2049 struct proposalspec *prspec;
2050 struct proposalspec **head;
2053 (*head)->prev = prspec;
2054 prspec->next = *head;
2058 static struct secprotospec *
2061 struct secprotospec *new;
2063 new = racoon_calloc(1, sizeof(*new));
2065 racoon_yyerror("failed to allocate spproto");
2069 new->encklen = 0; /*XXX*/
2072 * Default to "uknown" vendor -- we will override this
2073 * as necessary. When we send a Vendor ID payload, an
2074 * "unknown" will be translated to a KAME/racoon ID.
2076 new->vendorid = VENDORID_UNKNOWN;
2082 * insert into head of list.
2085 insspspec(spspec, head)
2086 struct secprotospec *spspec;
2087 struct proposalspec **head;
2089 spspec->back = *head;
2091 if ((*head)->spspec != NULL)
2092 (*head)->spspec->prev = spspec;
2093 spspec->next = (*head)->spspec;
2094 (*head)->spspec = spspec;
2097 /* set final acceptable proposal */
2099 set_isakmp_proposal(rmconf, prspec)
2100 struct remoteconf *rmconf;
2101 struct proposalspec *prspec;
2103 struct proposalspec *p;
2104 struct secprotospec *s;
2107 int32_t types[MAXALGCLASS];
2112 "multiple proposal definition.\n");
2116 /* mandatory check */
2117 if (p->spspec == NULL) {
2118 racoon_yyerror("no remote specification found: %s.\n",
2119 saddr2str((struct sockaddr *)rmconf->remote));
2122 for (s = p->spspec; s != NULL; s = s->next) {
2123 /* XXX need more to check */
2124 if (s->algclass[algclass_isakmp_enc] == 0) {
2125 racoon_yyerror("encryption algorithm required.");
2128 if (s->algclass[algclass_isakmp_hash] == 0) {
2129 racoon_yyerror("hash algorithm required.");
2132 if (s->algclass[algclass_isakmp_dh] == 0) {
2133 racoon_yyerror("DH group required.");
2136 if (s->algclass[algclass_isakmp_ameth] == 0) {
2137 racoon_yyerror("authentication method required.");
2142 /* skip to last part */
2143 for (s = p->spspec; s->next != NULL; s = s->next)
2147 plog(ASL_LEVEL_DEBUG,
2148 "lifetime = %ld\n", (long)
2149 (s->lifetime ? s->lifetime : p->lifetime));
2150 plog(ASL_LEVEL_DEBUG,
2152 s->lifebyte ? s->lifebyte : p->lifebyte);
2153 plog(ASL_LEVEL_DEBUG,
2154 "encklen=%d\n", s->encklen);
2156 memset(types, 0, ARRAYLEN(types));
2157 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
2158 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
2159 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
2160 types[algclass_isakmp_ameth] =
2161 s->algclass[algclass_isakmp_ameth];
2163 /* expanding spspec */
2165 trns_no = expand_isakmpspec(prop_no, trns_no, types,
2166 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
2167 s->lifetime ? s->lifetime : p->lifetime,
2168 s->lifebyte ? s->lifebyte : p->lifebyte,
2169 s->encklen, s->vendorid, s->gssid,
2171 if (trns_no == -1) {
2173 "failed to expand isakmp proposal.\n");
2180 if (rmconf->proposal == NULL) {
2182 "no proposal found.\n");
2193 for (i = 0; i < MAXALGCLASS; i++)
2194 tmpalgtype[i] = 0; /* means algorithm undefined. */
2198 expand_isakmpspec(prop_no, trns_no, types,
2199 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
2201 int prop_no, trns_no;
2202 int *types, class, last;
2208 struct remoteconf *rmconf;
2210 struct isakmpsa *new;
2216 plog(ASL_LEVEL_DEBUG,
2217 "p:%d t:%d\n", prop_no, trns_no);
2218 for (j = class; j < MAXALGCLASS; j++) {
2219 snprintf(tb, sizeof(tb), "%d", types[j]);
2220 plog(ASL_LEVEL_DEBUG,
2222 s_algtype(j, types[j]),
2223 types[j] ? "(" : "",
2224 tb[0] == '0' ? "" : tb,
2225 types[j] ? ")" : "");
2227 plog(ASL_LEVEL_DEBUG, "\n");
2230 #define TMPALGTYPE2STR(n) \
2231 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
2232 /* check mandatory values */
2233 if (types[algclass_isakmp_enc] == 0
2234 || types[algclass_isakmp_ameth] == 0
2235 || types[algclass_isakmp_dh] == 0) {
2236 racoon_yyerror("few definition of algorithm "
2237 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2238 TMPALGTYPE2STR(enc),
2239 TMPALGTYPE2STR(ameth),
2240 TMPALGTYPE2STR(hash),
2241 TMPALGTYPE2STR(dh));
2244 #undef TMPALGTYPE2STR
2247 new = newisakmpsa();
2249 racoon_yyerror("failed to allocate isakmp sa");
2252 new->prop_no = prop_no;
2253 new->trns_no = trns_no++;
2254 new->lifetime = lifetime;
2255 new->lifebyte = lifebyte;
2256 new->enctype = types[algclass_isakmp_enc];
2257 new->encklen = encklen;
2258 new->authmethod = types[algclass_isakmp_ameth];
2259 new->hashtype = types[algclass_isakmp_hash];
2260 new->prf = types[algclass_isakmp_hash];
2261 new->dh_group = types[algclass_isakmp_dh];
2262 new->vendorid = vendorid;
2263 insisakmpsa(new, rmconf);
2269 listen_addr (struct sockaddr_storage *addr, int udp_encap)
2275 racoon_yyerror("failed to allocate myaddrs");
2279 if (p->addr == NULL) {
2280 racoon_yyerror("failed to copy sockaddr_storage ");
2284 p->udp_encap = udp_encap;
2285 /* These need to be initialized for Apple modifications
2286 * to open code for isakmp sockets
2291 insmyaddr(p, &lcconf->myaddrs);
2293 lcconf->autograbaddr = 0;
2300 * Must be more than 1024B because its unit is kilobytes.
2301 * That is defined RFC2407.
2308 racoon_yyerror("byte size should be more than 1024B.");
2321 plog(ASL_LEVEL_DEBUG, "===== parsing configuration\n");
2325 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2326 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2327 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2328 CONSTSTR("could not read configuration file"),
2329 CONSTSTR("cfparse: yycf_switch_buffer erred"));
2331 "could not read configuration file \"%s\"\n",
2332 lcconf->racoon_conf);
2340 "fatal parse failure (%d errors)\n",
2344 "fatal parse failure.\n");
2346 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2347 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2348 CONSTSTR("fatal parse failure"),
2349 CONSTSTR("cfparse: yyparse erred"));
2350 yycf_clean_buffer();
2354 if (error == 0 && yyerrorcount) {
2356 "parse error is nothing, but yyerrorcount is %d.\n",
2358 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2359 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2360 CONSTSTR("ambivalent error code"),
2361 CONSTSTR("cfparse: error == 0 && yerrorcount"));
2362 yycf_clean_buffer();
2366 yycf_clean_buffer();
2368 plog(ASL_LEVEL_DEBUG, "parse succeeded.\n");
2377 int ignore_estab_or_assert_handles = (sig == SIGUSR1);
2379 if (sig >= 0 && sig < NSIG) {
2380 plog(ASL_LEVEL_DEBUG, "==== Got %s signal - re-parsing configuration.\n", sys_signame[sig]);
2382 plog(ASL_LEVEL_ERR, "==== Got Unknown signal - re-parsing configuration.\n");
2383 IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"),
2384 IPSECCONFIGEVENTCODE_REPARSE_ERROR,
2385 CONSTSTR("Unknown signal"),
2386 CONSTSTR("cfreparse: triggered by unknown signal"));
2388 plog(ASL_LEVEL_DEBUG, "==== %s sessions.\n", ignore_estab_or_assert_handles? "flush negotiating" : "flush all");
2390 ike_session_flush_all_phase2(ignore_estab_or_assert_handles);
2391 ike_session_flush_all_phase1(ignore_estab_or_assert_handles);
2394 check_auto_exit(); /* check/change state of auto exit */