1 /* $KAME: cfparse.y,v 1.114 2003/02/03 08:27:50 itojun Exp $ */
7 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <netinet6/ipsec.h>
11 #include <netkey/key_var.h>
18 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
30 /*#include "cfparse.h"*/
32 #include "algorithm.h"
33 #include "localconf.h"
38 #include "remoteconf.h"
39 #include "grabmyaddr.h"
40 #include "isakmp_var.h"
43 #include "ipsec_doi.h"
52 time_t lifetime; /* for isakmp/ipsec */
53 int lifebyte; /* for isakmp/ipsec */
54 struct secprotospec *spspec; /* the head is always current spec. */
55 struct proposalspec *next; /* the tail is the most prefered. */
56 struct proposalspec *prev;
62 int strength; /* for isakmp/ipsec */
63 int encklen; /* for isakmp/ipsec */
64 time_t lifetime; /* for isakmp */
65 int lifebyte; /* for isakmp */
66 int proto_id; /* for ipsec (isakmp?) */
67 int ipsec_level; /* for ipsec */
68 int encmode; /* for ipsec */
69 int vendorid; /* for isakmp */
71 struct sockaddr *remote;
72 int algclass[MAXALGCLASS];
74 struct secprotospec *next; /* the tail is the most prefiered. */
75 struct secprotospec *prev;
76 struct proposalspec *back;
79 static int num2dhgroup[] = {
81 OAKLEY_ATTR_GRP_DESC_MODP768,
82 OAKLEY_ATTR_GRP_DESC_MODP1024,
83 OAKLEY_ATTR_GRP_DESC_EC2N155,
84 OAKLEY_ATTR_GRP_DESC_EC2N185,
85 OAKLEY_ATTR_GRP_DESC_MODP1536,
88 static struct remoteconf *cur_rmconf;
89 static int tmpalgtype[MAXALGCLASS];
90 static struct sainfo *cur_sainfo;
91 static int cur_algclass;
93 static struct proposalspec *prhead; /* the head is always current. */
95 static struct proposalspec *newprspec __P((void));
96 static void cleanprhead __P((void));
97 static void insprspec __P((struct proposalspec *, struct proposalspec **));
98 static struct secprotospec *newspspec __P((void));
99 static void insspspec __P((struct secprotospec *, struct proposalspec **));
101 static int set_isakmp_proposal
102 __P((struct remoteconf *, struct proposalspec *));
103 static void clean_tmpalgtype __P((void));
104 static int expand_isakmpspec __P((int, int, int *,
105 int, int, time_t, int, int, int, char *, struct remoteconf *));
108 static int fix_lifebyte __P((u_long));
115 struct remoteconf *rmconf;
116 struct sockaddr *saddr;
117 struct sainfoalg *alg;
124 /* self information */
125 %token IDENTIFIER VENDORID
127 %token LOGGING LOGLEV
129 %token PADDING PAD_RANDOMIZE PAD_RANDOMIZELEN PAD_MAXLEN PAD_STRICT PAD_EXCLTAIL
131 %token LISTEN X_ISAKMP X_ADMIN STRICT_ADDRESS
133 %token RETRY RETRY_COUNTER RETRY_INTERVAL RETRY_PERSEND
134 %token RETRY_PHASE1 RETRY_PHASE2
136 %token ALGORITHM_CLASS ALGORITHMTYPE STRENGTHTYPE
140 %token REMOTE ANONYMOUS
141 %token EXCHANGE_MODE EXCHANGETYPE DOI DOITYPE SITUATION SITUATIONTYPE
142 %token CERTIFICATE_TYPE CERTTYPE PEERS_CERTFILE VERIFY_CERT SEND_CERT SEND_CR
143 %token IDENTIFIERTYPE MY_IDENTIFIER PEERS_IDENTIFIER VERIFY_IDENTIFIER
144 %token SHARED_SECRET SECRETTYPE
145 %token DNSSEC CERT_X509
146 %token NONCE_SIZE DH_GROUP KEEPALIVE PASSIVE INITIAL_CONTACT
147 %token PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL
148 %token GENERATE_POLICY SUPPORT_MIP6
150 %token EXEC_PATH EXEC_COMMAND EXEC_SUCCESS EXEC_FAILURE
152 %token COMPLEX_BUNDLE
154 %token PREFIX PORT PORTANY UL_PROTO ANY
155 %token PFS_GROUP LIFETIME LIFETYPE_TIME LIFETYPE_BYTE STRENGTH
157 %token NUMBER SWITCH BOOLEAN
158 %token HEXSTRING QUOTEDSTRING ADDRSTRING
159 %token UNITTYPE_BYTE UNITTYPE_KBYTES UNITTYPE_MBYTES UNITTYPE_TBYTES
160 %token UNITTYPE_SEC UNITTYPE_MIN UNITTYPE_HOUR
161 %token EOS BOC EOC COMMA
163 %type <num> NUMBER BOOLEAN SWITCH keylength
164 %type <num> PATHTYPE IDENTIFIERTYPE LOGLEV
165 %type <num> SECRETTYPE
166 %type <num> ALGORITHM_CLASS dh_group_num
167 %type <num> ALGORITHMTYPE STRENGTHTYPE
168 %type <num> PREFIX prefix PORT port ike_port
169 %type <num> ul_proto UL_PROTO
170 %type <num> EXCHANGETYPE DOITYPE SITUATIONTYPE
171 %type <num> CERTTYPE CERT_X509 PROPOSAL_CHECK_LEVEL
172 %type <num> unittype_time unittype_byte
173 %type <val> QUOTEDSTRING HEXSTRING ADDRSTRING sainfo_id
174 %type <val> identifierstring
175 %type <saddr> remote_index ike_addrinfo_port
176 %type <alg> algorithm
182 | statements statement
187 | identifier_statement
199 : PATH PATHTYPE QUOTEDSTRING
201 if ($2 > LC_PATHTYPE_MAX) {
202 yyerror("invalid path type %d", $2);
206 /* free old pathinfo */
207 if (lcconf->pathinfo[$2])
208 racoon_free(lcconf->pathinfo[$2]);
210 /* set new pathinfo */
211 lcconf->pathinfo[$2] = strdup($3->v);
219 : COMPLEX_BUNDLE SWITCH { lcconf->complex_bundle = $2; } EOS
224 : INCLUDE QUOTEDSTRING EOS
226 char path[MAXPATHLEN];
228 getpathname(path, sizeof(path),
229 LC_PATHTYPE_INCLUDE, $2->v);
231 if (yycf_switch_buffer(path) != 0)
236 /* self infomation */
238 : IDENTIFIER identifier_stmt
243 /*XXX to be deleted */
246 | IDENTIFIERTYPE QUOTEDSTRING
248 /*XXX to be deleted */
249 $2->l--; /* nuke '\0' */
250 lcconf->ident[$1] = $2;
251 if (lcconf->ident[$1] == NULL) {
252 yyerror("failed to set my ident: %s",
262 : LOGGING log_level EOS
268 * XXX ignore it because this specification
271 yywarn("see racoon.conf(5), such a log specification will be obsoleted.");
277 * set the loglevel by configuration file only when
278 * the command line did not specify any loglevel.
280 if (loglevel <= LLV_BASE)
287 : PADDING BOC padding_stmts EOC
291 | padding_stmts padding_stmt
294 : PAD_RANDOMIZE SWITCH { lcconf->pad_random = $2; } EOS
295 | PAD_RANDOMIZELEN SWITCH { lcconf->pad_randomlen = $2; } EOS
296 | PAD_MAXLEN NUMBER { lcconf->pad_maxsize = $2; } EOS
297 | PAD_STRICT SWITCH { lcconf->pad_strict = $2; } EOS
298 | PAD_EXCLTAIL SWITCH { lcconf->pad_excltail = $2; } EOS
303 : LISTEN BOC listen_stmts EOC
307 | listen_stmts listen_stmt
310 : X_ISAKMP ike_addrinfo_port
316 yyerror("failed to allocate myaddrs");
320 if (p->addr == NULL) {
321 yyerror("failed to copy sockaddr ");
326 insmyaddr(p, &lcconf->myaddrs);
328 lcconf->autograbaddr = 0;
333 yyerror("admin directive is obsoleted.");
336 | STRICT_ADDRESS { lcconf->strict_address = TRUE; } EOS
339 : ADDRSTRING ike_port
343 snprintf(portbuf, sizeof(portbuf), "%ld", $2);
344 $$ = str2saddr($1->v, portbuf);
351 : /* nothing */ { $$ = PORT_ISAKMP; }
357 : RETRY BOC timer_stmts EOC
361 | timer_stmts timer_stmt
364 : RETRY_COUNTER NUMBER
366 lcconf->retry_counter = $2;
369 | RETRY_INTERVAL NUMBER unittype_time
371 lcconf->retry_interval = $2 * $3;
374 | RETRY_PERSEND NUMBER
376 lcconf->count_persend = $2;
379 | RETRY_PHASE1 NUMBER unittype_time
381 lcconf->retry_checkph1 = $2 * $3;
384 | RETRY_PHASE2 NUMBER unittype_time
386 lcconf->wait_ph2complete = $2 * $3;
395 cur_sainfo = newsainfo();
396 if (cur_sainfo == NULL) {
397 yyerror("failed to allocate sainfo");
401 sainfo_name BOC sainfo_specs
403 struct sainfo *check;
406 if (cur_sainfo->algs[algclass_ipsec_enc] == 0) {
407 yyerror("no encryption algorithm at %s",
408 sainfo2str(cur_sainfo));
411 if (cur_sainfo->algs[algclass_ipsec_auth] == 0) {
412 yyerror("no authentication algorithm at %s",
413 sainfo2str(cur_sainfo));
416 if (cur_sainfo->algs[algclass_ipsec_comp] == 0) {
417 yyerror("no compression algorithm at %s",
418 sainfo2str(cur_sainfo));
422 /* duplicate check */
423 check = getsainfo(cur_sainfo->idsrc, cur_sainfo->iddst);
424 if (check && (!check->idsrc && !cur_sainfo->idsrc)) {
425 yyerror("duplicated sainfo: %s",
426 sainfo2str(cur_sainfo));
429 inssainfo(cur_sainfo);
436 cur_sainfo->idsrc = NULL;
437 cur_sainfo->iddst = NULL;
439 | sainfo_id sainfo_id
441 cur_sainfo->idsrc = $1;
442 cur_sainfo->iddst = $2;
446 : IDENTIFIERTYPE ADDRSTRING prefix port ul_proto
449 struct sockaddr *saddr;
451 if (($5 == IPPROTO_ICMP || $5 == IPPROTO_ICMPV6)
452 && ($4 != IPSEC_PORT_ANY || $4 != IPSEC_PORT_ANY)) {
453 yyerror("port number must be \"any\".");
457 snprintf(portbuf, sizeof(portbuf), "%lu", $4);
458 saddr = str2saddr($2->v, portbuf);
463 switch (saddr->sa_family) {
465 if ($5 == IPPROTO_ICMPV6) {
466 yyerror("upper layer protocol mismatched.\n");
470 $$ = ipsecdoi_sockaddr2id(saddr,
471 $3 == ~0 ? (sizeof(struct in_addr) << 3): $3,
476 if ($5 == IPPROTO_ICMP) {
477 yyerror("upper layer protocol mismatched.\n");
481 $$ = ipsecdoi_sockaddr2id(saddr,
482 $3 == ~0 ? (sizeof(struct in6_addr) << 3) : $3,
487 yyerror("invalid family: %d", saddr->sa_family);
494 | IDENTIFIERTYPE QUOTEDSTRING
496 struct ipsecdoi_id_b *id_b;
498 if ($1 == IDTYPE_ASN1DN) {
499 yyerror("id type forbidden: %d", $1);
505 $$ = vmalloc(sizeof(*id_b) + $2->l);
507 yyerror("failed to allocate identifier");
511 id_b = (struct ipsecdoi_id_b *)$$->v;
512 id_b->type = idtype2doi($1);
517 memcpy($$->v + sizeof(*id_b), $2->v, $2->l);
522 | sainfo_specs sainfo_spec
525 : PFS_GROUP dh_group_num
527 cur_sainfo->pfs_group = $2;
530 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
532 cur_sainfo->lifetime = $3 * $4;
535 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
538 yyerror("byte lifetime support is deprecated");
541 cur_sainfo->lifebyte = fix_lifebyte($3 * $4);
542 if (cur_sainfo->lifebyte == 0)
551 | IDENTIFIER IDENTIFIERTYPE
553 yyerror("it's deprecated to specify a identifier in phase 2");
556 | MY_IDENTIFIER IDENTIFIERTYPE QUOTEDSTRING
558 yyerror("it's deprecated to specify a identifier in phase 2");
566 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
570 inssainfoalg(&cur_sainfo->algs[cur_algclass], $1);
575 : ALGORITHMTYPE keylength
581 yyerror("failed to get algorithm allocation");
585 $$->alg = algtype2doi(cur_algclass, $1);
587 yyerror("algorithm mismatched");
592 defklen = default_keylen(cur_algclass, $1);
595 yyerror("keylen not allowed");
600 if ($2 && check_keylen(cur_algclass, $1, $2) < 0) {
601 yyerror("invalid keylen %d", $2);
610 $$->encklen = defklen;
612 /* check if it's supported algorithm by kernel */
613 if (!(cur_algclass == algclass_ipsec_auth && $1 == algtype_non_auth)
614 && pk_checkalg(cur_algclass, $1, $$->encklen)) {
615 int a = algclass2doi(cur_algclass);
616 int b = algtype2doi(cur_algclass, $1);
617 if (a == IPSECDOI_ATTR_AUTH)
618 a = IPSECDOI_PROTO_IPSEC_AH;
619 yyerror("algorithm %s not supported",
620 s_ipsecdoi_trns(a, b));
627 : /* nothing */ { $$ = ~0; }
628 | PREFIX { $$ = $1; }
631 : /* nothing */ { $$ = IPSEC_PORT_ANY; }
633 | PORTANY { $$ = IPSEC_PORT_ANY; }
636 : NUMBER { $$ = $1; }
637 | UL_PROTO { $$ = $1; }
638 | ANY { $$ = IPSEC_ULPROTO_ANY; }
641 : /* nothing */ { $$ = 0; }
642 | NUMBER { $$ = $1; }
647 : REMOTE remote_index
649 struct remoteconf *new;
650 struct proposalspec *prspec;
654 yyerror("failed to get new remoteconf.");
661 prspec = newprspec();
664 prspec->lifetime = oakley_get_defaultlifetime();
665 insprspec(prspec, &prhead);
669 /* check a exchange mode */
670 if (cur_rmconf->etypes == NULL) {
671 yyerror("no exchange mode specified.\n");
675 if (cur_rmconf->idvtype == IDTYPE_ASN1DN
676 && cur_rmconf->mycertfile == NULL) {
677 yyerror("id type mismatched due to "
678 "no CERT defined.\n");
682 if (set_isakmp_proposal(cur_rmconf, prhead) != 0)
685 /* DH group settting if aggressive mode is there. */
686 if (check_etypeok(cur_rmconf, ISAKMP_ETYPE_AGG) != NULL) {
691 for (p = cur_rmconf->proposal; p; p = p->next) {
692 if (b == 0 || (b && b == p->dh_group)) {
696 yyerror("DH group must be equal "
697 "to each proposals's "
698 "when aggressive mode is "
702 cur_rmconf->dh_group = b;
704 if (cur_rmconf->dh_group == 0) {
705 yyerror("DH group must be required.\n");
709 /* DH group settting if PFS is required. */
710 if (oakley_setdhgroup(cur_rmconf->dh_group,
711 &cur_rmconf->dhgrp) < 0) {
712 yyerror("failed to set DH value.\n");
717 insrmconf(cur_rmconf);
726 $$ = newsaddr(sizeof(struct sockaddr *));
727 $$->sa_family = AF_UNSPEC;
728 ((struct sockaddr_in *)$$)->sin_port = htons($2);
734 yyerror("failed to allocate sockaddr");
741 | remote_specs remote_spec
744 : EXCHANGE_MODE exchange_types EOS
745 | DOI DOITYPE { cur_rmconf->doitype = $2; } EOS
746 | SITUATION SITUATIONTYPE { cur_rmconf->sittype = $2; } EOS
747 | CERTIFICATE_TYPE cert_spec
748 | PEERS_CERTFILE QUOTEDSTRING
750 #ifdef HAVE_SIGNING_C
751 cur_rmconf->getcert_method = ISAKMP_GETCERT_LOCALFILE;
752 cur_rmconf->peerscertfile = strdup($2->v);
755 yyerror("directive not supported");
760 | PEERS_CERTFILE DNSSEC
762 #ifdef HAVE_SIGNING_C
763 cur_rmconf->getcert_method = ISAKMP_GETCERT_DNS;
764 cur_rmconf->peerscertfile = NULL;
766 yyerror("directive not supported");
771 | VERIFY_CERT SWITCH { cur_rmconf->verify_cert = $2; } EOS
772 | SEND_CERT SWITCH { cur_rmconf->send_cert = $2; } EOS
773 | SEND_CR SWITCH { cur_rmconf->send_cr = $2; } EOS
774 | IDENTIFIER IDENTIFIERTYPE
776 /*XXX to be deleted */
777 cur_rmconf->idvtype = $2;
780 | MY_IDENTIFIER IDENTIFIERTYPE identifierstring
782 if (set_identifier(&cur_rmconf->idv, $2, $3) != 0) {
783 yyerror("failed to set identifer.\n");
787 cur_rmconf->idvtype = $2;
790 | PEERS_IDENTIFIER IDENTIFIERTYPE identifierstring
792 if (set_identifier(&cur_rmconf->idv_p, $2, $3) != 0) {
793 yyerror("failed to set identifer.\n");
797 cur_rmconf->idvtype_p = $2;
800 | VERIFY_IDENTIFIER SWITCH { cur_rmconf->verify_identifier = $2; } EOS
801 | SHARED_SECRET SECRETTYPE QUOTEDSTRING { cur_rmconf->secrettype = $2; cur_rmconf->shared_secret = $3; } EOS
802 | NONCE_SIZE NUMBER { cur_rmconf->nonce_size = $2; } EOS
805 yyerror("dh_group cannot be defined here.");
809 | KEEPALIVE { cur_rmconf->keepalive = TRUE; } EOS
810 | PASSIVE SWITCH { cur_rmconf->passive = $2; } EOS
811 | GENERATE_POLICY SWITCH { cur_rmconf->gen_policy = $2; } EOS
812 | SUPPORT_MIP6 SWITCH { cur_rmconf->support_mip6 = $2; } EOS
813 | INITIAL_CONTACT SWITCH { cur_rmconf->ini_contact = $2; } EOS
814 | PROPOSAL_CHECK PROPOSAL_CHECK_LEVEL { cur_rmconf->pcheck_level = $2; } EOS
815 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
817 prhead->lifetime = $3 * $4;
820 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
823 yyerror("byte lifetime support is deprecated");
826 yywarn("the lifetime of bytes in phase 1 "
827 "will be ignored at the moment.");
828 prhead->lifebyte = fix_lifebyte($3 * $4);
829 if (prhead->lifebyte == 0)
836 struct secprotospec *spspec;
838 spspec = newspspec();
841 insspspec(spspec, &prhead);
843 BOC isakmpproposal_specs EOC
847 | exchange_types EXCHANGETYPE
850 new = racoon_malloc(sizeof(struct etypes));
852 yyerror("filed to allocate etypes");
857 if (cur_rmconf->etypes == NULL)
858 cur_rmconf->etypes = new;
861 for (p = cur_rmconf->etypes;
870 : CERT_X509 QUOTEDSTRING QUOTEDSTRING
872 #ifdef HAVE_SIGNING_C
873 cur_rmconf->certtype = $1;
874 cur_rmconf->mycertfile = strdup($2->v);
876 cur_rmconf->myprivfile = strdup($3->v);
879 yyerror("directive not supported");
888 $$ = algtype2doi(algclass_isakmp_dh, $1);
890 yyerror("must be DH group");
896 if (ARRAYLEN(num2dhgroup) > $1 && num2dhgroup[$1] != 0) {
897 $$ = num2dhgroup[$1];
899 yyerror("must be DH group");
905 : /* nothing */ { $$ = NULL; }
906 | ADDRSTRING { $$ = $1; }
907 | QUOTEDSTRING { $$ = $1; }
911 | isakmpproposal_specs isakmpproposal_spec
916 yyerror("strength directive is obsoleted.");
918 | LIFETIME LIFETYPE_TIME NUMBER unittype_time
920 prhead->spspec->lifetime = $3 * $4;
923 | LIFETIME LIFETYPE_BYTE NUMBER unittype_byte
926 yyerror("byte lifetime support is deprecated");
929 prhead->spspec->lifebyte = fix_lifebyte($3 * $4);
930 if (prhead->spspec->lifebyte == 0)
935 | DH_GROUP dh_group_num
937 prhead->spspec->algclass[algclass_isakmp_dh] = $2;
940 | GSSAPI_ID QUOTEDSTRING
942 if (prhead->spspec->vendorid != VENDORID_GSSAPI) {
943 yyerror("wrong Vendor ID for gssapi_id");
946 prhead->spspec->gssid = strdup($2->v);
949 | ALGORITHM_CLASS ALGORITHMTYPE keylength
954 doi = algtype2doi($1, $2);
956 yyerror("algorithm mismatched 1");
961 case algclass_isakmp_enc:
962 /* reject suppressed algorithms */
963 #ifndef HAVE_OPENSSL_RC5_H
964 if ($2 == algtype_rc5) {
965 yyerror("algorithm %s not supported",
966 s_attr_isakmp_enc(doi));
970 #ifndef HAVE_OPENSSL_IDEA_H
971 if ($2 == algtype_idea) {
972 yyerror("algorithm %s not supported",
973 s_attr_isakmp_enc(doi));
978 prhead->spspec->algclass[algclass_isakmp_enc] = doi;
979 defklen = default_keylen($1, $2);
982 yyerror("keylen not allowed");
986 if ($3 && check_keylen($1, $2, $3) < 0) {
987 yyerror("invalid keylen %d", $3);
992 prhead->spspec->encklen = $3;
994 prhead->spspec->encklen = defklen;
996 case algclass_isakmp_hash:
997 prhead->spspec->algclass[algclass_isakmp_hash] = doi;
999 case algclass_isakmp_ameth:
1000 prhead->spspec->algclass[algclass_isakmp_ameth] = doi;
1002 * We may have to set the Vendor ID for the
1003 * authentication method we're using.
1006 case algtype_gssapikrb:
1007 if (prhead->spspec->vendorid !=
1009 yyerror("Vendor ID mismatch "
1014 * For interoperability with Win2k,
1015 * we set the Vendor ID to "GSSAPI".
1017 prhead->spspec->vendorid =
1025 yyerror("algorithm mismatched 2");
1033 : UNITTYPE_SEC { $$ = 1; }
1034 | UNITTYPE_MIN { $$ = 60; }
1035 | UNITTYPE_HOUR { $$ = (60 * 60); }
1038 : UNITTYPE_BYTE { $$ = 1; }
1039 | UNITTYPE_KBYTES { $$ = 1024; }
1040 | UNITTYPE_MBYTES { $$ = (1024 * 1024); }
1041 | UNITTYPE_TBYTES { $$ = (1024 * 1024 * 1024); }
1045 static struct proposalspec *
1048 struct proposalspec *new;
1050 new = racoon_calloc(1, sizeof(*new));
1052 yyerror("failed to allocate proposal");
1060 struct proposalspec *p, *next;
1065 for (p = prhead; p != NULL; p = next) {
1066 struct secprotospec *psp, *nextsp;
1067 for (psp = p->spspec; psp; psp = nextsp) {
1069 racoon_free(p->spspec);
1079 * insert into head of list.
1082 insprspec(prspec, head)
1083 struct proposalspec *prspec;
1084 struct proposalspec **head;
1087 (*head)->prev = prspec;
1088 prspec->next = *head;
1092 static struct secprotospec *
1095 struct secprotospec *new;
1097 new = racoon_calloc(1, sizeof(*new));
1099 yyerror("failed to allocate spproto");
1103 new->encklen = 0; /*XXX*/
1106 * Default to "uknown" vendor -- we will override this
1107 * as necessary. When we send a Vendor ID payload, an
1108 * "unknown" will be translated to a KAME/racoon ID.
1110 new->vendorid = VENDORID_UNKNOWN;
1116 * insert into head of list.
1119 insspspec(spspec, head)
1120 struct secprotospec *spspec;
1121 struct proposalspec **head;
1123 spspec->back = *head;
1125 if ((*head)->spspec != NULL)
1126 (*head)->spspec->prev = spspec;
1127 spspec->next = (*head)->spspec;
1128 (*head)->spspec = spspec;
1131 /* set final acceptable proposal */
1133 set_isakmp_proposal(rmconf, prspec)
1134 struct remoteconf *rmconf;
1135 struct proposalspec *prspec;
1137 struct proposalspec *p;
1138 struct secprotospec *s;
1141 u_int32_t types[MAXALGCLASS];
1145 plog(LLV_ERROR, LOCATION, NULL,
1146 "multiple proposal definition.\n");
1150 /* mandatory check */
1151 if (p->spspec == NULL) {
1152 yyerror("no remote specification found: %s.\n",
1156 for (s = p->spspec; s != NULL; s = s->next) {
1157 /* XXX need more to check */
1158 if (s->algclass[algclass_isakmp_enc] == 0) {
1159 yyerror("encryption algorithm required.");
1162 if (s->algclass[algclass_isakmp_hash] == 0) {
1163 yyerror("hash algorithm required.");
1166 if (s->algclass[algclass_isakmp_dh] == 0) {
1167 yyerror("DH group required.");
1170 if (s->algclass[algclass_isakmp_ameth] == 0) {
1171 yyerror("authentication method required.");
1176 /* skip to last part */
1177 for (s = p->spspec; s->next != NULL; s = s->next)
1181 plog(LLV_DEBUG2, LOCATION, NULL,
1182 "lifetime = %ld\n", (long)
1183 (s->lifetime ? s->lifetime : p->lifetime));
1184 plog(LLV_DEBUG2, LOCATION, NULL,
1186 s->lifebyte ? s->lifebyte : p->lifebyte);
1187 plog(LLV_DEBUG2, LOCATION, NULL,
1188 "encklen=%d\n", s->encklen);
1190 memset(types, 0, ARRAYLEN(types));
1191 types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
1192 types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
1193 types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
1194 types[algclass_isakmp_ameth] =
1195 s->algclass[algclass_isakmp_ameth];
1197 /* expanding spspec */
1199 trns_no = expand_isakmpspec(prop_no, trns_no, types,
1200 algclass_isakmp_enc, algclass_isakmp_ameth + 1,
1201 s->lifetime ? s->lifetime : p->lifetime,
1202 s->lifebyte ? s->lifebyte : p->lifebyte,
1203 s->encklen, s->vendorid, s->gssid,
1205 if (trns_no == -1) {
1206 plog(LLV_ERROR, LOCATION, NULL,
1207 "failed to expand isakmp proposal.\n");
1214 if (rmconf->proposal == NULL) {
1215 plog(LLV_ERROR, LOCATION, NULL,
1216 "no proposal found.\n");
1227 for (i = 0; i < MAXALGCLASS; i++)
1228 tmpalgtype[i] = 0; /* means algorithm undefined. */
1232 expand_isakmpspec(prop_no, trns_no, types,
1233 class, last, lifetime, lifebyte, encklen, vendorid, gssid,
1235 int prop_no, trns_no;
1236 int *types, class, last;
1242 struct remoteconf *rmconf;
1244 struct isakmpsa *new;
1250 plog(LLV_DEBUG2, LOCATION, NULL,
1251 "p:%d t:%d\n", prop_no, trns_no);
1252 for (j = class; j < MAXALGCLASS; j++) {
1253 snprintf(tb, sizeof(tb), "%d", types[j]);
1254 plog(LLV_DEBUG2, LOCATION, NULL,
1256 s_algtype(j, types[j]),
1257 types[j] ? "(" : "",
1258 tb[0] == '0' ? "" : tb,
1259 types[j] ? ")" : "");
1261 plog(LLV_DEBUG2, LOCATION, NULL, "\n");
1264 #define TMPALGTYPE2STR(n) \
1265 s_algtype(algclass_isakmp_##n, types[algclass_isakmp_##n])
1266 /* check mandatory values */
1267 if (types[algclass_isakmp_enc] == 0
1268 || types[algclass_isakmp_ameth] == 0
1269 || types[algclass_isakmp_hash] == 0
1270 || types[algclass_isakmp_dh] == 0) {
1271 yyerror("few definition of algorithm "
1272 "enc=%s ameth=%s hash=%s dhgroup=%s.\n",
1273 TMPALGTYPE2STR(enc),
1274 TMPALGTYPE2STR(ameth),
1275 TMPALGTYPE2STR(hash),
1276 TMPALGTYPE2STR(dh));
1279 #undef TMPALGTYPE2STR
1282 new = newisakmpsa();
1284 yyerror("failed to allocate isakmp sa");
1287 new->prop_no = prop_no;
1288 new->trns_no = trns_no++;
1289 new->lifetime = lifetime;
1290 new->lifebyte = lifebyte;
1291 new->enctype = types[algclass_isakmp_enc];
1292 new->encklen = encklen;
1293 new->authmethod = types[algclass_isakmp_ameth];
1294 new->hashtype = types[algclass_isakmp_hash];
1295 new->dh_group = types[algclass_isakmp_dh];
1296 new->vendorid = vendorid;
1298 if (gssid != NULL) {
1299 new->gssid = vmalloc(strlen(gssid) + 1);
1300 memcpy(new->gssid->v, gssid, new->gssid->l);
1305 insisakmpsa(new, rmconf);
1313 * Must be more than 1024B because its unit is kilobytes.
1314 * That is defined RFC2407.
1321 yyerror("byte size should be more than 1024B.");
1329 extern int yyparse(void);
1338 if (yycf_switch_buffer(lcconf->racoon_conf) != 0)
1346 plog(LLV_ERROR, LOCATION, NULL,
1347 "fatal parse failure (%d errors)\n",
1350 plog(LLV_ERROR, LOCATION, NULL,
1351 "fatal parse failure.\n");
1356 if (error == 0 && yyerrorcount) {
1357 plog(LLV_ERROR, LOCATION, NULL,
1358 "parse error is nothing, but yyerrorcount is %d.\n",
1363 yycf_clean_buffer();
1365 plog(LLV_DEBUG2, LOCATION, NULL, "parse successed.\n");