pfkey.c (d570044ce1552a68faccc81562a6209afd0f5e65) pfkey.c (5666643a95389e3ea7637b86cc556d411242f71e)
1/* $KAME: pfkey.c,v 1.46 2003/08/26 03:37:06 itojun Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7 * All rights reserved.
8 *

--- 328 unchanged lines hidden (view full) ---

337
338 return ~0;
339}
340
341/*
342 * sending SADB_GETSPI message to the kernel.
343 * OUT:
344 * positive: success and return length sent.
1/* $KAME: pfkey.c,v 1.46 2003/08/26 03:37:06 itojun Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7 * All rights reserved.
8 *

--- 328 unchanged lines hidden (view full) ---

337
338 return ~0;
339}
340
341/*
342 * sending SADB_GETSPI message to the kernel.
343 * OUT:
344 * positive: success and return length sent.
345 * -1 : error occured, and set errno.
345 * -1 : error occurred, and set errno.
346 */
347int
348pfkey_send_getspi(so, satype, mode, src, dst, min, max, reqid, seq)
349 int so;
350 u_int satype, mode;
351 struct sockaddr *src, *dst;
352 u_int32_t min, max, reqid, seq;
353{

--- 112 unchanged lines hidden (view full) ---

466 return len;
467}
468
469/*
470 * sending SADB_UPDATE message to the kernel.
471 * The length of key material is a_keylen + e_keylen.
472 * OUT:
473 * positive: success and return length sent.
346 */
347int
348pfkey_send_getspi(so, satype, mode, src, dst, min, max, reqid, seq)
349 int so;
350 u_int satype, mode;
351 struct sockaddr *src, *dst;
352 u_int32_t min, max, reqid, seq;
353{

--- 112 unchanged lines hidden (view full) ---

466 return len;
467}
468
469/*
470 * sending SADB_UPDATE message to the kernel.
471 * The length of key material is a_keylen + e_keylen.
472 * OUT:
473 * positive: success and return length sent.
474 * -1 : error occured, and set errno.
474 * -1 : error occurred, and set errno.
475 */
476int
477pfkey_send_update(so, satype, mode, src, dst, spi, reqid, wsize,
478 keymat, e_type, e_keylen, a_type, a_keylen, flags,
479 l_alloc, l_bytes, l_addtime, l_usetime, seq)
480 int so;
481 u_int satype, mode, wsize;
482 struct sockaddr *src, *dst;

--- 14 unchanged lines hidden (view full) ---

497 return len;
498}
499
500/*
501 * sending SADB_ADD message to the kernel.
502 * The length of key material is a_keylen + e_keylen.
503 * OUT:
504 * positive: success and return length sent.
475 */
476int
477pfkey_send_update(so, satype, mode, src, dst, spi, reqid, wsize,
478 keymat, e_type, e_keylen, a_type, a_keylen, flags,
479 l_alloc, l_bytes, l_addtime, l_usetime, seq)
480 int so;
481 u_int satype, mode, wsize;
482 struct sockaddr *src, *dst;

--- 14 unchanged lines hidden (view full) ---

497 return len;
498}
499
500/*
501 * sending SADB_ADD message to the kernel.
502 * The length of key material is a_keylen + e_keylen.
503 * OUT:
504 * positive: success and return length sent.
505 * -1 : error occured, and set errno.
505 * -1 : error occurred, and set errno.
506 */
507int
508pfkey_send_add(so, satype, mode, src, dst, spi, reqid, wsize,
509 keymat, e_type, e_keylen, a_type, a_keylen, flags,
510 l_alloc, l_bytes, l_addtime, l_usetime, seq)
511 int so;
512 u_int satype, mode, wsize;
513 struct sockaddr *src, *dst;

--- 13 unchanged lines hidden (view full) ---

527
528 return len;
529}
530
531/*
532 * sending SADB_DELETE message to the kernel.
533 * OUT:
534 * positive: success and return length sent.
506 */
507int
508pfkey_send_add(so, satype, mode, src, dst, spi, reqid, wsize,
509 keymat, e_type, e_keylen, a_type, a_keylen, flags,
510 l_alloc, l_bytes, l_addtime, l_usetime, seq)
511 int so;
512 u_int satype, mode, wsize;
513 struct sockaddr *src, *dst;

--- 13 unchanged lines hidden (view full) ---

527
528 return len;
529}
530
531/*
532 * sending SADB_DELETE message to the kernel.
533 * OUT:
534 * positive: success and return length sent.
535 * -1 : error occured, and set errno.
535 * -1 : error occurred, and set errno.
536 */
537int
538pfkey_send_delete(so, satype, mode, src, dst, spi)
539 int so;
540 u_int satype, mode;
541 struct sockaddr *src, *dst;
542 u_int32_t spi;
543{

--- 6 unchanged lines hidden (view full) ---

550
551/*
552 * sending SADB_DELETE without spi to the kernel. This is
553 * the "delete all" request (an extension also present in
554 * Solaris).
555 *
556 * OUT:
557 * positive: success and return length sent
536 */
537int
538pfkey_send_delete(so, satype, mode, src, dst, spi)
539 int so;
540 u_int satype, mode;
541 struct sockaddr *src, *dst;
542 u_int32_t spi;
543{

--- 6 unchanged lines hidden (view full) ---

550
551/*
552 * sending SADB_DELETE without spi to the kernel. This is
553 * the "delete all" request (an extension also present in
554 * Solaris).
555 *
556 * OUT:
557 * positive: success and return length sent
558 * -1 : error occured, and set errno
558 * -1 : error occurred, and set errno
559 */
560int
561pfkey_send_delete_all(so, satype, mode, src, dst)
562 int so;
563 u_int satype, mode;
564 struct sockaddr *src, *dst;
565{
566 struct sadb_msg *newmsg;

--- 65 unchanged lines hidden (view full) ---

632 __ipsec_errcode = EIPSEC_NO_ERROR;
633 return len;
634}
635
636/*
637 * sending SADB_GET message to the kernel.
638 * OUT:
639 * positive: success and return length sent.
559 */
560int
561pfkey_send_delete_all(so, satype, mode, src, dst)
562 int so;
563 u_int satype, mode;
564 struct sockaddr *src, *dst;
565{
566 struct sadb_msg *newmsg;

--- 65 unchanged lines hidden (view full) ---

632 __ipsec_errcode = EIPSEC_NO_ERROR;
633 return len;
634}
635
636/*
637 * sending SADB_GET message to the kernel.
638 * OUT:
639 * positive: success and return length sent.
640 * -1 : error occured, and set errno.
640 * -1 : error occurred, and set errno.
641 */
642int
643pfkey_send_get(so, satype, mode, src, dst, spi)
644 int so;
645 u_int satype, mode;
646 struct sockaddr *src, *dst;
647 u_int32_t spi;
648{
649 int len;
650 if ((len = pfkey_send_x2(so, SADB_GET, satype, mode, src, dst, spi)) < 0)
651 return -1;
652
653 return len;
654}
655
656/*
657 * sending SADB_REGISTER message to the kernel.
658 * OUT:
659 * positive: success and return length sent.
641 */
642int
643pfkey_send_get(so, satype, mode, src, dst, spi)
644 int so;
645 u_int satype, mode;
646 struct sockaddr *src, *dst;
647 u_int32_t spi;
648{
649 int len;
650 if ((len = pfkey_send_x2(so, SADB_GET, satype, mode, src, dst, spi)) < 0)
651 return -1;
652
653 return len;
654}
655
656/*
657 * sending SADB_REGISTER message to the kernel.
658 * OUT:
659 * positive: success and return length sent.
660 * -1 : error occured, and set errno.
660 * -1 : error occurred, and set errno.
661 */
662int
663pfkey_send_register(so, satype)
664 int so;
665 u_int satype;
666{
667 int len, algno;
668

--- 25 unchanged lines hidden (view full) ---

694 return len;
695}
696
697/*
698 * receiving SADB_REGISTER message from the kernel, and copy buffer for
699 * sadb_supported returned into ipsec_supported.
700 * OUT:
701 * 0: success and return length sent.
661 */
662int
663pfkey_send_register(so, satype)
664 int so;
665 u_int satype;
666{
667 int len, algno;
668

--- 25 unchanged lines hidden (view full) ---

694 return len;
695}
696
697/*
698 * receiving SADB_REGISTER message from the kernel, and copy buffer for
699 * sadb_supported returned into ipsec_supported.
700 * OUT:
701 * 0: success and return length sent.
702 * -1: error occured, and set errno.
702 * -1: error occurred, and set errno.
703 */
704int
705pfkey_recv_register(so)
706 int so;
707{
708 pid_t pid = getpid();
709 struct sadb_msg *newmsg;
710 int error = -1;

--- 23 unchanged lines hidden (view full) ---

734/*
735 * receiving SADB_REGISTER message from the kernel, and copy buffer for
736 * sadb_supported returned into ipsec_supported.
737 * NOTE: sadb_msg_len must be host order.
738 * IN:
739 * tlen: msg length, it's to makeing sure.
740 * OUT:
741 * 0: success and return length sent.
703 */
704int
705pfkey_recv_register(so)
706 int so;
707{
708 pid_t pid = getpid();
709 struct sadb_msg *newmsg;
710 int error = -1;

--- 23 unchanged lines hidden (view full) ---

734/*
735 * receiving SADB_REGISTER message from the kernel, and copy buffer for
736 * sadb_supported returned into ipsec_supported.
737 * NOTE: sadb_msg_len must be host order.
738 * IN:
739 * tlen: msg length, it's to makeing sure.
740 * OUT:
741 * 0: success and return length sent.
742 * -1: error occured, and set errno.
742 * -1: error occurred, and set errno.
743 */
744int
745pfkey_set_supported(msg, tlen)
746 struct sadb_msg *msg;
747 int tlen;
748{
749 struct sadb_supported *sup;
750 caddr_t p;

--- 47 unchanged lines hidden (view full) ---

798
799 return 0;
800}
801
802/*
803 * sending SADB_FLUSH message to the kernel.
804 * OUT:
805 * positive: success and return length sent.
743 */
744int
745pfkey_set_supported(msg, tlen)
746 struct sadb_msg *msg;
747 int tlen;
748{
749 struct sadb_supported *sup;
750 caddr_t p;

--- 47 unchanged lines hidden (view full) ---

798
799 return 0;
800}
801
802/*
803 * sending SADB_FLUSH message to the kernel.
804 * OUT:
805 * positive: success and return length sent.
806 * -1 : error occured, and set errno.
806 * -1 : error occurred, and set errno.
807 */
808int
809pfkey_send_flush(so, satype)
810 int so;
811 u_int satype;
812{
813 int len;
814
815 if ((len = pfkey_send_x3(so, SADB_FLUSH, satype)) < 0)
816 return -1;
817
818 return len;
819}
820
821/*
822 * sending SADB_DUMP message to the kernel.
823 * OUT:
824 * positive: success and return length sent.
807 */
808int
809pfkey_send_flush(so, satype)
810 int so;
811 u_int satype;
812{
813 int len;
814
815 if ((len = pfkey_send_x3(so, SADB_FLUSH, satype)) < 0)
816 return -1;
817
818 return len;
819}
820
821/*
822 * sending SADB_DUMP message to the kernel.
823 * OUT:
824 * positive: success and return length sent.
825 * -1 : error occured, and set errno.
825 * -1 : error occurred, and set errno.
826 */
827int
828pfkey_send_dump(so, satype)
829 int so;
830 u_int satype;
831{
832 int len;
833

--- 5 unchanged lines hidden (view full) ---

839
840/*
841 * sending SADB_X_PROMISC message to the kernel.
842 * NOTE that this function handles promisc mode toggle only.
843 * IN:
844 * flag: set promisc off if zero, set promisc on if non-zero.
845 * OUT:
846 * positive: success and return length sent.
826 */
827int
828pfkey_send_dump(so, satype)
829 int so;
830 u_int satype;
831{
832 int len;
833

--- 5 unchanged lines hidden (view full) ---

839
840/*
841 * sending SADB_X_PROMISC message to the kernel.
842 * NOTE that this function handles promisc mode toggle only.
843 * IN:
844 * flag: set promisc off if zero, set promisc on if non-zero.
845 * OUT:
846 * positive: success and return length sent.
847 * -1 : error occured, and set errno.
848 * 0 : error occured, and set errno.
847 * -1 : error occurred, and set errno.
848 * 0 : error occurred, and set errno.
849 * others: a pointer to new allocated buffer in which supported
850 * algorithms is.
851 */
852int
853pfkey_send_promisc_toggle(so, flag)
854 int so;
855 int flag;
856{

--- 4 unchanged lines hidden (view full) ---

861
862 return len;
863}
864
865/*
866 * sending SADB_X_SPDADD message to the kernel.
867 * OUT:
868 * positive: success and return length sent.
849 * others: a pointer to new allocated buffer in which supported
850 * algorithms is.
851 */
852int
853pfkey_send_promisc_toggle(so, flag)
854 int so;
855 int flag;
856{

--- 4 unchanged lines hidden (view full) ---

861
862 return len;
863}
864
865/*
866 * sending SADB_X_SPDADD message to the kernel.
867 * OUT:
868 * positive: success and return length sent.
869 * -1 : error occured, and set errno.
869 * -1 : error occurred, and set errno.
870 */
871int
872pfkey_send_spdadd(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
873 int so;
874 struct sockaddr *src, *dst;
875 u_int prefs, prefd, proto;
876 caddr_t policy;
877 int policylen;

--- 9 unchanged lines hidden (view full) ---

887
888 return len;
889}
890
891/*
892 * sending SADB_X_SPDADD message to the kernel.
893 * OUT:
894 * positive: success and return length sent.
870 */
871int
872pfkey_send_spdadd(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
873 int so;
874 struct sockaddr *src, *dst;
875 u_int prefs, prefd, proto;
876 caddr_t policy;
877 int policylen;

--- 9 unchanged lines hidden (view full) ---

887
888 return len;
889}
890
891/*
892 * sending SADB_X_SPDADD message to the kernel.
893 * OUT:
894 * positive: success and return length sent.
895 * -1 : error occured, and set errno.
895 * -1 : error occurred, and set errno.
896 */
897int
898pfkey_send_spdadd2(so, src, prefs, dst, prefd, proto, ltime, vtime,
899 policy, policylen, seq)
900 int so;
901 struct sockaddr *src, *dst;
902 u_int prefs, prefd, proto;
903 u_int64_t ltime, vtime;

--- 11 unchanged lines hidden (view full) ---

915
916 return len;
917}
918
919/*
920 * sending SADB_X_SPDUPDATE message to the kernel.
921 * OUT:
922 * positive: success and return length sent.
896 */
897int
898pfkey_send_spdadd2(so, src, prefs, dst, prefd, proto, ltime, vtime,
899 policy, policylen, seq)
900 int so;
901 struct sockaddr *src, *dst;
902 u_int prefs, prefd, proto;
903 u_int64_t ltime, vtime;

--- 11 unchanged lines hidden (view full) ---

915
916 return len;
917}
918
919/*
920 * sending SADB_X_SPDUPDATE message to the kernel.
921 * OUT:
922 * positive: success and return length sent.
923 * -1 : error occured, and set errno.
923 * -1 : error occurred, and set errno.
924 */
925int
926pfkey_send_spdupdate(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
927 int so;
928 struct sockaddr *src, *dst;
929 u_int prefs, prefd, proto;
930 caddr_t policy;
931 int policylen;

--- 9 unchanged lines hidden (view full) ---

941
942 return len;
943}
944
945/*
946 * sending SADB_X_SPDUPDATE message to the kernel.
947 * OUT:
948 * positive: success and return length sent.
924 */
925int
926pfkey_send_spdupdate(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
927 int so;
928 struct sockaddr *src, *dst;
929 u_int prefs, prefd, proto;
930 caddr_t policy;
931 int policylen;

--- 9 unchanged lines hidden (view full) ---

941
942 return len;
943}
944
945/*
946 * sending SADB_X_SPDUPDATE message to the kernel.
947 * OUT:
948 * positive: success and return length sent.
949 * -1 : error occured, and set errno.
949 * -1 : error occurred, and set errno.
950 */
951int
952pfkey_send_spdupdate2(so, src, prefs, dst, prefd, proto, ltime, vtime,
953 policy, policylen, seq)
954 int so;
955 struct sockaddr *src, *dst;
956 u_int prefs, prefd, proto;
957 u_int64_t ltime, vtime;

--- 11 unchanged lines hidden (view full) ---

969
970 return len;
971}
972
973/*
974 * sending SADB_X_SPDDELETE message to the kernel.
975 * OUT:
976 * positive: success and return length sent.
950 */
951int
952pfkey_send_spdupdate2(so, src, prefs, dst, prefd, proto, ltime, vtime,
953 policy, policylen, seq)
954 int so;
955 struct sockaddr *src, *dst;
956 u_int prefs, prefd, proto;
957 u_int64_t ltime, vtime;

--- 11 unchanged lines hidden (view full) ---

969
970 return len;
971}
972
973/*
974 * sending SADB_X_SPDDELETE message to the kernel.
975 * OUT:
976 * positive: success and return length sent.
977 * -1 : error occured, and set errno.
977 * -1 : error occurred, and set errno.
978 */
979int
980pfkey_send_spddelete(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
981 int so;
982 struct sockaddr *src, *dst;
983 u_int prefs, prefd, proto;
984 caddr_t policy;
985 int policylen;

--- 14 unchanged lines hidden (view full) ---

1000
1001 return len;
1002}
1003
1004/*
1005 * sending SADB_X_SPDDELETE message to the kernel.
1006 * OUT:
1007 * positive: success and return length sent.
978 */
979int
980pfkey_send_spddelete(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
981 int so;
982 struct sockaddr *src, *dst;
983 u_int prefs, prefd, proto;
984 caddr_t policy;
985 int policylen;

--- 14 unchanged lines hidden (view full) ---

1000
1001 return len;
1002}
1003
1004/*
1005 * sending SADB_X_SPDDELETE message to the kernel.
1006 * OUT:
1007 * positive: success and return length sent.
1008 * -1 : error occured, and set errno.
1008 * -1 : error occurred, and set errno.
1009 */
1010int
1011pfkey_send_spddelete2(so, spid)
1012 int so;
1013 u_int32_t spid;
1014{
1015 int len;
1016
1017 if ((len = pfkey_send_x5(so, SADB_X_SPDDELETE2, spid)) < 0)
1018 return -1;
1019
1020 return len;
1021}
1022
1023/*
1024 * sending SADB_X_SPDGET message to the kernel.
1025 * OUT:
1026 * positive: success and return length sent.
1009 */
1010int
1011pfkey_send_spddelete2(so, spid)
1012 int so;
1013 u_int32_t spid;
1014{
1015 int len;
1016
1017 if ((len = pfkey_send_x5(so, SADB_X_SPDDELETE2, spid)) < 0)
1018 return -1;
1019
1020 return len;
1021}
1022
1023/*
1024 * sending SADB_X_SPDGET message to the kernel.
1025 * OUT:
1026 * positive: success and return length sent.
1027 * -1 : error occured, and set errno.
1027 * -1 : error occurred, and set errno.
1028 */
1029int
1030pfkey_send_spdget(so, spid)
1031 int so;
1032 u_int32_t spid;
1033{
1034 int len;
1035
1036 if ((len = pfkey_send_x5(so, SADB_X_SPDGET, spid)) < 0)
1037 return -1;
1038
1039 return len;
1040}
1041
1042/*
1043 * sending SADB_X_SPDSETIDX message to the kernel.
1044 * OUT:
1045 * positive: success and return length sent.
1028 */
1029int
1030pfkey_send_spdget(so, spid)
1031 int so;
1032 u_int32_t spid;
1033{
1034 int len;
1035
1036 if ((len = pfkey_send_x5(so, SADB_X_SPDGET, spid)) < 0)
1037 return -1;
1038
1039 return len;
1040}
1041
1042/*
1043 * sending SADB_X_SPDSETIDX message to the kernel.
1044 * OUT:
1045 * positive: success and return length sent.
1046 * -1 : error occured, and set errno.
1046 * -1 : error occurred, and set errno.
1047 */
1048int
1049pfkey_send_spdsetidx(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
1050 int so;
1051 struct sockaddr *src, *dst;
1052 u_int prefs, prefd, proto;
1053 caddr_t policy;
1054 int policylen;

--- 14 unchanged lines hidden (view full) ---

1069
1070 return len;
1071}
1072
1073/*
1074 * sending SADB_SPDFLUSH message to the kernel.
1075 * OUT:
1076 * positive: success and return length sent.
1047 */
1048int
1049pfkey_send_spdsetidx(so, src, prefs, dst, prefd, proto, policy, policylen, seq)
1050 int so;
1051 struct sockaddr *src, *dst;
1052 u_int prefs, prefd, proto;
1053 caddr_t policy;
1054 int policylen;

--- 14 unchanged lines hidden (view full) ---

1069
1070 return len;
1071}
1072
1073/*
1074 * sending SADB_SPDFLUSH message to the kernel.
1075 * OUT:
1076 * positive: success and return length sent.
1077 * -1 : error occured, and set errno.
1077 * -1 : error occurred, and set errno.
1078 */
1079int
1080pfkey_send_spdflush(so)
1081 int so;
1082{
1083 int len;
1084
1085 if ((len = pfkey_send_x3(so, SADB_X_SPDFLUSH, SADB_SATYPE_UNSPEC)) < 0)
1086 return -1;
1087
1088 return len;
1089}
1090
1091/*
1092 * sending SADB_SPDDUMP message to the kernel.
1093 * OUT:
1094 * positive: success and return length sent.
1078 */
1079int
1080pfkey_send_spdflush(so)
1081 int so;
1082{
1083 int len;
1084
1085 if ((len = pfkey_send_x3(so, SADB_X_SPDFLUSH, SADB_SATYPE_UNSPEC)) < 0)
1086 return -1;
1087
1088 return len;
1089}
1090
1091/*
1092 * sending SADB_SPDDUMP message to the kernel.
1093 * OUT:
1094 * positive: success and return length sent.
1095 * -1 : error occured, and set errno.
1095 * -1 : error occurred, and set errno.
1096 */
1097int
1098pfkey_send_spddump(so)
1099 int so;
1100{
1101 int len;
1102
1103 if ((len = pfkey_send_x3(so, SADB_X_SPDDUMP, SADB_SATYPE_UNSPEC)) < 0)

--- 549 unchanged lines hidden (view full) ---

1653 __ipsec_errcode = EIPSEC_NO_ERROR;
1654 return;
1655}
1656
1657/*
1658 * receive sadb_msg data, and return pointer to new buffer allocated.
1659 * Must free this buffer later.
1660 * OUT:
1096 */
1097int
1098pfkey_send_spddump(so)
1099 int so;
1100{
1101 int len;
1102
1103 if ((len = pfkey_send_x3(so, SADB_X_SPDDUMP, SADB_SATYPE_UNSPEC)) < 0)

--- 549 unchanged lines hidden (view full) ---

1653 __ipsec_errcode = EIPSEC_NO_ERROR;
1654 return;
1655}
1656
1657/*
1658 * receive sadb_msg data, and return pointer to new buffer allocated.
1659 * Must free this buffer later.
1660 * OUT:
1661 * NULL : error occured.
1661 * NULL : error occurred.
1662 * others : a pointer to sadb_msg structure.
1663 *
1664 * XXX should be rewritten to pass length explicitly
1665 */
1666struct sadb_msg *
1667pfkey_recv(so)
1668 int so;
1669{

--- 530 unchanged lines hidden ---
1662 * others : a pointer to sadb_msg structure.
1663 *
1664 * XXX should be rewritten to pass length explicitly
1665 */
1666struct sadb_msg *
1667pfkey_recv(so)
1668 int so;
1669{

--- 530 unchanged lines hidden ---