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"
96 #include "ipsecConfigTracer.h"
97 #include "ipsecMessageTracer.h"
99 static int num2dhgroup[] = {
101 OAKLEY_ATTR_GRP_DESC_MODP768,
102 OAKLEY_ATTR_GRP_DESC_MODP1024,
103 OAKLEY_ATTR_GRP_DESC_EC2N155,
104 OAKLEY_ATTR_GRP_DESC_EC2N185,
105 OAKLEY_ATTR_GRP_DESC_MODP1536,
114 OAKLEY_ATTR_GRP_DESC_MODP2048,
115 OAKLEY_ATTR_GRP_DESC_MODP3072,
116 OAKLEY_ATTR_GRP_DESC_MODP4096,
117 OAKLEY_ATTR_GRP_DESC_MODP6144,
118 OAKLEY_ATTR_GRP_DESC_MODP8192
121 struct remote_index_val {
123 struct sockaddr_storage *addr;
126 static struct remoteconf *cur_rmconf;
127 static int tmpalgtype[MAXALGCLASS];
128 static struct sainfo *cur_sainfo;
129 static int cur_algclass;
131 static struct proposalspec *newprspec (void);
132 static void insprspec (struct proposalspec *, struct proposalspec **);
133 static struct secprotospec *newspspec (void);
134 static void insspspec (struct secprotospec *, struct proposalspec **);
136 static int set_isakmp_proposal (struct remoteconf *, struct proposalspec *);
137 static void clean_tmpalgtype (void);
138 static int expand_isakmpspec (int, int, int *,
139 int, int, time_t, int, int, int, char *, struct remoteconf *);
140 static int listen_addr (struct sockaddr_storage *addr, int udp_encap);
142 void freeetypes (struct etypes **etypes);
145 static int fix_lifebyte (u_long);
152 struct remoteconf *rmconf;
153 struct sockaddr_storage *saddr;
154 struct sainfoalg *alg;
155 struct remote_index_val *rmidx;
162 /* self information */
163 %token IDENTIFIER VENDORID
165 %token LOGGING LOGLEV
167 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
169 %token LISTEN X_ISAKMP X_ISAKMP_NATT X_ADMIN STRICT_ADDRESS ADMINSOCK DISABLED
171 %token MODECFG CFG_NET4 CFG_MASK4 CFG_DNS4 CFG_NBNS4 CFG_DEFAULT_DOMAIN
172 %token CFG_AUTH_SOURCE CFG_AUTH_GROUPS CFG_SYSTEM CFG_RADIUS CFG_PAM CFG_LDAP CFG_LOCAL CFG_NONE
173 %token CFG_GROUP_SOURCE CFG_ACCOUNTING CFG_CONF_SOURCE CFG_MOTD CFG_POOL_SIZE CFG_AUTH_THROTTLE
174 %token CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL CFG_SPLIT_INCLUDE CFG_SPLIT_DNS
175 %token CFG_PFS_GROUP CFG_SAVE_PASSWD
177 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
178 %token RETRY_PHASE1 RETRY_PHASE2 NATT_KA AUTO_EXIT_DELAY
180 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
182 %token SAINFO FROM GROUP
184 %token REMOTE ANONYMOUS INHERIT
185 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
186 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE CA_TYPE
187 %token VERIFY_CERT SEND_CERT SEND_CR
188 %token IDENTIFIERTYPE IDENTIFIERQUAL MY_IDENTIFIER
189 %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
207 %token PREFIX PORT PORTANY UL_PROTO ANY IKE_FRAG ESP_FRAG MODE_CFG
208 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH REMOTEID
210 %token NUMBER SWITCH BOOLEAN
211 %token HEXSTRING QUOTEDSTRING ADDRSTRING ADDRRANGE
212 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
213 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
214 %token EOS BOC EOC COMMA
215 %token DPD_ALGO_TYPE_DEFAULT DPD_ALGO_TYPE_INBOUND DPD_ALGO_TYPE_BLACKHOLE
216 %token IDLE_DIRECTION_IN IDLE_DIRECTION_OUT IDLE_DIRECTION_ANY IKE_VERSION
218 %type <num> NUMBER BOOLEAN SWITCH keylength
219 %type <num> PATHTYPE IDENTIFIERTYPE IDENTIFIERQUAL LOGLEV GSS_ID_ENCTYPE
220 %type <num> SECRETTYPE
221 %type <num> ALGORITHM_CLASS dh_group_num
222 %type <num> ALGORITHMTYPE STRENGTHTYPE
223 %type <num> PREFIX prefix PORT port ike_port
224 %type <num> ul_proto UL_PROTO
225 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
226 %type <num> CERTTYPE CERT_X509 CERT_PLAINRSA PROPOSAL_CHECK_LEVEL NAT_TRAVERSAL_LEVEL GENERATE_LEVEL
227 %type <num> VERIFICATION_MODULE VERIFICATION_OPTION
228 %type <num> unittype_time unittype_byte
229 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING ADDRRANGE sainfo_id
230 %type <val> identifierstring
231 %type <saddr> ike_addrinfo_port
232 %type <alg> algorithm
233 %type <num> dpd_algo_type
234 %type <num> idle_dir_type
235 %type <rmidx> remote_index ike_addrinfo_prefix_port
241 | statements statement
246 | identifier_statement
259 : PATH PATHTYPE QUOTEDSTRING
261 if ($2 >= LC_PATHTYPE_MAX) {
262 racoon_yyerror("invalid path type %d", $2);
266 /* free old pathinfo */
267 if (lcconf->pathinfo[$2])
268 racoon_free(lcconf->pathinfo[$2]);
270 /* set new pathinfo */
271 lcconf->pathinfo[$2] = racoon_strdup($3->v);
272 STRDUP_FATAL(lcconf->pathinfo[$2]);
280 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
285 : INCLUDE QUOTEDSTRING EOS
287 char path[MAXPATHLEN];
289 getpathname(path, sizeof(path),
290 LC_PATHTYPE_INCLUDE, $2->v);
292 if (yycf_switch_buffer(path) != 0)
297 /* self information */
299 : IDENTIFIER identifier_stmt
304 /*XXX to be deleted */
307 | IDENTIFIERTYPE QUOTEDSTRING
309 /*XXX to be deleted */
310 $2->l--; /* nuke '\0' */
311 lcconf->ident[$1] = $2;
312 if (lcconf->ident[$1] == NULL) {
313 racoon_yyerror("failed to set my ident: %s",
323 : LOGGING log_level EOS
329 * XXX ignore it because this specification
332 plogsetlevelquotedstr($1->v);
343 : PADDING BOC padding_stmts EOC
347 | padding_stmts padding_stmt
350 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
351 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
352 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
353 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
354 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
359 : LISTEN BOC listen_stmts EOC
363 | listen_stmts listen_stmt
366 : X_ISAKMP ike_addrinfo_port
371 | X_ISAKMP_NATT ike_addrinfo_port
376 racoon_yyerror("NAT-T support not compiled in.");
382 racoon_yyerror("admin directive is obsoleted.");
385 | ADMINSOCK QUOTEDSTRING QUOTEDSTRING QUOTEDSTRING NUMBER
387 racoon_yywarn("admin port support not compiled in");
390 | ADMINSOCK QUOTEDSTRING
392 racoon_yywarn("admin port support not compiled in");
397 racoon_yywarn("admin port support not compiled in");
400 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
403 : ADDRSTRING ike_port
407 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
408 $$ = str2saddr($1->v, portbuf);
414 ike_addrinfo_prefix_port
415 : ADDRSTRING prefix ike_port
418 struct remote_index_val *new;
420 new = racoon_calloc(1, sizeof(*new));
422 racoon_yyerror("failed to allocate remote index struct");
426 snprintf(portbuf, sizeof(portbuf), "%ld", $3);
427 new->addr = str2saddr($1->v, portbuf);
430 racoon_yyerror("failed to allocate sockaddr storage");
438 : /* nothing */ { $$ = PORT_ISAKMP; }
443 : MODECFG BOC modecfg_stmts EOC
447 | modecfg_stmts modecfg_stmt
450 : CFG_NET4 ADDRSTRING
453 if (inet_pton(AF_INET, $2->v,
454 &isakmp_cfg_config.network4) != 1)
455 racoon_yyerror("bad IPv4 network address.");
458 racoon_yyerror("racoon not configured with --enable-hybrid");
462 | CFG_MASK4 ADDRSTRING
465 if (inet_pton(AF_INET, $2->v,
466 &isakmp_cfg_config.netmask4) != 1)
467 racoon_yyerror("bad IPv4 netmask address.");
470 racoon_yyerror("racoon not configured with --enable-hybrid");
474 | CFG_DNS4 addrdnslist
476 | CFG_NBNS4 addrwinslist
478 | CFG_SPLIT_NETWORK CFG_SPLIT_LOCAL splitnetlist
481 isakmp_cfg_config.splitnet_type = UNITY_LOCAL_LAN;
483 racoon_yyerror("racoon not configured with --enable-hybrid");
487 | CFG_SPLIT_NETWORK CFG_SPLIT_INCLUDE splitnetlist
490 isakmp_cfg_config.splitnet_type = UNITY_SPLIT_INCLUDE;
492 racoon_yyerror("racoon not configured with --enable-hybrid");
496 | CFG_SPLIT_DNS splitdnslist
498 #ifndef ENABLE_HYBRID
499 racoon_yyerror("racoon not configured with --enable-hybrid");
503 | CFG_DEFAULT_DOMAIN QUOTEDSTRING
506 strlcpy(&isakmp_cfg_config.default_domain[0],
507 $2->v, sizeof(isakmp_cfg_config.default_domain));
510 racoon_yyerror("racoon not configured with --enable-hybrid");
514 | CFG_AUTH_SOURCE CFG_SYSTEM
517 isakmp_cfg_config.authsource = ISAKMP_CFG_AUTH_SYSTEM;
519 racoon_yyerror("racoon not configured with --enable-hybrid");
523 | CFG_AUTH_SOURCE CFG_RADIUS
526 racoon_yyerror("racoon not configured with --with-libradius");
527 #else /* ENABLE_HYBRID */
528 racoon_yyerror("racoon not configured with --enable-hybrid");
529 #endif /* ENABLE_HYBRID */
532 | CFG_AUTH_SOURCE CFG_PAM
535 racoon_yyerror("racoon not configured with --with-libpam");
536 #else /* ENABLE_HYBRID */
537 racoon_yyerror("racoon not configured with --enable-hybrid");
538 #endif /* ENABLE_HYBRID */
541 | CFG_AUTH_SOURCE CFG_LDAP
544 racoon_yyerror("racoon not configured with --with-libldap");
545 #else /* ENABLE_HYBRID */
546 racoon_yyerror("racoon not configured with --enable-hybrid");
547 #endif /* ENABLE_HYBRID */
550 | CFG_AUTH_GROUPS authgrouplist
552 #ifndef ENABLE_HYBRID
553 racoon_yyerror("racoon not configured with --enable-hybrid");
557 | CFG_GROUP_SOURCE CFG_SYSTEM
560 isakmp_cfg_config.groupsource = ISAKMP_CFG_GROUP_SYSTEM;
562 racoon_yyerror("racoon not configured with --enable-hybrid");
566 | CFG_GROUP_SOURCE CFG_LDAP
569 racoon_yyerror("racoon not configured with --with-libldap");
570 #else /* ENABLE_HYBRID */
571 racoon_yyerror("racoon not configured with --enable-hybrid");
572 #endif /* ENABLE_HYBRID */
575 | CFG_ACCOUNTING CFG_NONE
578 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_NONE;
580 racoon_yyerror("racoon not configured with --enable-hybrid");
584 | CFG_ACCOUNTING CFG_SYSTEM
587 isakmp_cfg_config.accounting = ISAKMP_CFG_ACCT_SYSTEM;
589 racoon_yyerror("racoon not configured with --enable-hybrid");
593 | CFG_ACCOUNTING CFG_RADIUS
596 racoon_yyerror("racoon not configured with --with-libradius");
597 #else /* ENABLE_HYBRID */
598 racoon_yyerror("racoon not configured with --enable-hybrid");
599 #endif /* ENABLE_HYBRID */
602 | CFG_ACCOUNTING CFG_PAM
605 racoon_yyerror("racoon not configured with --with-libpam");
606 #else /* ENABLE_HYBRID */
607 racoon_yyerror("racoon not configured with --enable-hybrid");
608 #endif /* ENABLE_HYBRID */
611 | CFG_POOL_SIZE NUMBER
614 if (isakmp_cfg_resize_pool($2) != 0)
615 racoon_yyerror("cannot allocate memory for pool");
616 #else /* ENABLE_HYBRID */
617 racoon_yyerror("racoon not configured with --enable-hybrid");
618 #endif /* ENABLE_HYBRID */
621 | CFG_PFS_GROUP NUMBER
624 isakmp_cfg_config.pfs_group = $2;
625 switch (isakmp_cfg_config.pfs_group)
627 case OAKLEY_ATTR_GRP_DESC_MODP768:
628 case OAKLEY_ATTR_GRP_DESC_MODP1024:
629 case OAKLEY_ATTR_GRP_DESC_MODP1536:
630 case OAKLEY_ATTR_GRP_DESC_MODP2048:
631 case OAKLEY_ATTR_GRP_DESC_MODP3072:
632 case OAKLEY_ATTR_GRP_DESC_MODP4096:
633 case OAKLEY_ATTR_GRP_DESC_MODP6144:
634 case OAKLEY_ATTR_GRP_DESC_MODP8192:
637 racoon_yyerror("Invalid PFS group specified");
641 #else /* ENABLE_HYBRID */
642 racoon_yyerror("racoon not configured with --enable-hybrid");
643 #endif /* ENABLE_HYBRID */
646 | CFG_SAVE_PASSWD SWITCH
649 isakmp_cfg_config.save_passwd = $2;
650 #else /* ENABLE_HYBRID */
651 racoon_yyerror("racoon not configured with --enable-hybrid");
652 #endif /* ENABLE_HYBRID */
655 | CFG_AUTH_THROTTLE NUMBER
658 isakmp_cfg_config.auth_throttle = $2;
659 #else /* ENABLE_HYBRID */
660 racoon_yyerror("racoon not configured with --enable-hybrid");
661 #endif /* ENABLE_HYBRID */
664 | CFG_CONF_SOURCE CFG_LOCAL
667 isakmp_cfg_config.confsource = ISAKMP_CFG_CONF_LOCAL;
668 #else /* ENABLE_HYBRID */
669 racoon_yyerror("racoon not configured with --enable-hybrid");
670 #endif /* ENABLE_HYBRID */
673 | CFG_CONF_SOURCE CFG_RADIUS
676 racoon_yyerror("racoon not configured with --with-libradius");
677 #else /* ENABLE_HYBRID */
678 racoon_yyerror("racoon not configured with --enable-hybrid");
679 #endif /* ENABLE_HYBRID */
682 | CFG_CONF_SOURCE CFG_LDAP
685 racoon_yyerror("racoon not configured with --with-libldap");
686 #else /* ENABLE_HYBRID */
687 racoon_yyerror("racoon not configured with --enable-hybrid");
688 #endif /* ENABLE_HYBRID */
691 | CFG_MOTD QUOTEDSTRING
694 strlcpy(&isakmp_cfg_config.motd[0], $2->v, sizeof(isakmp_cfg_config.motd));
697 racoon_yyerror("racoon not configured with --enable-hybrid");
705 | addrdns COMMA addrdnslist
711 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
713 if (icc->dns4_index >= MAXNS) {
714 racoon_yyerror("No more than %d DNS", MAXNS);
717 if (inet_pton(AF_INET, $1->v,
718 &icc->dns4[icc->dns4_index++]) != 1)
719 racoon_yyerror("bad IPv4 DNS address.");
723 racoon_yyerror("racoon not configured with --enable-hybrid");
730 | addrwins COMMA addrwinslist
736 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
738 if (icc->nbns4_index > MAXWINS) {
739 racoon_yyerror("No more than %d WINS", MAXWINS);
742 if (inet_pton(AF_INET, $1->v,
743 &icc->nbns4[icc->nbns4_index++]) != 1)
744 racoon_yyerror("bad IPv4 WINS address.");
748 racoon_yyerror("racoon not configured with --enable-hybrid");
755 | splitnetlist COMMA splitnet
761 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
762 struct unity_network network;
764 if (inet_pton(AF_INET, $1->v, &network.addr4) != 1)
765 racoon_yyerror("bad IPv4 SPLIT address.");
767 /* Turn $2 (the prefix) into a subnet mask */
768 network.mask4.s_addr = ($2) ? htonl(~((1 << (32 - $2)) - 1)) : 0;
770 /* add the network to our list */
771 if (splitnet_list_add(&icc->splitnet_list, &network,&icc->splitnet_count))
772 racoon_yyerror("Unable to allocate split network");
776 racoon_yyerror("racoon not configured with --enable-hybrid");
783 | authgroup COMMA authgrouplist
789 char * groupname = NULL;
790 char ** grouplist = NULL;
791 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
793 grouplist = racoon_realloc(icc->grouplist,
794 sizeof(char**)*(icc->groupcount+1));
795 if (grouplist == NULL)
796 racoon_yyerror("unable to allocate auth group list");
798 groupname = racoon_malloc($1->l+1);
799 if (groupname == NULL)
800 racoon_yyerror("unable to allocate auth group name");
802 memcpy(groupname,$1->v,$1->l);
804 grouplist[icc->groupcount]=groupname;
805 icc->grouplist = grouplist;
810 racoon_yyerror("racoon not configured with --enable-hybrid");
817 | splitdns COMMA splitdnslist
823 struct isakmp_cfg_config *icc = &isakmp_cfg_config;
825 if (!icc->splitdns_len)
827 icc->splitdns_list = racoon_malloc($1->l);
828 if(icc->splitdns_list == NULL)
829 racoon_yyerror("error allocating splitdns list buffer");
830 memcpy(icc->splitdns_list,$1->v,$1->l);
831 icc->splitdns_len = $1->l;
835 int len = icc->splitdns_len + $1->l + 1;
836 icc->splitdns_list = racoon_realloc(icc->splitdns_list,len);
837 if(icc->splitdns_list == NULL)
838 racoon_yyerror("error allocating splitdns list buffer");
839 icc->splitdns_list[icc->splitdns_len] = ',';
840 memcpy(icc->splitdns_list + icc->splitdns_len + 1, $1->v, $1->l);
841 icc->splitdns_len = len;
845 racoon_yyerror("racoon not configured with --enable-hybrid");
853 : RETRY BOC timer_stmts EOC
857 | timer_stmts timer_stmt
860 : RETRY_COUNTER NUMBER
862 lcconf->retry_counter = $2;
865 | RETRY_INTERVAL NUMBER unittype_time
867 lcconf->retry_interval = $2 * $3;
870 | RETRY_PERSEND NUMBER
872 lcconf->count_persend = $2;
875 | RETRY_PHASE1 NUMBER unittype_time
877 lcconf->retry_checkph1 = $2 * $3;
880 | RETRY_PHASE2 NUMBER unittype_time
882 lcconf->wait_ph2complete = $2 * $3;
885 | AUTO_EXIT_DELAY NUMBER unittype_time
887 lcconf->auto_exit_delay = $2 * $3;
888 lcconf->auto_exit_state |= LC_AUTOEXITSTATE_SET;
892 | NATT_KA NUMBER unittype_time
895 lcconf->natt_ka_interval = $2 * $3;
897 racoon_yyerror("NAT-T support not compiled in.");
907 cur_sainfo = create_sainfo();
908 if (cur_sainfo == NULL) {
909 racoon_yyerror("failed to allocate sainfo");
913 sainfo_name sainfo_param BOC sainfo_specs
915 struct sainfo *check;
918 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
919 racoon_yyerror("no encryption algorithm at %s",
920 sainfo2str(cur_sainfo));
923 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
924 racoon_yyerror("no authentication algorithm at %s",
925 sainfo2str(cur_sainfo));
928 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
929 racoon_yyerror("no compression algorithm at %s",
930 sainfo2str(cur_sainfo));
934 /* duplicate check */
935 check = getsainfo(cur_sainfo->idsrc,
937 cur_sainfo->id_i, 0);
938 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
939 racoon_yyerror("duplicated sainfo: %s",
940 sainfo2str(cur_sainfo));
943 inssainfo(cur_sainfo);
950 cur_sainfo->idsrc = NULL;
951 cur_sainfo->iddst = NULL;
953 | ANONYMOUS sainfo_id
955 cur_sainfo->idsrc = NULL;
956 cur_sainfo->iddst = $2;
958 | sainfo_id ANONYMOUS
960 cur_sainfo->idsrc = $1;
961 cur_sainfo->iddst = NULL;
963 | sainfo_id sainfo_id
965 cur_sainfo->idsrc = $1;
966 cur_sainfo->iddst = $2;
970 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
973 struct sockaddr_storage *saddr;
975 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
976 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
977 racoon_yyerror("port number must be \"any\".");
981 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
982 saddr = str2saddr($2->v, portbuf);
987 switch (saddr->ss_family) {
989 if ($5 == IPPROTO_ICMPV6) {
990 racoon_yyerror("upper layer protocol mismatched.\n");
994 $$ = ipsecdoi_sockaddr2id(saddr,
995 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
1000 if ($5 == IPPROTO_ICMP) {
1001 racoon_yyerror("upper layer protocol mismatched.\n");
1005 $$ = ipsecdoi_sockaddr2id(saddr,
1006 $3 == ~0 ? (sizeof(struct in6_addr) << 3): $3,
1011 racoon_yyerror("invalid family: %d", saddr->ss_family);
1019 | IDENTIFIERTYPE ADDRSTRING ADDRRANGE prefix port ul_proto
1022 struct sockaddr_storage *laddr = NULL, *haddr = NULL;
1024 if (($6 == IPPROTO_ICMP || $6 == IPPROTO_ICMPV6)
1025 && ($5 != IPSEC_PORT_ANY || $5 != IPSEC_PORT_ANY)) {
1026 racoon_yyerror("port number must be \"any\".");
1030 snprintf(portbuf, sizeof(portbuf), "%lu", $5);
1032 laddr = str2saddr($2->v, portbuf);
1033 if (laddr == NULL) {
1037 haddr = str2saddr($3->v, portbuf);
1038 if (haddr == NULL) {
1044 switch (laddr->ss_family) {
1046 if ($6 == IPPROTO_ICMPV6) {
1047 racoon_yyerror("upper layer protocol mismatched.\n");
1054 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1059 if ($6 == IPPROTO_ICMP) {
1060 racoon_yyerror("upper layer protocol mismatched.\n");
1067 $$ = ipsecdoi_sockrange2id(laddr, haddr,
1072 racoon_yyerror("invalid family: %d", laddr->ss_family);
1083 | IDENTIFIERTYPE QUOTEDSTRING
1085 struct ipsecdoi_id_b *id_b;
1087 if ($1 == IDTYPE_ASN1DN) {
1088 racoon_yyerror("id type forbidden: %d", $1);
1095 $$ = vmalloc(sizeof(*id_b) + $2->l);
1097 racoon_yyerror("failed to allocate identifier");
1101 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)$$->v;
1102 id_b->type = idtype2doi($1);
1107 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
1113 cur_sainfo->id_i = NULL;
1116 | FROM IDENTIFIERTYPE identifierstring
1118 struct ipsecdoi_id_b *id_b;
1121 if (set_identifier(&idv, $2, $3) != 0) {
1122 racoon_yyerror("failed to set identifer.\n");
1125 cur_sainfo->id_i = vmalloc(sizeof(*id_b) + idv->l);
1126 if (cur_sainfo->id_i == NULL) {
1127 racoon_yyerror("failed to allocate identifier");
1131 id_b = ALIGNED_CAST(struct ipsecdoi_id_b *)cur_sainfo->id_i->v;
1132 id_b->type = idtype2doi($2);
1137 memcpy(cur_sainfo->id_i->v + sizeof(*id_b),
1141 | GROUP QUOTEDSTRING
1143 #ifdef ENABLE_HYBRID
1144 if ((cur_sainfo->group = vdup($2)) == NULL) {
1145 racoon_yyerror("failed to set sainfo xauth group.\n");
1149 racoon_yyerror("racoon not configured with --enable-hybrid");
1156 | sainfo_specs sainfo_spec
1159 : PFS_GROUP dh_group_num
1161 cur_sainfo->pfs_group = $2;
1162 switch (cur_sainfo->pfs_group)
1164 case OAKLEY_ATTR_GRP_DESC_MODP768:
1165 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1166 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1167 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1168 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1169 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1170 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1171 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1174 racoon_yyerror("Invalid PFS group specified");
1180 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1182 cur_sainfo->lifetime = $3 * $4;
1185 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1188 racoon_yyerror("byte lifetime support is deprecated");
1191 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
1192 if (cur_sainfo->lifebyte == 0)
1201 | IDENTIFIER IDENTIFIERTYPE
1203 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1206 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
1208 racoon_yyerror("it's deprecated to specify a identifier in phase 2");
1216 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1220 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
1225 : ALGORITHMTYPE keylength
1229 $$ = newsainfoalg();
1231 racoon_yyerror("failed to get algorithm allocation");
1235 $$->alg = algtype2doi(cur_algclass, $1);
1236 if ($$->alg == -1) {
1237 racoon_yyerror("algorithm mismatched");
1243 defklen = default_keylen(cur_algclass, $1);
1246 racoon_yyerror("keylen not allowed");
1252 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
1253 racoon_yyerror("invalid keylen %d", $2);
1263 $$->encklen = defklen;
1265 /* check if it's supported algorithm by kernel */
1266 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
1267 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
1268 int a = algclass2doi(cur_algclass);
1269 int b = algtype2doi(cur_algclass, $1);
1270 if (a == IPSECDOI_ATTR_AUTH)
1271 a = IPSECDOI_PROTO_IPSEC_AH;
1272 racoon_yyerror("algorithm %s not supported by the kernel (missing module?)",
1273 s_ipsecdoi_trns(a, b));
1281 : /* nothing */ { $$ = ~0; }
1282 | PREFIX { $$ = $1; }
1285 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
1287 | PORTANY { $$ = IPSEC_PORT_ANY; }
1290 : NUMBER { $$ = $1; }
1291 | UL_PROTO { $$ = $1; }
1292 | ANY { $$ = IPSEC_ULPROTO_ANY; }
1295 : /* nothing */ { $$ = 0; }
1296 | NUMBER { $$ = $1; }
1301 : REMOTE remote_index INHERIT remote_index
1303 struct remoteconf *new;
1304 struct proposalspec *prspec;
1306 new = copyrmconf($4->addr);
1308 racoon_yyerror("failed to get remoteconf for %s.", saddr2str((struct sockaddr *)$4));
1309 racoon_free($2->addr);
1311 racoon_free($4->addr);
1316 new->remote = $2->addr;
1317 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1318 new->inherited_from = getrmconf_strict($4->addr, 1);
1319 new->proposal = NULL;
1323 racoon_free($4->addr);
1326 prspec = newprspec();
1327 if (prspec == NULL || !cur_rmconf->inherited_from
1328 || !cur_rmconf->inherited_from->proposal)
1330 prspec->lifetime = cur_rmconf->inherited_from->proposal->lifetime;
1331 prspec->lifebyte = cur_rmconf->inherited_from->proposal->lifebyte;
1332 insprspec(prspec, &cur_rmconf->prhead);
1335 | REMOTE remote_index
1337 struct remoteconf *new;
1338 struct proposalspec *prspec;
1340 new = create_rmconf();
1342 racoon_yyerror("failed to get new remoteconf.");
1343 racoon_free($2->addr);
1347 new->remote = $2->addr;
1348 new->remote_prefix = ($2->prefix == ~0 ? 0 : $2->prefix);
1352 prspec = newprspec();
1355 prspec->lifetime = oakley_get_defaultlifetime();
1356 insprspec(prspec, &cur_rmconf->prhead);
1362 : BOC remote_specs EOC
1364 /* check a exchange mode */
1365 if (cur_rmconf->etypes == NULL) {
1366 racoon_yyerror("no exchange mode specified.\n");
1370 if (cur_rmconf->idvtype == IDTYPE_UNDEFINED)
1371 cur_rmconf->idvtype = IDTYPE_ADDRESS;
1374 if (cur_rmconf->idvtype == IDTYPE_ASN1DN) {
1375 if (cur_rmconf->identity_in_keychain)
1377 if (cur_rmconf->idv)
1378 racoon_yywarn("Both CERT and ASN1 ID "
1379 "are set. Hope this is OK.\n");
1380 /* TODO: Preparse the DN here */
1381 } else if (cur_rmconf->idv) {
1382 /* OK, using asn1dn without X.509. */
1384 racoon_yyerror("ASN1 ID not specified "
1385 "and no CERT defined!\n");
1390 if (cur_rmconf->cert_verification_option == VERIFICATION_OPTION_PEERS_IDENTIFIER) {
1391 struct genlist_entry *gpb;
1392 if (genlist_next(cur_rmconf->idvl_p, &gpb) == NULL) {
1393 racoon_yyerror("peers_identifier required for specified certificate "
1394 "verification option.\n");
1399 if (cur_rmconf->prhead->spspec == NULL
1400 && cur_rmconf->inherited_from
1401 && cur_rmconf->inherited_from->prhead) {
1402 cur_rmconf->prhead->spspec = cur_rmconf->inherited_from->prhead->spspec;
1404 if (set_isakmp_proposal(cur_rmconf, cur_rmconf->prhead) != 0)
1407 /* DH group setting if aggressive mode or IKEv2. */
1408 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
1413 for (p = cur_rmconf->proposal; p; p = p->next) {
1414 if (b == 0 || (b && b == p->dh_group)) {
1418 racoon_yyerror("DH group must be equal "
1420 "when aggressive mode is "
1424 cur_rmconf->dh_group = b;
1426 if (cur_rmconf->dh_group == 0) {
1427 racoon_yyerror("DH group must be set in the proposal.\n");
1431 /* DH group settting if PFS is required. */
1432 if (oakley_setdhgroup(cur_rmconf->dh_group,
1433 &cur_rmconf->dhgrp) < 0) {
1434 racoon_yyerror("failed to set DH value.\n");
1439 insrmconf(cur_rmconf);
1443 : ANONYMOUS ike_port
1446 struct remote_index_val *new;
1448 new = racoon_calloc(1, sizeof(*new));
1450 racoon_yyerror("failed to allocate remote index struct");
1453 new->addr = newsaddr(sizeof(struct sockaddr_storage));
1454 if (new->addr == NULL) {
1455 racoon_yyerror("failed to allocate sockaddr storage");
1459 new->addr->ss_family = AF_UNSPEC;
1460 (ALIGNED_CAST(struct sockaddr_in *)new->addr)->sin_port = htons($2);
1464 | ike_addrinfo_prefix_port
1468 racoon_yyerror("failed to allocate sockaddr_storage");
1475 | remote_specs remote_spec
1480 cur_rmconf->etypes = NULL;
1483 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
1484 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
1485 | IKE_VERSION NUMBER
1488 cur_rmconf->ike_version = ISAKMP_VERSION_NUMBER_IKEV1;
1490 racoon_yyerror("invalid IKE version specified.\n");
1494 | CERTIFICATE_TYPE cert_spec
1495 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
1496 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
1497 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
1498 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE
1500 cur_rmconf->cert_verification = $2;
1502 | CERTIFICATE_VERIFICATION VERIFICATION_MODULE VERIFICATION_OPTION
1504 cur_rmconf->cert_verification = $2;
1505 cur_rmconf->cert_verification_option = $3;
1508 | OPEN_DIR_AUTH_GROUP QUOTEDSTRING
1511 cur_rmconf->open_dir_auth_group = $2;
1513 racoon_yyerror("Apple specific features not compiled in.");
1517 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
1519 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
1520 racoon_yyerror("failed to set identifer.\n");
1521 vfree($3); //%%% BUG FIX - memory leak
1524 vfree($3); //%%% BUG FIX - memory leak
1525 cur_rmconf->idvtype = $2;
1528 | MY_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1530 if (set_identifier_qual(&cur_rmconf->idv, $2, $4, $3) != 0) {
1531 racoon_yyerror("failed to set identifer.\n");
1534 cur_rmconf->idvtype = $2;
1537 | XAUTH_LOGIN identifierstring
1539 #ifdef ENABLE_HYBRID
1540 /* formerly identifier type login */
1541 if (xauth_rmconf_used(&cur_rmconf->xauth) == -1) {
1542 racoon_yyerror("failed to allocate xauth state\n");
1545 if ((cur_rmconf->xauth->login = vdup($2)) == NULL) {
1546 racoon_yyerror("failed to set identifer.\n");
1549 vfree($2); //%%% BUG FIX - memory leak
1551 racoon_yyerror("racoon not configured with --enable-hybrid");
1555 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
1560 racoon_yyerror("failed to allocate idspec");
1563 if (set_identifier(&id->id, $2, $3) != 0) {
1564 racoon_yyerror("failed to set identifer.\n");
1566 vfree($3); //%%% BUG FIX - memory leak
1569 vfree($3); //%%% BUG FIX - memory leak
1571 genlist_append (cur_rmconf->idvl_p, id);
1574 | PEERS_IDENTIFIER IDENTIFIERTYPE IDENTIFIERQUAL identifierstring
1579 racoon_yyerror("failed to allocate idspec");
1582 if (set_identifier_qual(&id->id, $2, $4, $3) != 0) {
1583 racoon_yyerror("failed to set identifer.\n");
1588 genlist_append (cur_rmconf->idvl_p, id);
1591 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
1592 | LOCAL_ADDRESS ADDRSTRING
1594 struct sockaddr_storage *saddr;
1595 saddr = str2saddr($2->v, NULL);
1599 cur_rmconf->forced_local = saddr;
1601 | SHARED_SECRET SECRETTYPE QUOTEDSTRING
1603 cur_rmconf->secrettype = $2;
1604 cur_rmconf->shared_secret = $3;
1606 | SHARED_SECRET SECRETTYPE
1608 if ($2 != SECRETTYPE_KEYCHAIN_BY_ID) {
1609 racoon_yyerror("shared secret value missing.\n");
1612 cur_rmconf->secrettype = $2;
1614 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
1617 racoon_yyerror("dh_group cannot be defined here.");
1621 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
1622 | IKE_FRAG SWITCH { cur_rmconf->ike_frag = $2; } EOS
1623 | IKE_FRAG REMOTE_FORCE_LEVEL { cur_rmconf->ike_frag = ISAKMP_FRAG_FORCE; } EOS
1625 #ifdef SADB_X_EXT_NAT_T_FRAG
1626 if (libipsec_opt & LIBIPSEC_OPT_FRAG)
1627 cur_rmconf->esp_frag = $2;
1629 racoon_yywarn("libipsec lacks IKE frag support");
1631 racoon_yywarn("Your kernel does not support esp_frag");
1634 | MODE_CFG SWITCH { cur_rmconf->mode_cfg = $2; } EOS
1635 | WEAK_PHASE1_CHECK SWITCH {
1636 cur_rmconf->weak_phase1_check = $2;
1638 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
1639 | GENERATE_POLICY GENERATE_LEVEL { cur_rmconf->gen_policy = $2; } EOS
1640 | SUPPORT_PROXY SWITCH { cur_rmconf->support_proxy = $2; } EOS
1641 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
1642 | NAT_TRAVERSAL SWITCH
1645 cur_rmconf->nat_traversal = $2;
1647 racoon_yyerror("NAT-T support not compiled in.");
1650 | NAT_TRAVERSAL NAT_TRAVERSAL_LEVEL
1653 cur_rmconf->nat_traversal = $2;
1655 racoon_yyerror("NAT-T support not compiled in.");
1658 | NAT_TRAVERSAL_MULTI_USER SWITCH
1661 cur_rmconf->natt_multiple_user = $2;
1663 racoon_yyerror("NAT-T support not compiled in.");
1666 | NAT_TRAVERSAL_KEEPALIVE SWITCH
1669 cur_rmconf->natt_keepalive = $2;
1671 racoon_yyerror("NAT-T support not compiled in.");
1677 cur_rmconf->dpd = $2;
1679 racoon_yyerror("DPD support not compiled in.");
1685 cur_rmconf->dpd_interval = $2;
1687 racoon_yyerror("DPD support not compiled in.");
1694 cur_rmconf->dpd_retry = $2;
1696 racoon_yyerror("DPD support not compiled in.");
1700 | DPD_MAXFAIL NUMBER
1703 cur_rmconf->dpd_maxfails = $2;
1705 racoon_yyerror("DPD support not compiled in.");
1709 | DPD_ALGORITHM dpd_algo_type
1712 cur_rmconf->dpd_algo = $2;
1714 racoon_yyerror("DPD support not compiled in.");
1718 | DISCONNECT_ON_IDLE IDLE_TIMEOUT NUMBER IDLE_DIRECTION idle_dir_type
1720 cur_rmconf->idle_timeout = $3;
1721 cur_rmconf->idle_timeout_dir = $5;
1724 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1726 cur_rmconf->prhead->lifetime = $3 * $4;
1729 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
1730 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1733 racoon_yyerror("byte lifetime support is deprecated in Phase 1");
1736 racoon_yywarn("the lifetime of bytes in phase 1 "
1737 "will be ignored at the moment.");
1738 cur_rmconf->prhead->lifebyte = fix_lifebyte($3 * $4);
1739 if (cur_rmconf->prhead->lifebyte == 0)
1746 struct secprotospec *spspec;
1748 spspec = newspspec();
1751 insspspec(spspec, &cur_rmconf->prhead);
1753 BOC isakmpproposal_specs EOC
1757 | exchange_types EXCHANGETYPE
1760 new = racoon_malloc(sizeof(struct etypes));
1762 racoon_yyerror("failed to allocate etypes");
1767 if (cur_rmconf->etypes == NULL)
1768 cur_rmconf->etypes = new;
1771 for (p = cur_rmconf->etypes;
1780 : CERT_X509 IN_KEYCHAIN
1782 cur_rmconf->certtype = $1;
1783 cur_rmconf->identity_in_keychain = 1;
1784 cur_rmconf->keychainCertRef = NULL;
1788 | CERT_X509 IN_KEYCHAIN QUOTEDSTRING
1790 cur_rmconf->certtype = $1;
1791 cur_rmconf->identity_in_keychain = 1;
1792 cur_rmconf->keychainCertRef = $3;
1799 $$ = algtype2doi(algclass_isakmp_dh, $1);
1801 racoon_yyerror("must be DH group");
1806 case OAKLEY_ATTR_GRP_DESC_MODP768:
1807 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1808 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1809 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1810 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1811 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1812 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1813 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1816 racoon_yyerror("Invalid DH group specified");
1823 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
1824 $$ = num2dhgroup[$1];
1826 racoon_yyerror("must be DH group");
1832 case OAKLEY_ATTR_GRP_DESC_MODP768:
1833 case OAKLEY_ATTR_GRP_DESC_MODP1024:
1834 case OAKLEY_ATTR_GRP_DESC_MODP1536:
1835 case OAKLEY_ATTR_GRP_DESC_MODP2048:
1836 case OAKLEY_ATTR_GRP_DESC_MODP3072:
1837 case OAKLEY_ATTR_GRP_DESC_MODP4096:
1838 case OAKLEY_ATTR_GRP_DESC_MODP6144:
1839 case OAKLEY_ATTR_GRP_DESC_MODP8192:
1842 racoon_yyerror("Invalid DH group specified");
1849 : /* nothing */ { $$ = NULL; }
1850 | ADDRSTRING { $$ = $1; }
1851 | QUOTEDSTRING { $$ = $1; }
1853 isakmpproposal_specs
1855 | isakmpproposal_specs isakmpproposal_spec
1860 racoon_yyerror("strength directive is obsoleted.");
1862 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
1864 cur_rmconf->prhead->spspec->lifetime = $3 * $4;
1867 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
1870 racoon_yyerror("byte lifetime support is deprecated");
1873 cur_rmconf->prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
1874 if (cur_rmconf->prhead->spspec->lifebyte == 0)
1879 | DH_GROUP dh_group_num
1881 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_dh] = $2;
1884 | GSS_ID QUOTEDSTRING
1886 if (cur_rmconf->prhead->spspec->vendorid != VENDORID_GSSAPI) {
1887 racoon_yyerror("wrong Vendor ID for gssapi_id");
1890 if (cur_rmconf->prhead->spspec->gssid != NULL)
1891 racoon_free(cur_rmconf->prhead->spspec->gssid);
1892 cur_rmconf->prhead->spspec->gssid =
1893 racoon_strdup($2->v);
1894 STRDUP_FATAL(cur_rmconf->prhead->spspec->gssid);
1897 | ALGORITHM_CLASS ALGORITHMTYPE keylength
1902 doi = algtype2doi($1, $2);
1904 racoon_yyerror("algorithm mismatched 1");
1910 case algclass_isakmp_enc:
1911 /* reject suppressed algorithms */
1912 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_enc] = doi;
1913 defklen = default_keylen($1, $2);
1916 racoon_yyerror("keylen not allowed");
1920 if ($3 && check_keylen($1, $2, $3) < 0) {
1921 racoon_yyerror("invalid keylen %d", $3);
1926 cur_rmconf->prhead->spspec->encklen = $3;
1928 cur_rmconf->prhead->spspec->encklen = defklen;
1930 case algclass_isakmp_hash:
1931 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_hash] = doi;
1933 case algclass_isakmp_ameth:
1934 cur_rmconf->prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
1936 * We may have to set the Vendor ID for the
1937 * authentication method we're using.
1940 case algtype_gssapikrb:
1941 if (cur_rmconf->prhead->spspec->vendorid !=
1943 racoon_yyerror("Vendor ID mismatch "
1948 * For interoperability with Win2k,
1949 * we set the Vendor ID to "GSSAPI".
1951 cur_rmconf->prhead->spspec->vendorid =
1959 racoon_yyerror("algorithm mismatched 2");
1967 : UNITTYPE_SEC { $$ = 1; }
1968 | UNITTYPE_MIN { $$ = 60; }
1969 | UNITTYPE_HOUR { $$ = (60 * 60); }
1972 : UNITTYPE_BYTE { $$ = 1; }
1973 | UNITTYPE_KBYTES { $$ = 1024; }
1974 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
1975 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
1978 : DPD_ALGO_TYPE_DEFAULT { $$ = DPD_ALGO_DEFAULT; }
1979 | DPD_ALGO_TYPE_INBOUND { $$ = DPD_ALGO_INBOUND_DETECT; }
1980 | DPD_ALGO_TYPE_BLACKHOLE { $$ = DPD_ALGO_BLACKHOLE_DETECT; }
1983 : IDLE_DIRECTION_ANY { $$ = IPSEC_DIR_ANY; }
1984 | IDLE_DIRECTION_IN { $$ = IPSEC_DIR_INBOUND; }
1985 | IDLE_DIRECTION_OUT { $$ = IPSEC_DIR_OUTBOUND; }
1989 static struct proposalspec *
1992 struct proposalspec *new;
1994 new = racoon_calloc(1, sizeof(*new));
1996 racoon_yyerror("failed to allocate proposal");
2002 * insert into head of list.
2005 insprspec(prspec, head)
2006 struct proposalspec *prspec;
2007 struct proposalspec **head;
2010 (*head)->prev = prspec;
2011 prspec->next = *head;
2015 static struct secprotospec *
2018 struct secprotospec *new;
2020 new = racoon_calloc(1, sizeof(*new));
2022 racoon_yyerror("failed to allocate spproto");
2026 new->encklen = 0; /*XXX*/
2029 * Default to "uknown" vendor -- we will override this
2030 * as necessary. When we send a Vendor ID payload, an
2031 * "unknown" will be translated to a KAME/racoon ID.
2033 new->vendorid = VENDORID_UNKNOWN;
2039 * insert into head of list.
2042 insspspec(spspec, head)
2043 struct secprotospec *spspec;
2044 struct proposalspec **head;
2046 spspec->back = *head;
2048 if ((*head)->spspec != NULL)
2049 (*head)->spspec->prev = spspec;
2050 spspec->next = (*head)->spspec;
2051 (*head)->spspec = spspec;
2054 /* set final acceptable proposal */
2056 set_isakmp_proposal(rmconf, prspec)
2057 struct remoteconf *rmconf;
2058 struct proposalspec *prspec;
2060 struct proposalspec *p;
2061 struct secprotospec *s;
2064 int32_t types[MAXALGCLASS];
2069 "multiple proposal definition.\n");
2073 /* mandatory check */
2074 if (p->spspec == NULL) {
2075 racoon_yyerror("no remote specification found: %s.\n",
2076 saddr2str((struct sockaddr *)rmconf->remote));
2079 for (s = p->spspec; s != NULL; s = s->next) {
2080 /* XXX need more to check */
2081 if (s->algclass[algclass_isakmp_enc] == 0) {
2082 racoon_yyerror("encryption algorithm required.");
2085 if (s->algclass[algclass_isakmp_hash] == 0) {
2086 racoon_yyerror("hash algorithm required.");
2089 if (s->algclass[algclass_isakmp_dh] == 0) {
2090 racoon_yyerror("DH group required.");
2093 if (s->algclass[algclass_isakmp_ameth] == 0) {
2094 racoon_yyerror("authentication method required.");
2099 /* skip to last part */
2100 for (s = p->spspec; s->next != NULL; s = s->next)
2104 plog(ASL_LEVEL_DEBUG,
2105 "lifetime = %ld\n", (long)
2106 (s->lifetime ? s->lifetime : p->lifetime));
2107 plog(ASL_LEVEL_DEBUG,
2109 s->lifebyte ? s->lifebyte : p->lifebyte);
2110 plog(ASL_LEVEL_DEBUG,
2111 "encklen=%d\n", s->encklen);
2113 memset(types, 0, ARRAYLEN(types));
2114 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
2115 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
2116 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
2117 types[algclass_isakmp_ameth] =
2118 s->algclass[algclass_isakmp_ameth];
2120 /* expanding spspec */
2122 trns_no = expand_isakmpspec(prop_no, trns_no, types,
2123 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
2124 s->lifetime ? s->lifetime : p->lifetime,
2125 s->lifebyte ? s->lifebyte : p->lifebyte,
2126 s->encklen, s->vendorid, s->gssid,
2128 if (trns_no == -1) {
2130 "failed to expand isakmp proposal.\n");
2137 if (rmconf->proposal == NULL) {
2139 "no proposal found.\n");
2150 for (i = 0; i < MAXALGCLASS; i++)
2151 tmpalgtype[i] = 0; /* means algorithm undefined. */
2155 expand_isakmpspec(prop_no, trns_no, types,
2156 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
2158 int prop_no, trns_no;
2159 int *types, class, last;
2165 struct remoteconf *rmconf;
2167 struct isakmpsa *new;
2173 plog(ASL_LEVEL_DEBUG,
2174 "p:%d t:%d\n", prop_no, trns_no);
2175 for (j = class; j < MAXALGCLASS; j++) {
2176 snprintf(tb, sizeof(tb), "%d", types[j]);
2177 plog(ASL_LEVEL_DEBUG,
2179 s_algtype(j, types[j]),
2180 types[j] ? "(" : "",
2181 tb[0] == '0' ? "" : tb,
2182 types[j] ? ")" : "");
2184 plog(ASL_LEVEL_DEBUG, "\n");
2187 #define TMPALGTYPE2STR(n) \
2188 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
2189 /* check mandatory values */
2190 if (types[algclass_isakmp_enc] == 0
2191 || types[algclass_isakmp_ameth] == 0
2192 || types[algclass_isakmp_dh] == 0) {
2193 racoon_yyerror("few definition of algorithm "
2194 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
2195 TMPALGTYPE2STR(enc),
2196 TMPALGTYPE2STR(ameth),
2197 TMPALGTYPE2STR(hash),
2198 TMPALGTYPE2STR(dh));
2201 #undef TMPALGTYPE2STR
2204 new = newisakmpsa();
2206 racoon_yyerror("failed to allocate isakmp sa");
2209 new->prop_no = prop_no;
2210 new->trns_no = trns_no++;
2211 new->lifetime = lifetime;
2212 new->lifebyte = lifebyte;
2213 new->enctype = types[algclass_isakmp_enc];
2214 new->encklen = encklen;
2215 new->authmethod = types[algclass_isakmp_ameth];
2216 new->hashtype = types[algclass_isakmp_hash];
2217 new->prf = types[algclass_isakmp_hash];
2218 new->dh_group = types[algclass_isakmp_dh];
2219 new->vendorid = vendorid;
2220 insisakmpsa(new, rmconf);
2226 listen_addr (struct sockaddr_storage *addr, int udp_encap)
2232 racoon_yyerror("failed to allocate myaddrs");
2236 if (p->addr == NULL) {
2237 racoon_yyerror("failed to copy sockaddr_storage ");
2241 p->udp_encap = udp_encap;
2242 /* These need to be initialized for Apple modifications
2243 * to open code for isakmp sockets
2248 insmyaddr(p, &lcconf->myaddrs);
2250 lcconf->autograbaddr = 0;
2257 * Must be more than 1024B because its unit is kilobytes.
2258 * That is defined RFC2407.
2265 racoon_yyerror("byte size should be more than 1024B.");
2278 plog(ASL_LEVEL_DEBUG, "===== parsing configuration\n");
2282 if (yycf_switch_buffer(lcconf->racoon_conf) != 0) {
2283 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2284 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2285 CONSTSTR("could not read configuration file"),
2286 CONSTSTR("cfparse: yycf_switch_buffer erred"));
2288 "could not read configuration file \"%s\"\n",
2289 lcconf->racoon_conf);
2297 "fatal parse failure (%d errors)\n",
2301 "fatal parse failure.\n");
2303 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2304 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2305 CONSTSTR("fatal parse failure"),
2306 CONSTSTR("cfparse: yyparse erred"));
2307 yycf_clean_buffer();
2311 if (error == 0 && yyerrorcount) {
2313 "parse error is nothing, but yyerrorcount is %d.\n",
2315 IPSECCONFIGTRACEREVENT(CONSTSTR(lcconf->racoon_conf),
2316 IPSECCONFIGEVENTCODE_PARSE_ERROR,
2317 CONSTSTR("ambivalent error code"),
2318 CONSTSTR("cfparse: error == 0 && yerrorcount"));
2319 yycf_clean_buffer();
2323 yycf_clean_buffer();
2325 plog(ASL_LEVEL_DEBUG, "parse succeeded.\n");
2334 int ignore_estab_or_assert_handles = (sig == SIGUSR1);
2336 if (sig >= 0 && sig < NSIG) {
2337 plog(ASL_LEVEL_DEBUG, "==== Got %s signal - re-parsing configuration.\n", sys_signame[sig]);
2339 plog(ASL_LEVEL_ERR, "==== Got Unknown signal - re-parsing configuration.\n");
2340 IPSECCONFIGTRACEREVENT(CONSTSTR("reparse"),
2341 IPSECCONFIGEVENTCODE_REPARSE_ERROR,
2342 CONSTSTR("Unknown signal"),
2343 CONSTSTR("cfreparse: triggered by unknown signal"));
2345 plog(ASL_LEVEL_DEBUG, "==== %s sessions.\n", ignore_estab_or_assert_handles? "flush negotiating" : "flush all");
2347 ike_session_flush_all_phase2(ignore_estab_or_assert_handles);
2348 ike_session_flush_all_phase1(ignore_estab_or_assert_handles);
2351 check_auto_exit(); /* check/change state of auto exit */