Lines Matching +full:short +full:- +full:ping
1 // SPDX-License-Identifier: GPL-2.0
3 * ipsec.c - Check xfrm on veth inside a net-ns.
45 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
59 #define VETH_FMT "ktst-%d"
62 static int nsfd_parent = -1;
63 static int nsfd_childa = -1;
64 static int nsfd_childb = -1;
88 while (words--) in randomize_buffer()
94 memcpy(buf + buflen - leftover, &tmp, leftover); in randomize_buffer()
107 return -1; in unshare_open()
113 return -1; in unshare_open()
123 return -1; in switch_ns()
130 * about cleanup on error-path.
136 return -1; in init_namespaces()
140 return -1; in init_namespaces()
143 return -1; in init_namespaces()
147 return -1; in init_namespaces()
150 return -1; in init_namespaces()
164 return -1; in netlink_sock()
174 return (struct rtattr *)((char *)(nh) + RTA_ALIGN((nh)->nlmsg_len)); in rtattr_hdr()
178 unsigned short rta_type, const void *payload, size_t size) in rtattr_pack()
182 size_t nl_size = RTA_ALIGN(nh->nlmsg_len) + RTA_LENGTH(size); in rtattr_pack()
186 return -1; in rtattr_pack()
188 nh->nlmsg_len = nl_size; in rtattr_pack()
190 attr->rta_len = RTA_LENGTH(size); in rtattr_pack()
191 attr->rta_type = rta_type; in rtattr_pack()
198 unsigned short rta_type, const void *payload, size_t size) in _rtattr_begin()
209 unsigned short rta_type) in rtattr_begin()
216 char *nlmsg_end = (char *)nh + nh->nlmsg_len; in rtattr_end()
218 attr->rta_len = nlmsg_end - (char *)attr; in rtattr_end()
233 return -1; in veth_pack_peerb()
236 return -1; in veth_pack_peerb()
239 return -1; in veth_pack_peerb()
256 return -1; in netlink_check_answer()
259 return -1; in netlink_check_answer()
262 answer.error, strerror(-answer.error)); in netlink_check_answer()
290 return -1; in veth_add()
293 return -1; in veth_add()
297 return -1; in veth_add()
300 return -1; in veth_add()
304 return -1; in veth_add()
307 return -1; in veth_add()
314 return -1; in veth_add()
342 strncpy(addr_str, inet_ntoa(addr), IPV4_STR_SZ - 1); in ip4_addr_set()
349 return -1; in ip4_addr_set()
352 return -1; in ip4_addr_set()
356 return -1; in ip4_addr_set()
382 return -1; in link_set_up()
410 return -1; in ip4_route_set()
413 return -1; in ip4_route_set()
416 return -1; in ip4_route_set()
420 return -1; in ip4_route_set()
432 return -1; in tunnel_set_route()
437 return -1; in tunnel_set_route()
448 int route_sock = -1, ret = -1; in init_child()
452 return -1; in init_child()
456 return -1; in init_child()
522 } ping; member
590 return -1; in udp_ping_init()
624 return -1; in udp_ping_init()
642 return -1; in udp_ping_send()
645 return -1; in udp_ping_send()
652 return -1; in udp_ping_send()
654 printk("EOF on reply to ping"); in udp_ping_send()
655 return -1; in udp_ping_send()
657 printk("ping reply packet is corrupted %zd/%zu", r_bytes, buf_len); in udp_ping_send()
658 return -1; in udp_ping_send()
680 return -1; in udp_ping_reply()
683 printk("EOF on reply to ping"); in udp_ping_reply()
684 return -1; in udp_ping_reply()
687 printk("ping reply packet is corrupted %zd/%zu", r_bytes, buf_len); in udp_ping_reply()
688 return -1; in udp_ping_reply()
694 return -1; in udp_ping_reply()
697 return -1; in udp_ping_reply()
714 printk("Failed to init ping"); in do_ping()
715 return -1; in do_ping()
720 msg.body.ping.port = s_port; in do_ping()
721 memcpy(&msg.body.ping.reply_ip, &from, sizeof(from)); in do_ping()
725 /* The other end sends ip to ping */ in do_ping()
728 return -1; in do_ping()
729 to = msg.body.ping.reply_ip; in do_ping()
730 d_port = msg.body.ping.port; in do_ping()
746 strncpy(to_str, inet_ntoa(*(struct in_addr *)&to), IPV4_STR_SZ - 1); in do_ping()
747 strncpy(from_str, inet_ntoa(from), IPV4_STR_SZ - 1); in do_ping()
750 printk("ping (%s) %s->%s failed %u/%u times", in do_ping()
752 ping_count - ping_succeeded, ping_count); in do_ping()
753 return -1; in do_ping()
757 printk("ping (%s) %s->%s succeeded %u/%u times", in do_ping()
807 else if (strncmp(name, "rfc4106(gcm(aes))-128", ALGO_LEN) == 0) in xfrm_fill_key()
809 else if (strncmp(name, "rfc4543(gcm(aes))-128", ALGO_LEN) == 0) in xfrm_fill_key()
811 else if (strncmp(name, "rfc4309(ccm(aes))-128", ALGO_LEN) == 0) in xfrm_fill_key()
813 else if (strncmp(name, "rfc4106(gcm(aes))-192", ALGO_LEN) == 0) in xfrm_fill_key()
815 else if (strncmp(name, "rfc4543(gcm(aes))-192", ALGO_LEN) == 0) in xfrm_fill_key()
817 else if (strncmp(name, "rfc4309(ccm(aes))-192", ALGO_LEN) == 0) in xfrm_fill_key()
819 else if (strncmp(name, "rfc4106(gcm(aes))-256", ALGO_LEN) == 0) in xfrm_fill_key()
821 else if (strncmp(name, "rfc4543(gcm(aes))-256", ALGO_LEN) == 0) in xfrm_fill_key()
823 else if (strncmp(name, "rfc4309(ccm(aes))-256", ALGO_LEN) == 0) in xfrm_fill_key()
825 else if (strncmp(name, "rfc7539(chacha20,poly1305)-128", ALGO_LEN) == 0) in xfrm_fill_key()
829 printk("Can't pack a key - too big for buffer"); in xfrm_fill_key()
830 return -1; in xfrm_fill_key()
850 unsigned short type; in xfrm_state_pack_algo()
852 alen = strlen(desc->a_algo); in xfrm_state_pack_algo()
853 elen = strlen(desc->e_algo); in xfrm_state_pack_algo()
854 clen = strlen(desc->c_algo); in xfrm_state_pack_algo()
855 aelen = strlen(desc->ae_algo); in xfrm_state_pack_algo()
858 switch (desc->proto) { in xfrm_state_pack_algo()
862 return -1; in xfrm_state_pack_algo()
864 strncpy(alg.u.alg.alg_name, desc->a_algo, ALGO_LEN - 1); in xfrm_state_pack_algo()
865 if (xfrm_fill_key(desc->a_algo, alg.u.alg.alg_key, in xfrm_state_pack_algo()
867 return -1; in xfrm_state_pack_algo()
873 return -1; in xfrm_state_pack_algo()
875 strncpy(alg.u.alg.alg_name, desc->c_algo, ALGO_LEN - 1); in xfrm_state_pack_algo()
876 if (xfrm_fill_key(desc->c_algo, alg.u.alg.alg_key, in xfrm_state_pack_algo()
878 return -1; in xfrm_state_pack_algo()
884 return -1; in xfrm_state_pack_algo()
887 alg.u.aead.alg_icv_len = desc->icv_len; in xfrm_state_pack_algo()
888 strncpy(alg.u.aead.alg_name, desc->ae_algo, ALGO_LEN - 1); in xfrm_state_pack_algo()
889 if (xfrm_fill_key(desc->ae_algo, alg.u.aead.alg_key, in xfrm_state_pack_algo()
891 return -1; in xfrm_state_pack_algo()
895 strncpy(alg.u.alg.alg_name, desc->e_algo, ALGO_LEN - 1); in xfrm_state_pack_algo()
897 if (xfrm_fill_key(desc->e_algo, alg.u.alg.alg_key, in xfrm_state_pack_algo()
899 return -1; in xfrm_state_pack_algo()
901 return -1; in xfrm_state_pack_algo()
903 strncpy(alg.u.alg.alg_name, desc->a_algo, ALGO_LEN); in xfrm_state_pack_algo()
905 if (xfrm_fill_key(desc->a_algo, alg.u.alg.alg_key, in xfrm_state_pack_algo()
907 return -1; in xfrm_state_pack_algo()
912 return -1; in xfrm_state_pack_algo()
916 return -1; in xfrm_state_pack_algo()
951 /* Note: zero-spi cannot be deleted */ in xfrm_state_add()
953 req.info.id.proto = desc->proto; in xfrm_state_add()
967 return -1; in xfrm_state_add()
971 return -1; in xfrm_state_add()
981 if (memcmp(&info->sel.daddr, &dst, sizeof(dst))) in xfrm_usersa_found()
984 if (memcmp(&info->sel.saddr, &src, sizeof(src))) in xfrm_usersa_found()
987 if (info->sel.family != AF_INET || in xfrm_usersa_found()
988 info->sel.prefixlen_d != PREFIX_LEN || in xfrm_usersa_found()
989 info->sel.prefixlen_s != PREFIX_LEN) in xfrm_usersa_found()
992 if (info->id.spi != spi || info->id.proto != desc->proto) in xfrm_usersa_found()
995 if (memcmp(&info->id.daddr, &dst, sizeof(dst))) in xfrm_usersa_found()
998 if (memcmp(&info->saddr, &src, sizeof(src))) in xfrm_usersa_found()
1001 if (info->lft.soft_byte_limit != XFRM_INF || in xfrm_usersa_found()
1002 info->lft.hard_byte_limit != XFRM_INF || in xfrm_usersa_found()
1003 info->lft.soft_packet_limit != XFRM_INF || in xfrm_usersa_found()
1004 info->lft.hard_packet_limit != XFRM_INF) in xfrm_usersa_found()
1007 if (info->family != AF_INET || info->mode != XFRM_MODE_TUNNEL) in xfrm_usersa_found()
1050 return -1; in xfrm_state_check()
1054 return -1; in xfrm_state_check()
1060 return -1; in xfrm_state_check()
1064 answer.error, strerror(-answer.error)); in xfrm_state_check()
1065 return -1; in xfrm_state_check()
1070 return -1; in xfrm_state_check()
1088 return -1; in xfrm_set()
1094 return -1; in xfrm_set()
1102 return -1; in xfrm_set()
1143 /* Note: zero-spi cannot be deleted */ in xfrm_policy_add()
1154 return -1; in xfrm_policy_add()
1158 return -1; in xfrm_policy_add()
1171 return -1; in xfrm_prepare()
1177 return -1; in xfrm_prepare()
1209 return -1; in xfrm_policy_del()
1222 return -1; in xfrm_cleanup()
1228 return -1; in xfrm_cleanup()
1253 /* Note: zero-spi cannot be deleted */ in xfrm_state_del()
1258 return -1; in xfrm_state_del()
1262 return -1; in xfrm_state_del()
1274 return -1; in xfrm_delete()
1279 return -1; in xfrm_delete()
1333 printk("NLMSG_ERROR: %d: %s", answer.error, strerror(-answer.error)); in xfrm_state_allocspi()
1341 int ret = -1; in netlink_sock_bind()
1348 return -1; in netlink_sock_bind()
1387 int xfrm_listen = -1, ret = KSFT_FAIL; in xfrm_monitor_acquire()
1423 printk("NLMSG_ERROR: %d: %s", req.error, strerror(-req.error)); in xfrm_monitor_acquire()
1457 int xfrm_listen = -1, ret = KSFT_FAIL; in xfrm_expire_state()
1479 req.expire.state.id.proto = desc->proto; in xfrm_expire_state()
1497 printk("NLMSG_ERROR: %d: %s", req.error, strerror(-req.error)); in xfrm_expire_state()
1529 int xfrm_listen = -1, ret = KSFT_FAIL; in xfrm_expire_policy()
1538 XFRM_POLICY_OUT, tunsrc, tundst, desc->proto)) { in xfrm_expire_policy()
1575 printk("NLMSG_ERROR: %d: %s", req.error, strerror(-req.error)); in xfrm_expire_policy()
1610 printk("ping failed before setting xfrm"); in child_serv()
1619 if (xfrm_prepare(xfrm_sock, seq, src, dst, tunsrc, tundst, desc->proto)) { in child_serv()
1636 printk("ping failed for xfrm"); in child_serv()
1648 if (xfrm_delete(xfrm_sock, seq, src, dst, tunsrc, tundst, desc->proto)) { in child_serv()
1649 printk("failed ping to remove xfrm"); in child_serv()
1659 printk("failed ping to cleanup xfrm"); in child_serv()
1669 int xfrm_sock = -1; in child_f()
1709 -1, desc.proto); in child_f()
1739 struct xfrm_desc *desc = &msg->body.xfrm_desc; in grand_child_serv()
1746 switch (msg->type) { in grand_child_serv()
1753 tun_reply = memcmp(&dst, &msg->body.ping.reply_ip, sizeof(in_addr_t)); in grand_child_serv()
1756 false, msg->body.ping.port, in grand_child_serv()
1757 msg->body.ping.reply_ip, udp_ping_reply)) { in grand_child_serv()
1758 printk("ping failed before setting xfrm"); in grand_child_serv()
1763 desc->proto)) { in grand_child_serv()
1776 desc->proto)) { in grand_child_serv()
1787 printk("got unknown msg type %d", msg->type); in grand_child_serv()
1794 int xfrm_sock = -1; in grand_child_f()
1821 return -1; in start_child()
1824 return -1; in start_child()
1829 return -1; in start_child()
1831 /* in parent - selftest */ in start_child()
1837 return -1; in start_child()
1842 MAP_SHARED | MAP_ANONYMOUS, -1, 0); in start_child()
1845 return -1; in start_child()
1852 return -1; in start_child()
1858 return -1; in start_child()
1862 return -1; in start_child()
1868 return -1; in start_child()
1890 return -1; in __write_desc()
1902 strncpy(desc.a_algo, a, ALGO_LEN - 1); in write_desc()
1904 strncpy(desc.e_algo, e, ALGO_LEN - 1); in write_desc()
1906 strncpy(desc.c_algo, c, ALGO_LEN - 1); in write_desc()
1908 strncpy(desc.ae_algo, ae, ALGO_LEN - 1); in write_desc()
1951 return -1; in write_proto_plan()
1957 return -1; in write_proto_plan()
1967 return -1; in write_proto_plan()
1972 return -1; in write_proto_plan()
1977 return -1; in write_proto_plan()
1985 * 64-bit and 32-bit ABI:
1987 * 32-bit UABI | 64-bit UABI
1988 * -------------------------------------|-------------------------------------
2005 strncpy(desc.a_algo, ah_list[0], ALGO_LEN - 1); in write_compat_struct_tests()
2008 return -1; in write_compat_struct_tests()
2012 return -1; in write_compat_struct_tests()
2016 return -1; in write_compat_struct_tests()
2020 return -1; in write_compat_struct_tests()
2033 return -1; in write_test_plan()
2111 desc_name[d->type], (unsigned int)d->proto, d->a_algo, in check_results()
2112 d->e_algo, d->c_algo, d->ae_algo, d->icv_len); in check_results()
2121 int route_sock = -1, ret = KSFT_SKIP; in main()