Lines Matching refs:args

160 	va_list args;  in log_msg()  local
168 va_start(args, format); in log_msg()
169 vfprintf(stdout, format, args); in log_msg()
170 va_end(args); in log_msg()
178 va_list args; in log_error() local
186 va_start(args, format); in log_error()
187 vfprintf(stderr, format, args); in log_error()
188 va_end(args); in log_error()
196 va_list args; in log_err_errno() local
204 va_start(args, fmt); in log_err_errno()
205 vfprintf(stderr, fmt, args); in log_err_errno()
206 va_end(args); in log_err_errno()
262 static int tcp_md5sig(int sd, void *addr, socklen_t alen, struct sock_args *args) in tcp_md5sig() argument
264 int keylen = strlen(args->password); in tcp_md5sig()
270 memcpy(md5sig.tcpm_key, args->password, keylen); in tcp_md5sig()
272 if (args->prefix_len) { in tcp_md5sig()
276 md5sig.tcpm_prefixlen = args->prefix_len; in tcp_md5sig()
277 addr = &args->md5_prefix; in tcp_md5sig()
281 if ((args->ifindex && args->bind_key_ifindex >= 0) || args->bind_key_ifindex >= 1) { in tcp_md5sig()
285 md5sig.tcpm_ifindex = args->ifindex; in tcp_md5sig()
303 static int tcp_md5_remote(int sd, struct sock_args *args) in tcp_md5_remote() argument
314 switch (args->version) { in tcp_md5_remote()
316 sin.sin_port = htons(args->port); in tcp_md5_remote()
317 sin.sin_addr = args->md5_prefix.v4.sin_addr; in tcp_md5_remote()
322 sin6.sin6_port = htons(args->port); in tcp_md5_remote()
323 sin6.sin6_addr = args->md5_prefix.v6.sin6_addr; in tcp_md5_remote()
332 if (tcp_md5sig(sd, addr, alen, args)) in tcp_md5_remote()
390 static int check_device(int sd, struct sock_args *args) in check_device() argument
403 if (!args->expected_ifindex) in check_device()
406 if (args->expected_ifindex != ifindex) { in check_device()
408 args->expected_ifindex, ifindex); in check_device()
413 args->expected_ifindex, ifindex); in check_device()
603 static int resolve_devices(struct sock_args *args) in resolve_devices() argument
605 if (args->dev) { in resolve_devices()
606 args->ifindex = get_ifidx(args->dev); in resolve_devices()
607 if (args->ifindex < 0) { in resolve_devices()
613 if (args->expected_dev) { in resolve_devices()
616 if (str_to_uint(args->expected_dev, 0, INT_MAX, &tmp) == 0) { in resolve_devices()
617 args->expected_ifindex = (int)tmp; in resolve_devices()
619 args->expected_ifindex = get_ifidx(args->expected_dev); in resolve_devices()
620 if (args->expected_ifindex < 0) { in resolve_devices()
670 static int show_sockstat(int sd, struct sock_args *args) in show_sockstat() argument
683 if (args->has_expected_laddr) { in show_sockstat()
684 rc = expected_addr_match(sa, &args->expected_laddr, in show_sockstat()
696 if (args->has_expected_raddr) { in show_sockstat()
697 rc |= expected_addr_match(sa, &args->expected_raddr, in show_sockstat()
716 static int convert_addr(struct sock_args *args, const char *_str, in convert_addr() argument
719 int pfx_len_max = args->version == AF_INET6 ? 128 : 32; in convert_addr()
720 int family = args->version; in convert_addr()
735 addr = &args->local_addr; in convert_addr()
739 addr = &args->remote_addr; in convert_addr()
743 addr = &args->grp; in convert_addr()
747 addr = &args->expected_laddr; in convert_addr()
751 addr = &args->expected_raddr; in convert_addr()
756 args->md5_prefix.v4.sin_family = AF_INET; in convert_addr()
757 addr = &args->md5_prefix.v4.sin_addr; in convert_addr()
759 args->md5_prefix.v6.sin6_family = AF_INET6; in convert_addr()
760 addr = &args->md5_prefix.v6.sin6_addr; in convert_addr()
769 &args->prefix_len) != 0) { in convert_addr()
774 args->prefix_len = 0; in convert_addr()
814 args->scope_id = get_ifidx(dev); in convert_addr()
815 if (args->scope_id < 0) { in convert_addr()
833 static int validate_addresses(struct sock_args *args) in validate_addresses() argument
835 if (args->local_addr_str && in validate_addresses()
836 convert_addr(args, args->local_addr_str, ADDR_TYPE_LOCAL) < 0) in validate_addresses()
839 if (args->remote_addr_str && in validate_addresses()
840 convert_addr(args, args->remote_addr_str, ADDR_TYPE_REMOTE) < 0) in validate_addresses()
843 if (args->md5_prefix_str && in validate_addresses()
844 convert_addr(args, args->md5_prefix_str, in validate_addresses()
848 if (args->expected_laddr_str && in validate_addresses()
849 convert_addr(args, args->expected_laddr_str, in validate_addresses()
853 if (args->expected_raddr_str && in validate_addresses()
854 convert_addr(args, args->expected_raddr_str, in validate_addresses()
978 static int send_msg(int sd, void *addr, socklen_t alen, struct sock_args *args) in send_msg() argument
980 if (args->type == SOCK_STREAM) { in send_msg()
985 } else if (args->datagram_connect) { in send_msg()
990 } else if (args->ifindex && args->use_cmsg) { in send_msg()
991 if (send_msg_cmsg(sd, addr, alen, args->ifindex, args->version)) in send_msg()
1004 static int socket_read_dgram(int sd, struct sock_args *args) in socket_read_dgram() argument
1045 if (args->expected_ifindex) { in socket_read_dgram()
1046 if (args->expected_ifindex != ifindex) { in socket_read_dgram()
1048 args->expected_ifindex, ifindex); in socket_read_dgram()
1052 args->expected_ifindex, ifindex); in socket_read_dgram()
1078 if (args->version == AF_INET6) { in socket_read_dgram()
1081 if (args->dev) { in socket_read_dgram()
1149 static int socket_read(int sd, struct sock_args *args) in socket_read() argument
1151 if (args->type == SOCK_STREAM) in socket_read()
1154 return socket_read_dgram(sd, args); in socket_read()
1205 struct sock_args *args) in msg_loop() argument
1212 if (args->type != SOCK_STREAM) in msg_loop()
1213 set_recv_attr(sd, args->version); in msg_loop()
1220 if (send_msg(sd, addr, alen, args)) in msg_loop()
1252 rc = socket_read(sd, args); in msg_loop()
1264 if (stdin_to_socket(sd, args->type, addr, alen) <= 0) in msg_loop()
1281 if (send_msg(sd, addr, alen, args)) { in msg_loop()
1291 static int msock_init(struct sock_args *args, int server) in msock_init() argument
1296 .sin_port = htons(args->port), in msock_init()
1301 if (!server && args->has_local_ip) in msock_init()
1302 if_addr = args->local_addr.in.s_addr; in msock_init()
1320 if (args->dev && bind_to_device(sd, args->dev) != 0) in msock_init()
1322 else if (args->use_setsockopt && in msock_init()
1323 set_multicast_if(sd, args->ifindex)) in msock_init()
1334 set_membership(sd, args->grp.s_addr, in msock_init()
1335 args->local_addr.in.s_addr, args->ifindex)) in msock_init()
1344 static int msock_server(struct sock_args *args) in msock_server() argument
1346 return msock_init(args, 1); in msock_server()
1349 static int msock_client(struct sock_args *args) in msock_client() argument
1351 return msock_init(args, 0); in msock_client()
1354 static int bind_socket(int sd, struct sock_args *args) in bind_socket() argument
1365 if (!args->has_local_ip && args->type == SOCK_RAW) in bind_socket()
1368 switch (args->version) { in bind_socket()
1370 serv_addr.sin_port = htons(args->port); in bind_socket()
1371 serv_addr.sin_addr = args->local_addr.in; in bind_socket()
1377 serv6_addr.sin6_port = htons(args->port); in bind_socket()
1378 serv6_addr.sin6_addr = args->local_addr.in6; in bind_socket()
1396 static int config_xfrm_policy(int sd, struct sock_args *args) in config_xfrm_policy() argument
1403 if (args->type != SOCK_DGRAM) { in config_xfrm_policy()
1409 policy.sel.family = args->version; in config_xfrm_policy()
1410 if (args->version == AF_INET6) { in config_xfrm_policy()
1431 static int lsock_init(struct sock_args *args) in lsock_init() argument
1436 sd = socket(args->version, args->type, args->protocol); in lsock_init()
1448 if (args->dev && bind_to_device(sd, args->dev) != 0) in lsock_init()
1450 else if (args->use_setsockopt && in lsock_init()
1451 set_unicast_if(sd, args->ifindex, args->version)) in lsock_init()
1454 if (args->use_freebind && set_freebind(sd, args->version)) in lsock_init()
1457 if (bind_socket(sd, args)) in lsock_init()
1460 if (args->bind_test_only) in lsock_init()
1463 if (args->type == SOCK_STREAM && listen(sd, 1) < 0) { in lsock_init()
1477 if (args->use_xfrm && config_xfrm_policy(sd, args)) { in lsock_init()
1500 static int do_server(struct sock_args *args, int ipc_fd) in do_server() argument
1511 if (args->serverns) { in do_server()
1512 if (switch_ns(args->serverns)) { in do_server()
1514 args->serverns); in do_server()
1520 args->dev = args->server_dev; in do_server()
1521 args->expected_dev = args->expected_server_dev; in do_server()
1522 if (resolve_devices(args) || validate_addresses(args)) in do_server()
1528 if (args->has_grp) in do_server()
1529 lsd = msock_server(args); in do_server()
1531 lsd = lsock_init(args); in do_server()
1536 if (args->bind_test_only) { in do_server()
1542 if (args->type != SOCK_STREAM) { in do_server()
1544 rc = msg_loop(0, lsd, (void *) addr, alen, args); in do_server()
1549 if (args->password && tcp_md5_remote(lsd, args)) { in do_server()
1582 rc = show_sockstat(csd, args); in do_server()
1586 rc = check_device(csd, args); in do_server()
1591 rc = msg_loop(0, csd, (void *) addr, alen, args); in do_server()
1641 static int connectsock(void *addr, socklen_t alen, struct sock_args *args) in connectsock() argument
1646 sd = socket(args->version, args->type, args->protocol); in connectsock()
1661 if (args->dev && bind_to_device(sd, args->dev) != 0) in connectsock()
1663 else if (args->use_setsockopt && in connectsock()
1664 set_unicast_if(sd, args->ifindex, args->version)) in connectsock()
1667 if (args->has_local_ip && bind_socket(sd, args)) in connectsock()
1670 if (args->type != SOCK_STREAM && !args->datagram_connect) in connectsock()
1673 if (args->password && tcp_md5sig(sd, addr, alen, args)) in connectsock()
1676 if (args->bind_test_only) in connectsock()
1697 static int do_client(struct sock_args *args) in do_client() argument
1710 if (!args->has_remote_ip && !args->has_grp) { in do_client()
1715 if (args->clientns) { in do_client()
1716 if (switch_ns(args->clientns)) { in do_client()
1718 args->clientns); in do_client()
1724 args->local_addr_str = args->client_local_addr_str; in do_client()
1725 if (resolve_devices(args) || validate_addresses(args)) in do_client()
1728 if ((args->use_setsockopt || args->use_cmsg) && !args->ifindex) { in do_client()
1732 if (args->use_setsockopt || args->use_cmsg) in do_client()
1733 args->dev = NULL; in do_client()
1735 switch (args->version) { in do_client()
1737 sin.sin_port = htons(args->port); in do_client()
1738 if (args->has_grp) in do_client()
1739 sin.sin_addr = args->grp; in do_client()
1741 sin.sin_addr = args->remote_addr.in; in do_client()
1746 sin6.sin6_port = htons(args->port); in do_client()
1747 sin6.sin6_addr = args->remote_addr.in6; in do_client()
1748 sin6.sin6_scope_id = args->scope_id; in do_client()
1754 args->password = args->client_pw; in do_client()
1756 if (args->has_grp) in do_client()
1757 sd = msock_client(args); in do_client()
1759 sd = connectsock(addr, alen, args); in do_client()
1764 if (args->bind_test_only) in do_client()
1767 if (args->type == SOCK_STREAM) { in do_client()
1768 rc = show_sockstat(sd, args); in do_client()
1773 rc = msg_loop(1, sd, addr, alen, args); in do_client()
1804 static int ipc_child(int fd, struct sock_args *args) in ipc_child() argument
1824 args->has_expected_laddr = 0; in ipc_child()
1825 args->has_expected_raddr = 0; in ipc_child()
1827 rc = do_server(args, fd); in ipc_child()
1836 static int ipc_parent(int cpid, int fd, struct sock_args *args) in ipc_parent() argument
1855 client_status = do_client(args); in ipc_parent()
1931 struct sock_args args = { in main() local
1963 args.has_local_ip = 1; in main()
1964 args.local_addr_str = optarg; in main()
1967 args.has_remote_ip = 1; in main()
1968 args.remote_addr_str = optarg; in main()
1971 args.has_local_ip = 1; in main()
1972 args.client_local_addr_str = optarg; in main()
1979 args.port = (unsigned short) tmp; in main()
1989 args.type = SOCK_DGRAM; in main()
1992 args.type = SOCK_RAW; in main()
1993 args.port = 0; in main()
1994 if (!args.protocol) in main()
1995 args.protocol = IPPROTO_RAW; in main()
2000 args.protocol = pe->p_proto; in main()
2006 args.protocol = tmp; in main()
2013 args.clientns = optarg; in main()
2016 args.serverns = optarg; in main()
2022 args.password = optarg; in main()
2025 args.bind_key_ifindex = 1; in main()
2028 args.bind_key_ifindex = -1; in main()
2031 args.client_pw = optarg; in main()
2034 args.md5_prefix_str = optarg; in main()
2037 args.use_setsockopt = 1; in main()
2040 args.use_freebind = 1; in main()
2043 args.use_cmsg = 1; in main()
2046 args.dev = optarg; in main()
2049 args.server_dev = optarg; in main()
2055 args.has_grp = 1; in main()
2056 if (convert_addr(&args, optarg, ADDR_TYPE_MCAST) < 0) in main()
2058 args.type = SOCK_DGRAM; in main()
2061 args.version = AF_INET6; in main()
2064 args.bind_test_only = 1; in main()
2067 args.has_expected_laddr = 1; in main()
2068 args.expected_laddr_str = optarg; in main()
2071 args.has_expected_raddr = 1; in main()
2072 args.expected_raddr_str = optarg; in main()
2075 args.expected_dev = optarg; in main()
2078 args.expected_server_dev = optarg; in main()
2084 args.use_xfrm = 1; in main()
2087 args.datagram_connect = 1; in main()
2095 if (args.password && in main()
2096 ((!args.has_remote_ip && !args.md5_prefix_str) || in main()
2097 args.type != SOCK_STREAM)) { in main()
2102 if (args.md5_prefix_str && !args.password) { in main()
2112 if (args.type == SOCK_STREAM && !args.protocol) in main()
2113 args.protocol = IPPROTO_TCP; in main()
2114 if (args.type == SOCK_DGRAM && !args.protocol) in main()
2115 args.protocol = IPPROTO_UDP; in main()
2117 if ((args.type == SOCK_STREAM || args.type == SOCK_DGRAM) && in main()
2118 args.port == 0) { in main()
2123 if ((both_mode || !server_mode) && !args.has_grp && in main()
2124 !args.has_remote_ip && !args.has_local_ip) { in main()
2147 return ipc_parent(cpid, fd[0], &args); in main()
2149 return ipc_child(fd[1], &args); in main()
2154 rc = do_server(&args, -1); in main()
2159 return do_client(&args); in main()