Lines Matching refs:args
161 va_list args; in log_msg() local
169 va_start(args, format); in log_msg()
170 vfprintf(stdout, format, args); in log_msg()
171 va_end(args); in log_msg()
179 va_list args; in log_error() local
187 va_start(args, format); in log_error()
188 vfprintf(stderr, format, args); in log_error()
189 va_end(args); in log_error()
197 va_list args; in log_err_errno() local
205 va_start(args, fmt); in log_err_errno()
206 vfprintf(stderr, fmt, args); in log_err_errno()
207 va_end(args); in log_err_errno()
263 static int tcp_md5sig(int sd, void *addr, socklen_t alen, struct sock_args *args) in tcp_md5sig() argument
265 int keylen = strlen(args->password); in tcp_md5sig()
271 memcpy(md5sig.tcpm_key, args->password, keylen); in tcp_md5sig()
273 if (args->prefix_len) { in tcp_md5sig()
277 md5sig.tcpm_prefixlen = args->prefix_len; in tcp_md5sig()
278 addr = &args->md5_prefix; in tcp_md5sig()
282 if ((args->ifindex && args->bind_key_ifindex >= 0) || args->bind_key_ifindex >= 1) { in tcp_md5sig()
286 md5sig.tcpm_ifindex = args->ifindex; in tcp_md5sig()
304 static int tcp_md5_remote(int sd, struct sock_args *args) in tcp_md5_remote() argument
315 switch (args->version) { in tcp_md5_remote()
317 sin.sin_port = htons(args->port); in tcp_md5_remote()
318 sin.sin_addr = args->md5_prefix.v4.sin_addr; in tcp_md5_remote()
323 sin6.sin6_port = htons(args->port); in tcp_md5_remote()
324 sin6.sin6_addr = args->md5_prefix.v6.sin6_addr; in tcp_md5_remote()
333 if (tcp_md5sig(sd, addr, alen, args)) in tcp_md5_remote()
391 static int check_device(int sd, struct sock_args *args) in check_device() argument
404 if (!args->expected_ifindex) in check_device()
407 if (args->expected_ifindex != ifindex) { in check_device()
409 args->expected_ifindex, ifindex); in check_device()
414 args->expected_ifindex, ifindex); in check_device()
634 static int resolve_devices(struct sock_args *args) in resolve_devices() argument
636 if (args->dev) { in resolve_devices()
637 args->ifindex = get_ifidx(args->dev); in resolve_devices()
638 if (args->ifindex < 0) { in resolve_devices()
644 if (args->expected_dev) { in resolve_devices()
647 if (str_to_uint(args->expected_dev, 0, INT_MAX, &tmp) == 0) { in resolve_devices()
648 args->expected_ifindex = (int)tmp; in resolve_devices()
650 args->expected_ifindex = get_ifidx(args->expected_dev); in resolve_devices()
651 if (args->expected_ifindex < 0) { in resolve_devices()
701 static int show_sockstat(int sd, struct sock_args *args) in show_sockstat() argument
714 if (args->has_expected_laddr) { in show_sockstat()
715 rc = expected_addr_match(sa, &args->expected_laddr, in show_sockstat()
727 if (args->has_expected_raddr) { in show_sockstat()
728 rc |= expected_addr_match(sa, &args->expected_raddr, in show_sockstat()
747 static int convert_addr(struct sock_args *args, const char *_str, in convert_addr() argument
750 int pfx_len_max = args->version == AF_INET6 ? 128 : 32; in convert_addr()
751 int family = args->version; in convert_addr()
766 addr = &args->local_addr; in convert_addr()
770 addr = &args->remote_addr; in convert_addr()
774 addr = &args->grp; in convert_addr()
778 addr = &args->expected_laddr; in convert_addr()
782 addr = &args->expected_raddr; in convert_addr()
787 args->md5_prefix.v4.sin_family = AF_INET; in convert_addr()
788 addr = &args->md5_prefix.v4.sin_addr; in convert_addr()
790 args->md5_prefix.v6.sin6_family = AF_INET6; in convert_addr()
791 addr = &args->md5_prefix.v6.sin6_addr; in convert_addr()
800 &args->prefix_len) != 0) { in convert_addr()
805 args->prefix_len = 0; in convert_addr()
845 args->scope_id = get_ifidx(dev); in convert_addr()
846 if (args->scope_id < 0) { in convert_addr()
864 static int validate_addresses(struct sock_args *args) in validate_addresses() argument
866 if (args->local_addr_str && in validate_addresses()
867 convert_addr(args, args->local_addr_str, ADDR_TYPE_LOCAL) < 0) in validate_addresses()
870 if (args->remote_addr_str && in validate_addresses()
871 convert_addr(args, args->remote_addr_str, ADDR_TYPE_REMOTE) < 0) in validate_addresses()
874 if (args->md5_prefix_str && in validate_addresses()
875 convert_addr(args, args->md5_prefix_str, in validate_addresses()
879 if (args->expected_laddr_str && in validate_addresses()
880 convert_addr(args, args->expected_laddr_str, in validate_addresses()
884 if (args->expected_raddr_str && in validate_addresses()
885 convert_addr(args, args->expected_raddr_str, in validate_addresses()
1009 static int send_msg(int sd, void *addr, socklen_t alen, struct sock_args *args) in send_msg() argument
1011 if (args->type == SOCK_STREAM) { in send_msg()
1016 } else if (args->datagram_connect) { in send_msg()
1021 } else if (args->ifindex && args->use_cmsg) { in send_msg()
1022 if (send_msg_cmsg(sd, addr, alen, args->ifindex, args->version)) in send_msg()
1035 static int socket_read_dgram(int sd, struct sock_args *args) in socket_read_dgram() argument
1076 if (args->expected_ifindex) { in socket_read_dgram()
1077 if (args->expected_ifindex != ifindex) { in socket_read_dgram()
1079 args->expected_ifindex, ifindex); in socket_read_dgram()
1083 args->expected_ifindex, ifindex); in socket_read_dgram()
1109 if (args->version == AF_INET6) { in socket_read_dgram()
1112 if (args->dev) { in socket_read_dgram()
1180 static int socket_read(int sd, struct sock_args *args) in socket_read() argument
1182 if (args->type == SOCK_STREAM) in socket_read()
1185 return socket_read_dgram(sd, args); in socket_read()
1236 struct sock_args *args) in msg_loop() argument
1243 if (args->type != SOCK_STREAM) in msg_loop()
1244 set_recv_attr(sd, args->version); in msg_loop()
1251 if (send_msg(sd, addr, alen, args)) in msg_loop()
1283 rc = socket_read(sd, args); in msg_loop()
1295 if (stdin_to_socket(sd, args->type, addr, alen) <= 0) in msg_loop()
1312 if (send_msg(sd, addr, alen, args)) { in msg_loop()
1322 static int msock_init(struct sock_args *args, int server) in msock_init() argument
1327 .sin_port = htons(args->port), in msock_init()
1332 if (!server && args->has_local_ip) in msock_init()
1333 if_addr = args->local_addr.in.s_addr; in msock_init()
1351 if (set_dsfield(sd, AF_INET, args->dsfield) != 0) in msock_init()
1354 if (args->dev && bind_to_device(sd, args->dev) != 0) in msock_init()
1356 else if (args->use_setsockopt && in msock_init()
1357 set_multicast_if(sd, args->ifindex)) in msock_init()
1368 set_membership(sd, args->grp.s_addr, in msock_init()
1369 args->local_addr.in.s_addr, args->ifindex)) in msock_init()
1378 static int msock_server(struct sock_args *args) in msock_server() argument
1380 return msock_init(args, 1); in msock_server()
1383 static int msock_client(struct sock_args *args) in msock_client() argument
1385 return msock_init(args, 0); in msock_client()
1388 static int bind_socket(int sd, struct sock_args *args) in bind_socket() argument
1399 if (!args->has_local_ip && args->type == SOCK_RAW) in bind_socket()
1402 switch (args->version) { in bind_socket()
1404 serv_addr.sin_port = htons(args->port); in bind_socket()
1405 serv_addr.sin_addr = args->local_addr.in; in bind_socket()
1411 serv6_addr.sin6_port = htons(args->port); in bind_socket()
1412 serv6_addr.sin6_addr = args->local_addr.in6; in bind_socket()
1430 static int config_xfrm_policy(int sd, struct sock_args *args) in config_xfrm_policy() argument
1437 if (args->type != SOCK_DGRAM) { in config_xfrm_policy()
1443 policy.sel.family = args->version; in config_xfrm_policy()
1444 if (args->version == AF_INET6) { in config_xfrm_policy()
1465 static int lsock_init(struct sock_args *args) in lsock_init() argument
1470 sd = socket(args->version, args->type, args->protocol); in lsock_init()
1482 if (set_dsfield(sd, args->version, args->dsfield) != 0) in lsock_init()
1485 if (args->dev && bind_to_device(sd, args->dev) != 0) in lsock_init()
1487 else if (args->use_setsockopt && in lsock_init()
1488 set_unicast_if(sd, args->ifindex, args->version)) in lsock_init()
1491 if (args->use_freebind && set_freebind(sd, args->version)) in lsock_init()
1494 if (bind_socket(sd, args)) in lsock_init()
1497 if (args->bind_test_only) in lsock_init()
1500 if (args->type == SOCK_STREAM && listen(sd, 1) < 0) { in lsock_init()
1514 if (args->use_xfrm && config_xfrm_policy(sd, args)) { in lsock_init()
1537 static int do_server(struct sock_args *args, int ipc_fd) in do_server() argument
1548 if (args->serverns) { in do_server()
1549 if (switch_ns(args->serverns)) { in do_server()
1551 args->serverns); in do_server()
1557 args->dev = args->server_dev; in do_server()
1558 args->expected_dev = args->expected_server_dev; in do_server()
1559 if (resolve_devices(args) || validate_addresses(args)) in do_server()
1565 if (args->has_grp) in do_server()
1566 lsd = msock_server(args); in do_server()
1568 lsd = lsock_init(args); in do_server()
1573 if (args->bind_test_only) { in do_server()
1579 if (args->type != SOCK_STREAM) { in do_server()
1581 rc = msg_loop(0, lsd, (void *) addr, alen, args); in do_server()
1586 if (args->password && tcp_md5_remote(lsd, args)) { in do_server()
1619 rc = show_sockstat(csd, args); in do_server()
1623 rc = check_device(csd, args); in do_server()
1628 rc = msg_loop(0, csd, (void *) addr, alen, args); in do_server()
1678 static int connectsock(void *addr, socklen_t alen, struct sock_args *args) in connectsock() argument
1683 sd = socket(args->version, args->type, args->protocol); in connectsock()
1698 if (set_dsfield(sd, args->version, args->dsfield) != 0) in connectsock()
1701 if (args->dev && bind_to_device(sd, args->dev) != 0) in connectsock()
1703 else if (args->use_setsockopt && in connectsock()
1704 set_unicast_if(sd, args->ifindex, args->version)) in connectsock()
1707 if (args->has_local_ip && bind_socket(sd, args)) in connectsock()
1710 if (args->type != SOCK_STREAM && !args->datagram_connect) in connectsock()
1713 if (args->password && tcp_md5sig(sd, addr, alen, args)) in connectsock()
1716 if (args->bind_test_only) in connectsock()
1737 static int do_client(struct sock_args *args) in do_client() argument
1750 if (!args->has_remote_ip && !args->has_grp) { in do_client()
1755 if (args->clientns) { in do_client()
1756 if (switch_ns(args->clientns)) { in do_client()
1758 args->clientns); in do_client()
1764 args->local_addr_str = args->client_local_addr_str; in do_client()
1765 if (resolve_devices(args) || validate_addresses(args)) in do_client()
1768 if ((args->use_setsockopt || args->use_cmsg) && !args->ifindex) { in do_client()
1772 if (args->use_setsockopt || args->use_cmsg) in do_client()
1773 args->dev = NULL; in do_client()
1775 switch (args->version) { in do_client()
1777 sin.sin_port = htons(args->port); in do_client()
1778 if (args->has_grp) in do_client()
1779 sin.sin_addr = args->grp; in do_client()
1781 sin.sin_addr = args->remote_addr.in; in do_client()
1786 sin6.sin6_port = htons(args->port); in do_client()
1787 sin6.sin6_addr = args->remote_addr.in6; in do_client()
1788 sin6.sin6_scope_id = args->scope_id; in do_client()
1794 args->password = args->client_pw; in do_client()
1796 if (args->has_grp) in do_client()
1797 sd = msock_client(args); in do_client()
1799 sd = connectsock(addr, alen, args); in do_client()
1804 if (args->bind_test_only) in do_client()
1807 if (args->type == SOCK_STREAM) { in do_client()
1808 rc = show_sockstat(sd, args); in do_client()
1813 rc = msg_loop(1, sd, addr, alen, args); in do_client()
1844 static int ipc_child(int fd, struct sock_args *args) in ipc_child() argument
1864 args->has_expected_laddr = 0; in ipc_child()
1865 args->has_expected_raddr = 0; in ipc_child()
1867 rc = do_server(args, fd); in ipc_child()
1876 static int ipc_parent(int cpid, int fd, struct sock_args *args) in ipc_parent() argument
1895 client_status = do_client(args); in ipc_parent()
1973 struct sock_args args = { in main() local
2005 args.has_local_ip = 1; in main()
2006 args.local_addr_str = optarg; in main()
2009 args.has_remote_ip = 1; in main()
2010 args.remote_addr_str = optarg; in main()
2013 args.has_local_ip = 1; in main()
2014 args.client_local_addr_str = optarg; in main()
2021 args.dsfield = tmp; in main()
2028 args.port = (unsigned short) tmp; in main()
2038 args.type = SOCK_DGRAM; in main()
2041 args.type = SOCK_RAW; in main()
2042 args.port = 0; in main()
2043 if (!args.protocol) in main()
2044 args.protocol = IPPROTO_RAW; in main()
2049 args.protocol = pe->p_proto; in main()
2055 args.protocol = tmp; in main()
2062 args.clientns = optarg; in main()
2065 args.serverns = optarg; in main()
2071 args.password = optarg; in main()
2074 args.bind_key_ifindex = 1; in main()
2077 args.bind_key_ifindex = -1; in main()
2080 args.client_pw = optarg; in main()
2083 args.md5_prefix_str = optarg; in main()
2086 args.use_setsockopt = 1; in main()
2089 args.use_freebind = 1; in main()
2092 args.use_cmsg = 1; in main()
2095 args.dev = optarg; in main()
2098 args.server_dev = optarg; in main()
2104 args.has_grp = 1; in main()
2105 if (convert_addr(&args, optarg, ADDR_TYPE_MCAST) < 0) in main()
2107 args.type = SOCK_DGRAM; in main()
2110 args.version = AF_INET6; in main()
2113 args.bind_test_only = 1; in main()
2116 args.has_expected_laddr = 1; in main()
2117 args.expected_laddr_str = optarg; in main()
2120 args.has_expected_raddr = 1; in main()
2121 args.expected_raddr_str = optarg; in main()
2124 args.expected_dev = optarg; in main()
2127 args.expected_server_dev = optarg; in main()
2133 args.use_xfrm = 1; in main()
2136 args.datagram_connect = 1; in main()
2144 if (args.password && in main()
2145 ((!args.has_remote_ip && !args.md5_prefix_str) || in main()
2146 args.type != SOCK_STREAM)) { in main()
2151 if (args.md5_prefix_str && !args.password) { in main()
2161 if (args.type == SOCK_STREAM && !args.protocol) in main()
2162 args.protocol = IPPROTO_TCP; in main()
2163 if (args.type == SOCK_DGRAM && !args.protocol) in main()
2164 args.protocol = IPPROTO_UDP; in main()
2166 if ((args.type == SOCK_STREAM || args.type == SOCK_DGRAM) && in main()
2167 args.port == 0) { in main()
2172 if ((both_mode || !server_mode) && !args.has_grp && in main()
2173 !args.has_remote_ip && !args.has_local_ip) { in main()
2196 return ipc_parent(cpid, fd[0], &args); in main()
2198 return ipc_child(fd[1], &args); in main()
2203 rc = do_server(&args, -1); in main()
2208 return do_client(&args); in main()