1 /* key-chain for authentication.
2 Copyright (C) 2000 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your
9 option) any later version.
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 DEFINE_MTYPE_STATIC(LIB
, KEY
, "Key")
29 DEFINE_MTYPE_STATIC(LIB
, KEYCHAIN
, "Key chain")
31 DEFINE_QOBJ_TYPE(keychain
)
34 /* Master list of key chain. */
35 struct list
*keychain_list
;
37 static struct keychain
*keychain_new(void)
39 struct keychain
*keychain
;
40 keychain
= XCALLOC(MTYPE_KEYCHAIN
, sizeof(struct keychain
));
41 QOBJ_REG(keychain
, keychain
);
45 static void keychain_free(struct keychain
*keychain
)
48 XFREE(MTYPE_KEYCHAIN
, keychain
);
51 static struct key
*key_new(void)
53 struct key
*key
= XCALLOC(MTYPE_KEY
, sizeof(struct key
));
58 static void key_free(struct key
*key
)
61 XFREE(MTYPE_KEY
, key
);
64 struct keychain
*keychain_lookup(const char *name
)
66 struct listnode
*node
;
67 struct keychain
*keychain
;
72 for (ALL_LIST_ELEMENTS_RO(keychain_list
, node
, keychain
)) {
73 if (strcmp(keychain
->name
, name
) == 0)
79 static int key_cmp_func(void *arg1
, void *arg2
)
81 const struct key
*k1
= arg1
;
82 const struct key
*k2
= arg2
;
84 if (k1
->index
> k2
->index
)
86 if (k1
->index
< k2
->index
)
91 static void key_delete_func(struct key
*key
)
98 static struct keychain
*keychain_get(const char *name
)
100 struct keychain
*keychain
;
102 keychain
= keychain_lookup(name
);
107 keychain
= keychain_new();
108 keychain
->name
= XSTRDUP(MTYPE_KEYCHAIN
, name
);
109 keychain
->key
= list_new();
110 keychain
->key
->cmp
= (int (*)(void *, void *))key_cmp_func
;
111 keychain
->key
->del
= (void (*)(void *))key_delete_func
;
112 listnode_add(keychain_list
, keychain
);
117 static void keychain_delete(struct keychain
*keychain
)
120 XFREE(MTYPE_KEYCHAIN
, keychain
->name
);
122 list_delete(keychain
->key
);
123 listnode_delete(keychain_list
, keychain
);
124 keychain_free(keychain
);
127 static struct key
*key_lookup(const struct keychain
*keychain
, u_int32_t index
)
129 struct listnode
*node
;
132 for (ALL_LIST_ELEMENTS_RO(keychain
->key
, node
, key
)) {
133 if (key
->index
== index
)
139 struct key
*key_lookup_for_accept(const struct keychain
*keychain
,
142 struct listnode
*node
;
148 for (ALL_LIST_ELEMENTS_RO(keychain
->key
, node
, key
)) {
149 if (key
->index
>= index
) {
150 if (key
->accept
.start
== 0)
153 if (key
->accept
.start
<= now
)
154 if (key
->accept
.end
>= now
155 || key
->accept
.end
== -1)
162 struct key
*key_match_for_accept(const struct keychain
*keychain
,
163 const char *auth_str
)
165 struct listnode
*node
;
171 for (ALL_LIST_ELEMENTS_RO(keychain
->key
, node
, key
)) {
172 if (key
->accept
.start
== 0
173 || (key
->accept
.start
<= now
174 && (key
->accept
.end
>= now
|| key
->accept
.end
== -1)))
175 if (strncmp(key
->string
, auth_str
, 16) == 0)
181 struct key
*key_lookup_for_send(const struct keychain
*keychain
)
183 struct listnode
*node
;
189 for (ALL_LIST_ELEMENTS_RO(keychain
->key
, node
, key
)) {
190 if (key
->send
.start
== 0)
193 if (key
->send
.start
<= now
)
194 if (key
->send
.end
>= now
|| key
->send
.end
== -1)
200 static struct key
*key_get(const struct keychain
*keychain
, u_int32_t index
)
204 key
= key_lookup(keychain
, index
);
211 listnode_add_sort(keychain
->key
, key
);
216 static void key_delete(struct keychain
*keychain
, struct key
*key
)
218 listnode_delete(keychain
->key
, key
);
221 XFREE(MTYPE_KEY
, key
->string
);
225 DEFUN_NOSH (key_chain
,
228 "Authentication key management\n"
229 "Key-chain management\n"
233 struct keychain
*keychain
;
235 keychain
= keychain_get(argv
[idx_word
]->arg
);
236 VTY_PUSH_CONTEXT(KEYCHAIN_NODE
, keychain
);
245 "Authentication key management\n"
246 "Key-chain management\n"
250 struct keychain
*keychain
;
252 keychain
= keychain_lookup(argv
[idx_word
]->arg
);
255 vty_out(vty
, "Can't find keychain %s%s", argv
[idx_word
]->arg
,
260 keychain_delete(keychain
);
267 "key (0-2147483647)",
269 "Key identifier number\n")
272 VTY_DECLVAR_CONTEXT(keychain
, keychain
);
276 VTY_GET_INTEGER("key identifier", index
, argv
[idx_number
]->arg
);
277 key
= key_get(keychain
, index
);
278 VTY_PUSH_CONTEXT_SUB(KEYCHAIN_KEY_NODE
, key
);
285 "no key (0-2147483647)",
288 "Key identifier number\n")
291 VTY_DECLVAR_CONTEXT(keychain
, keychain
);
295 VTY_GET_INTEGER("key identifier", index
, argv
[idx_number
]->arg
);
296 key
= key_lookup(keychain
, index
);
298 vty_out(vty
, "Can't find key %d%s", index
, VTY_NEWLINE
);
302 key_delete(keychain
, key
);
304 vty
->node
= KEYCHAIN_NODE
;
316 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
319 XFREE(MTYPE_KEY
, key
->string
);
320 key
->string
= XSTRDUP(MTYPE_KEY
, argv
[idx_line
]->arg
);
325 DEFUN (no_key_string
,
327 "no key-string [LINE]",
332 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
335 XFREE(MTYPE_KEY
, key
->string
);
342 /* Convert HH:MM:SS MON DAY YEAR to time_t value. -1 is returned when
343 given string is malformed. */
344 static time_t key_str2time(const char *time_str
, const char *day_str
,
345 const char *month_str
, const char *year_str
)
351 unsigned int sec
, min
, hour
;
352 unsigned int day
, month
, year
;
354 const char *month_name
[] = {
355 "January", "February", "March", "April", "May",
356 "June", "July", "August", "September", "October",
357 "November", "December", NULL
};
359 #define _GET_LONG_RANGE(V, STR, MMCOND) \
361 unsigned long tmpl; \
362 char *endptr = NULL; \
363 tmpl = strtoul((STR), &endptr, 10); \
364 if (*endptr != '\0' || tmpl == ULONG_MAX) \
370 #define GET_LONG_RANGE(V, STR, MIN, MAX) \
371 _GET_LONG_RANGE(V, STR, tmpl<(MIN) || tmpl>(MAX))
372 #define GET_LONG_RANGE0(V, STR, MAX) _GET_LONG_RANGE(V, STR, tmpl > (MAX))
374 /* Check hour field of time_str. */
375 colon
= strchr(time_str
, ':');
380 /* Hour must be between 0 and 23. */
381 GET_LONG_RANGE0(hour
, time_str
, 23);
383 /* Check min field of time_str. */
384 time_str
= colon
+ 1;
385 colon
= strchr(time_str
, ':');
386 if (*time_str
== '\0' || colon
== NULL
)
390 /* Min must be between 0 and 59. */
391 GET_LONG_RANGE0(min
, time_str
, 59);
393 /* Check sec field of time_str. */
394 time_str
= colon
+ 1;
395 if (*time_str
== '\0')
398 /* Sec must be between 0 and 59. */
399 GET_LONG_RANGE0(sec
, time_str
, 59);
401 /* Check day_str. Day must be <1-31>. */
402 GET_LONG_RANGE(day
, day_str
, 1, 31);
404 /* Check month_str. Month must match month_name. */
406 if (strlen(month_str
) >= 3)
407 for (i
= 0; month_name
[i
]; i
++)
408 if (strncmp(month_str
, month_name
[i
], strlen(month_str
))
416 /* Check year_str. Year must be <1993-2035>. */
417 GET_LONG_RANGE(year
, year_str
, 1993, 2035);
419 memset(&tm
, 0, sizeof(struct tm
));
425 tm
.tm_year
= year
- 1900;
430 #undef GET_LONG_RANGE
433 static int key_lifetime_set(struct vty
*vty
, struct key_range
*krange
,
434 const char *stime_str
, const char *sday_str
,
435 const char *smonth_str
, const char *syear_str
,
436 const char *etime_str
, const char *eday_str
,
437 const char *emonth_str
, const char *eyear_str
)
442 time_start
= key_str2time(stime_str
, sday_str
, smonth_str
, syear_str
);
443 if (time_start
< 0) {
444 vty_out(vty
, "Malformed time value%s", VTY_NEWLINE
);
447 time_end
= key_str2time(etime_str
, eday_str
, emonth_str
, eyear_str
);
450 vty_out(vty
, "Malformed time value%s", VTY_NEWLINE
);
454 if (time_end
<= time_start
) {
455 vty_out(vty
, "Expire time is not later than start time%s",
460 krange
->start
= time_start
;
461 krange
->end
= time_end
;
466 static int key_lifetime_duration_set(struct vty
*vty
, struct key_range
*krange
,
467 const char *stime_str
,
468 const char *sday_str
,
469 const char *smonth_str
,
470 const char *syear_str
,
471 const char *duration_str
)
476 time_start
= key_str2time(stime_str
, sday_str
, smonth_str
, syear_str
);
477 if (time_start
< 0) {
478 vty_out(vty
, "Malformed time value%s", VTY_NEWLINE
);
481 krange
->start
= time_start
;
483 VTY_GET_INTEGER("duration", duration
, duration_str
);
484 krange
->duration
= 1;
485 krange
->end
= time_start
+ duration
;
490 static int key_lifetime_infinite_set(struct vty
*vty
, struct key_range
*krange
,
491 const char *stime_str
,
492 const char *sday_str
,
493 const char *smonth_str
,
494 const char *syear_str
)
498 time_start
= key_str2time(stime_str
, sday_str
, smonth_str
, syear_str
);
499 if (time_start
< 0) {
500 vty_out(vty
, "Malformed time value%s", VTY_NEWLINE
);
503 krange
->start
= time_start
;
510 DEFUN (accept_lifetime_day_month_day_month
,
511 accept_lifetime_day_month_day_month_cmd
,
512 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
513 "Set accept lifetime of the key\n"
515 "Day of th month to start\n"
516 "Month of the year to start\n"
519 "Day of th month to expire\n"
520 "Month of the year to expire\n"
526 int idx_number_2
= 4;
527 int idx_hhmmss_2
= 5;
528 int idx_number_3
= 6;
530 int idx_number_4
= 8;
531 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
533 return key_lifetime_set(
534 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
535 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
536 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
537 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
540 DEFUN (accept_lifetime_day_month_month_day
,
541 accept_lifetime_day_month_month_day_cmd
,
542 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
543 "Set accept lifetime of the key\n"
545 "Day of th month to start\n"
546 "Month of the year to start\n"
549 "Month of the year to expire\n"
550 "Day of th month to expire\n"
556 int idx_number_2
= 4;
557 int idx_hhmmss_2
= 5;
559 int idx_number_3
= 7;
560 int idx_number_4
= 8;
561 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
563 return key_lifetime_set(
564 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
565 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
566 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
567 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
570 DEFUN (accept_lifetime_month_day_day_month
,
571 accept_lifetime_month_day_day_month_cmd
,
572 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
573 "Set accept lifetime of the key\n"
575 "Month of the year to start\n"
576 "Day of th month to start\n"
579 "Day of th month to expire\n"
580 "Month of the year to expire\n"
586 int idx_number_2
= 4;
587 int idx_hhmmss_2
= 5;
588 int idx_number_3
= 6;
590 int idx_number_4
= 8;
591 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
593 return key_lifetime_set(
594 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
595 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
596 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
597 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
600 DEFUN (accept_lifetime_month_day_month_day
,
601 accept_lifetime_month_day_month_day_cmd
,
602 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
603 "Set accept lifetime of the key\n"
605 "Month of the year to start\n"
606 "Day of th month to start\n"
609 "Month of the year to expire\n"
610 "Day of th month to expire\n"
616 int idx_number_2
= 4;
617 int idx_hhmmss_2
= 5;
619 int idx_number_3
= 7;
620 int idx_number_4
= 8;
621 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
623 return key_lifetime_set(
624 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
625 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
626 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
627 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
630 DEFUN (accept_lifetime_infinite_day_month
,
631 accept_lifetime_infinite_day_month_cmd
,
632 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) infinite",
633 "Set accept lifetime of the key\n"
635 "Day of th month to start\n"
636 "Month of the year to start\n"
643 int idx_number_2
= 4;
644 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
646 return key_lifetime_infinite_set(
647 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
648 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
);
651 DEFUN (accept_lifetime_infinite_month_day
,
652 accept_lifetime_infinite_month_day_cmd
,
653 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) infinite",
654 "Set accept lifetime of the key\n"
656 "Month of the year to start\n"
657 "Day of th month to start\n"
664 int idx_number_2
= 4;
665 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
667 return key_lifetime_infinite_set(
668 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
669 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
);
672 DEFUN (accept_lifetime_duration_day_month
,
673 accept_lifetime_duration_day_month_cmd
,
674 "accept-lifetime HH:MM:SS (1-31) MONTH (1993-2035) duration (1-2147483646)",
675 "Set accept lifetime of the key\n"
677 "Day of th month to start\n"
678 "Month of the year to start\n"
680 "Duration of the key\n"
681 "Duration seconds\n")
686 int idx_number_2
= 4;
687 int idx_number_3
= 6;
688 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
690 return key_lifetime_duration_set(
691 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
692 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
693 argv
[idx_number_3
]->arg
);
696 DEFUN (accept_lifetime_duration_month_day
,
697 accept_lifetime_duration_month_day_cmd
,
698 "accept-lifetime HH:MM:SS MONTH (1-31) (1993-2035) duration (1-2147483646)",
699 "Set accept lifetime of the key\n"
701 "Month of the year to start\n"
702 "Day of th month to start\n"
704 "Duration of the key\n"
705 "Duration seconds\n")
710 int idx_number_2
= 4;
711 int idx_number_3
= 6;
712 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
714 return key_lifetime_duration_set(
715 vty
, &key
->accept
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
716 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
717 argv
[idx_number_3
]->arg
);
720 DEFUN (send_lifetime_day_month_day_month
,
721 send_lifetime_day_month_day_month_cmd
,
722 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
723 "Set send lifetime of the key\n"
725 "Day of th month to start\n"
726 "Month of the year to start\n"
729 "Day of th month to expire\n"
730 "Month of the year to expire\n"
736 int idx_number_2
= 4;
737 int idx_hhmmss_2
= 5;
738 int idx_number_3
= 6;
740 int idx_number_4
= 8;
741 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
743 return key_lifetime_set(
744 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
745 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
746 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
747 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
750 DEFUN (send_lifetime_day_month_month_day
,
751 send_lifetime_day_month_month_day_cmd
,
752 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
753 "Set send lifetime of the key\n"
755 "Day of th month to start\n"
756 "Month of the year to start\n"
759 "Month of the year to expire\n"
760 "Day of th month to expire\n"
766 int idx_number_2
= 4;
767 int idx_hhmmss_2
= 5;
769 int idx_number_3
= 7;
770 int idx_number_4
= 8;
771 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
773 return key_lifetime_set(
774 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
775 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
776 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
777 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
780 DEFUN (send_lifetime_month_day_day_month
,
781 send_lifetime_month_day_day_month_cmd
,
782 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS (1-31) MONTH (1993-2035)",
783 "Set send lifetime of the key\n"
785 "Month of the year to start\n"
786 "Day of th month to start\n"
789 "Day of th month to expire\n"
790 "Month of the year to expire\n"
796 int idx_number_2
= 4;
797 int idx_hhmmss_2
= 5;
798 int idx_number_3
= 6;
800 int idx_number_4
= 8;
801 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
803 return key_lifetime_set(
804 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
805 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
806 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
807 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
810 DEFUN (send_lifetime_month_day_month_day
,
811 send_lifetime_month_day_month_day_cmd
,
812 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) HH:MM:SS MONTH (1-31) (1993-2035)",
813 "Set send lifetime of the key\n"
815 "Month of the year to start\n"
816 "Day of th month to start\n"
819 "Month of the year to expire\n"
820 "Day of th month to expire\n"
826 int idx_number_2
= 4;
827 int idx_hhmmss_2
= 5;
829 int idx_number_3
= 7;
830 int idx_number_4
= 8;
831 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
833 return key_lifetime_set(
834 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
835 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
836 argv
[idx_hhmmss_2
]->arg
, argv
[idx_number_3
]->arg
,
837 argv
[idx_month_2
]->arg
, argv
[idx_number_4
]->arg
);
840 DEFUN (send_lifetime_infinite_day_month
,
841 send_lifetime_infinite_day_month_cmd
,
842 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) infinite",
843 "Set send lifetime of the key\n"
845 "Day of th month to start\n"
846 "Month of the year to start\n"
853 int idx_number_2
= 4;
854 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
856 return key_lifetime_infinite_set(
857 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
858 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
);
861 DEFUN (send_lifetime_infinite_month_day
,
862 send_lifetime_infinite_month_day_cmd
,
863 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) infinite",
864 "Set send lifetime of the key\n"
866 "Month of the year to start\n"
867 "Day of th month to start\n"
874 int idx_number_2
= 4;
875 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
877 return key_lifetime_infinite_set(
878 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
879 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
);
882 DEFUN (send_lifetime_duration_day_month
,
883 send_lifetime_duration_day_month_cmd
,
884 "send-lifetime HH:MM:SS (1-31) MONTH (1993-2035) duration (1-2147483646)",
885 "Set send lifetime of the key\n"
887 "Day of th month to start\n"
888 "Month of the year to start\n"
890 "Duration of the key\n"
891 "Duration seconds\n")
896 int idx_number_2
= 4;
897 int idx_number_3
= 6;
898 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
900 return key_lifetime_duration_set(
901 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
902 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
903 argv
[idx_number_3
]->arg
);
906 DEFUN (send_lifetime_duration_month_day
,
907 send_lifetime_duration_month_day_cmd
,
908 "send-lifetime HH:MM:SS MONTH (1-31) (1993-2035) duration (1-2147483646)",
909 "Set send lifetime of the key\n"
911 "Month of the year to start\n"
912 "Day of th month to start\n"
914 "Duration of the key\n"
915 "Duration seconds\n")
920 int idx_number_2
= 4;
921 int idx_number_3
= 6;
922 VTY_DECLVAR_CONTEXT_SUB(key
, key
);
924 return key_lifetime_duration_set(
925 vty
, &key
->send
, argv
[idx_hhmmss
]->arg
, argv
[idx_number
]->arg
,
926 argv
[idx_month
]->arg
, argv
[idx_number_2
]->arg
,
927 argv
[idx_number_3
]->arg
);
930 static struct cmd_node keychain_node
= {KEYCHAIN_NODE
, "%s(config-keychain)# ",
933 static struct cmd_node keychain_key_node
= {KEYCHAIN_KEY_NODE
,
934 "%s(config-keychain-key)# ", 1};
936 static int keychain_strftime(char *buf
, int bufsiz
, time_t *time
)
941 tm
= localtime(time
);
943 len
= strftime(buf
, bufsiz
, "%T %b %d %Y", tm
);
948 static int keychain_config_write(struct vty
*vty
)
950 struct keychain
*keychain
;
952 struct listnode
*node
;
953 struct listnode
*knode
;
956 for (ALL_LIST_ELEMENTS_RO(keychain_list
, node
, keychain
)) {
957 vty_out(vty
, "key chain %s%s", keychain
->name
, VTY_NEWLINE
);
959 for (ALL_LIST_ELEMENTS_RO(keychain
->key
, knode
, key
)) {
960 vty_out(vty
, " key %d%s", key
->index
, VTY_NEWLINE
);
963 vty_out(vty
, " key-string %s%s", key
->string
,
966 if (key
->accept
.start
) {
967 keychain_strftime(buf
, BUFSIZ
,
969 vty_out(vty
, " accept-lifetime %s", buf
);
971 if (key
->accept
.end
== -1)
972 vty_out(vty
, " infinite");
973 else if (key
->accept
.duration
)
974 vty_out(vty
, " duration %ld",
975 (long)(key
->accept
.end
976 - key
->accept
.start
));
978 keychain_strftime(buf
, BUFSIZ
,
980 vty_out(vty
, " %s", buf
);
982 vty_out(vty
, "%s", VTY_NEWLINE
);
985 if (key
->send
.start
) {
986 keychain_strftime(buf
, BUFSIZ
,
988 vty_out(vty
, " send-lifetime %s", buf
);
990 if (key
->send
.end
== -1)
991 vty_out(vty
, " infinite");
992 else if (key
->send
.duration
)
993 vty_out(vty
, " duration %ld",
997 keychain_strftime(buf
, BUFSIZ
,
999 vty_out(vty
, " %s", buf
);
1001 vty_out(vty
, "%s", VTY_NEWLINE
);
1004 vty_out(vty
, "!%s", VTY_NEWLINE
);
1010 void keychain_init()
1012 keychain_list
= list_new();
1014 install_node(&keychain_node
, keychain_config_write
);
1015 install_node(&keychain_key_node
, NULL
);
1017 install_default(KEYCHAIN_NODE
);
1018 install_default(KEYCHAIN_KEY_NODE
);
1020 install_element(CONFIG_NODE
, &key_chain_cmd
);
1021 install_element(CONFIG_NODE
, &no_key_chain_cmd
);
1022 install_element(KEYCHAIN_NODE
, &key_cmd
);
1023 install_element(KEYCHAIN_NODE
, &no_key_cmd
);
1025 install_element(KEYCHAIN_NODE
, &key_chain_cmd
);
1026 install_element(KEYCHAIN_NODE
, &no_key_chain_cmd
);
1028 install_element(KEYCHAIN_KEY_NODE
, &key_string_cmd
);
1029 install_element(KEYCHAIN_KEY_NODE
, &no_key_string_cmd
);
1031 install_element(KEYCHAIN_KEY_NODE
, &key_chain_cmd
);
1032 install_element(KEYCHAIN_KEY_NODE
, &no_key_chain_cmd
);
1034 install_element(KEYCHAIN_KEY_NODE
, &key_cmd
);
1035 install_element(KEYCHAIN_KEY_NODE
, &no_key_cmd
);
1037 install_element(KEYCHAIN_KEY_NODE
,
1038 &accept_lifetime_day_month_day_month_cmd
);
1039 install_element(KEYCHAIN_KEY_NODE
,
1040 &accept_lifetime_day_month_month_day_cmd
);
1041 install_element(KEYCHAIN_KEY_NODE
,
1042 &accept_lifetime_month_day_day_month_cmd
);
1043 install_element(KEYCHAIN_KEY_NODE
,
1044 &accept_lifetime_month_day_month_day_cmd
);
1045 install_element(KEYCHAIN_KEY_NODE
,
1046 &accept_lifetime_infinite_day_month_cmd
);
1047 install_element(KEYCHAIN_KEY_NODE
,
1048 &accept_lifetime_infinite_month_day_cmd
);
1049 install_element(KEYCHAIN_KEY_NODE
,
1050 &accept_lifetime_duration_day_month_cmd
);
1051 install_element(KEYCHAIN_KEY_NODE
,
1052 &accept_lifetime_duration_month_day_cmd
);
1054 install_element(KEYCHAIN_KEY_NODE
,
1055 &send_lifetime_day_month_day_month_cmd
);
1056 install_element(KEYCHAIN_KEY_NODE
,
1057 &send_lifetime_day_month_month_day_cmd
);
1058 install_element(KEYCHAIN_KEY_NODE
,
1059 &send_lifetime_month_day_day_month_cmd
);
1060 install_element(KEYCHAIN_KEY_NODE
,
1061 &send_lifetime_month_day_month_day_cmd
);
1062 install_element(KEYCHAIN_KEY_NODE
,
1063 &send_lifetime_infinite_day_month_cmd
);
1064 install_element(KEYCHAIN_KEY_NODE
,
1065 &send_lifetime_infinite_month_day_cmd
);
1066 install_element(KEYCHAIN_KEY_NODE
,
1067 &send_lifetime_duration_day_month_cmd
);
1068 install_element(KEYCHAIN_KEY_NODE
,
1069 &send_lifetime_duration_month_day_cmd
);