Increase bind() coverage - GH#538
v3 cover Increase bind() coverage - GH#538
This patchset adds a test that bind() opens sockets for incoming connections. The test is split into two programs, one for stream-oriented sockets and the other for datagram-oriented sockets.
This is a v3 resubmission of a patchset from last year. I had more important patches to write for a while but I've dusted this code off now because I'll need some of the helper functions in an upcoming CVE test.
Martin Doucha (3):
Create separate .c file for include/tst_net.h
Add socket address initialization functions to tst_net library Add connection tests for bind()
include/tst_net.h | 136 ++------------ lib/tst_net.c | 217 ++++++++++++++++++++++ runtest/syscalls | 2 + testcases/kernel/syscalls/bind/.gitignore | 2 + testcases/kernel/syscalls/bind/Makefile | 2 + testcases/kernel/syscalls/bind/bind04.c | 172 +++++++++++++++++ testcases/kernel/syscalls/bind/bind05.c | 186 +++++++++++++++++++ testcases/kernel/syscalls/bind/libbind.h | 29 +++ testcases/lib/tst_net_iface_prefix.c | 9 +- testcases/lib/tst_net_ip_prefix.c | 10 +- testcases/lib/tst_net_vars.c | 64 +++---- 11 files changed, 671 insertions(+), 158 deletions(-) create mode 100644 lib/tst_net.c create mode 100644 testcases/kernel/syscalls/bind/bind04.c create mode 100644 testcases/kernel/syscalls/bind/bind05.c create mode 100644 testcases/kernel/syscalls/bind/libbind.h
Signature · 1 line
2.25.1
PATCH v3 1/3 Create separate .c file for include/tst_net.h
---
Changes since v1:
- new patch
Changes since v2:
- Also separate print_svar*()
- Added tst_ prefix to functions separated into tst_net.c
include/tst_net.h | 132 ++---------------------- lib/tst_net.c | 146 +++++++++++++++++++++++++++ testcases/lib/tst_net_iface_prefix.c | 9 +- testcases/lib/tst_net_ip_prefix.c | 10 +- testcases/lib/tst_net_vars.c | 64 ++++++------ 5 files changed, 197 insertions(+), 164 deletions(-) create mode 100644 lib/tst_net.c
include/tst_net.h +9 -123
@@ -4,10 +4,7 @@*/ #include <arpa/inet.h> -#include <errno.h> #include <stdio.h> -#include <stdlib.h> -#include <string.h> #define MAX_IPV4_PREFIX 32#define MAX_IPV6_PREFIX 128
@@ -21,124 +18,13 @@fprintf (stderr,"# " ); \tst_brk (TCONF , __VA_ARGS__); } \ -static inline void print_svar (const char *name,const char *val) -{ -if (name && val) -printf ("export %s=\"%s\"\n" , name, val); -} +void tst_print_svar (const char *name,const char *val); +void tst_print_svar_change (const char *name,const char *val); -static inline void print_svar_change (const char *name,const char *val) -{ -if (name && val) -printf ("export %s=\"${%s:-%s}\"\n" , name, name, val); -} - -/* -* Function bit_count is from ipcalc project, ipcalc.c. -*/ -static inline int bit_count (uint32_t i) -{ -int c =0 ; -unsigned int seen_one =0 ; - -while (i >0 ) { -if (i &1 ) { - seen_one =1 ; - c++; - }else { -if (seen_one) -return -1 ; - } - i >>=1 ; - } - -return c; -} - -/* -* Function mask2prefix is from ipcalc project, ipcalc.c. -*/ -static inline int mask2prefix (struct in_addr mask) -{ -return bit_count (ntohl (mask.s_addr)); -} - -/* -* Function ipv4_mask_to_int is from ipcalc project, ipcalc.c. -*/ -static inline int ipv4_mask_to_int (const char *prefix) -{ -int ret; -struct in_addr in; - - ret =inet_pton (AF_INET , prefix, &in); -if (ret ==0 ) -return -1 ; - -return mask2prefix (in); -} - -/* -* Function safe_atoi is from ipcalc project, ipcalc.c. -*/ -static inline int safe_atoi (const char *s,int *ret_i) -{ -char *x =NULL ; -long l; - - errno =0 ; - l =strtol (s, &x,0 ); - -if (!x || x == s || *x || errno) -return errno >0 ? -errno : -EINVAL ; - -if ((long )(int )l != l) -return -ERANGE ; - - *ret_i = (int )l; - -return 0 ; -} - -/* -* Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c. -*/ -static inline int get_prefix (const char *ip_str,int is_ipv6) -{ -char *prefix_str =NULL ; -int prefix =-1 , r; - - prefix_str =strchr (ip_str,'/' ); -if (!prefix_str) -return -1 ; - - *(prefix_str++) ='\0' ; - -if (!is_ipv6 &&strchr (prefix_str,'.' )) - prefix =ipv4_mask_to_int (prefix_str); -else { - r =safe_atoi (prefix_str, &prefix); -if (r !=0 ) -tst_brk_comment ("conversion error: '%s' is not integer" , - prefix_str); - } - -if (prefix <0 || ((is_ipv6 && prefix >MAX_IPV6_PREFIX ) || - (!is_ipv6 && prefix >MAX_IPV4_PREFIX ))) -tst_brk_comment ("bad %s prefix: %s" , is_ipv6 ?"IPv6" :"IPv4" , - prefix_str); - -return prefix; -} - -static inline void get_in_addr (const char *ip_str,struct in_addr *ip) -{ -if (inet_pton (AF_INET , ip_str, ip) <=0 ) -tst_brk_comment ("bad IPv4 address: '%s'" , ip_str); -} - -static inline void get_in6_addr (const char *ip_str,struct in6_addr *ip6) -{ -if (inet_pton (AF_INET6 , ip_str, ip6) <=0 ) -tst_brk_comment ("bad IPv6 address: '%s'" , ip_str); -} +int tst_bit_count (uint32_t i); +int tst_mask2prefix (struct in_addr mask); +int tst_ipv4_mask_to_int (const char *prefix); +int tst_safe_atoi (const char *s,int *ret_i); +int tst_get_prefix (const char *ip_str,int is_ipv6); +void tst_get_in_addr (const char *ip_str,struct in_addr *ip); +void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);
lib/tst_net.c new file +146 -0
146 lines not on this page · raw message
testcases/lib/tst_net_iface_prefix.c +5 -4
@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) prefix_str =strchr (ip_str,'/' );if (prefix_str) { - prefix =get_prefix (ip_str, is_ipv6); + prefix =tst_get_prefix (ip_str, is_ipv6);tst_res_comment (TINFO ,"IP address '%s' contains prefix %d, using it and don't search for iface.\n" , ip_str, prefix);
@@ -136,11 +136,12 @@ int main(int argc, char *argv[])/* checks for validity of IP string */ if (is_ipv6) -get_in6_addr (ip_str, &ip6); +tst_get_in6_addr (ip_str, &ip6);else -get_in_addr (ip_str, &ip); +tst_get_in_addr (ip_str, &ip); -print_svar_change (is_rhost ?"RHOST_IFACES" :"LHOST_IFACES" , iface); +tst_print_svar_change (is_rhost ?"RHOST_IFACES" :"LHOST_IFACES" , + iface);if (is_ipv6)print_ivar (is_rhost ?"IPV6_RPREFIX" :"IPV6_LPREFIX" , prefix);else
testcases/lib/tst_net_ip_prefix.c +5 -5
@@ -67,22 +67,22 @@ int main(int argc, char *argv[]) prefix_str =strchr (ip_str,'/' );if (prefix_str) - prefix =get_prefix (ip_str, is_ipv6); + prefix =tst_get_prefix (ip_str, is_ipv6);else prefix = is_ipv6 ?DEFAULT_IPV6_PREFIX :DEFAULT_IPV4_PREFIX ;/* checks for validity of IP string */ if (is_ipv6) -get_in6_addr (ip_str, &ip6); +tst_get_in6_addr (ip_str, &ip6);else -get_in_addr (ip_str, &ip); +tst_get_in_addr (ip_str, &ip);if (is_ipv6) {print_ivar (is_rhost ?"IPV6_RPREFIX" :"IPV6_LPREFIX" , prefix); -print_svar (is_rhost ?"IPV6_RHOST" :"IPV6_LHOST" , ip_str); +tst_print_svar (is_rhost ?"IPV6_RHOST" :"IPV6_LHOST" , ip_str); }else {print_ivar (is_rhost ?"IPV4_RPREFIX" :"IPV4_LPREFIX" , prefix); -print_svar (is_rhost ?"IPV4_RHOST" :"IPV4_LHOST" , ip_str); +tst_print_svar (is_rhost ?"IPV4_RHOST" :"IPV4_LHOST" , ip_str); }exit (EXIT_SUCCESS );
testcases/lib/tst_net_vars.c +32 -32
132 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 1/3 Create separate .c file for include/tst_net.h
Hi!
include/tst_net.h line 30
Quoted 7 lines
include/tst_net.h +7
-0+int tst_bit_count (uint32_t i); +int tst_mask2prefix (struct in_addr mask); +int tst_ipv4_mask_to_int (const char *prefix); +int tst_safe_atoi (const char *s,int *ret_i); +int tst_get_prefix (const char *ip_str,int is_ipv6); +void tst_get_in_addr (const char *ip_str,struct in_addr *ip); +void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);
Do we need all of these exported in the public API?
It looks to me like most of these shouldn't be exported at all.
Quoted 365 lines
lib/tst_net.c new file +146
-0@@ -0,0 +1,146 @@ +/* +* Copyright (c) 2017 Petr Vorel <[email protected]> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <errno.h> +#include <string.h> +#include <stdlib.h> + +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "tst_net.h" + +void tst_print_svar (const char *name,const char *val) +{ +if (name && val) +printf ("export %s=\"%s\"\n" , name, val); +} + +void tst_print_svar_change (const char *name,const char *val) +{ +if (name && val) +printf ("export %s=\"${%s:-%s}\"\n" , name, name, val); +} + +/* +* Function bit_count is from ipcalc project, ipcalc.c. +*/ +int tst_bit_count (uint32_t i) +{ +int c =0 ; +unsigned int seen_one =0 ; + +while (i >0 ) { +if (i &1 ) { + seen_one =1 ; + c++; + }else { +if (seen_one) +return -1 ; + } + i >>=1 ; + } + +return c; +} + +/* +* Function mask2prefix is from ipcalc project, ipcalc.c. +*/ +int tst_mask2prefix (struct in_addr mask) +{ +return tst_bit_count (ntohl (mask.s_addr)); +} + +/* +* Function ipv4_mask_to_int is from ipcalc project, ipcalc.c. +*/ +int tst_ipv4_mask_to_int (const char *prefix) +{ +int ret; +struct in_addr in; + + ret =inet_pton (AF_INET , prefix, &in); +if (ret ==0 ) +return -1 ; + +return tst_mask2prefix (in); +} + +/* +* Function safe_atoi is from ipcalc project, ipcalc.c. +*/ +int tst_safe_atoi (const char *s,int *ret_i) +{ +char *x =NULL ; +long l; + + errno =0 ; + l =strtol (s, &x,0 ); + +if (!x || x == s || *x || errno) +return errno >0 ? -errno : -EINVAL ; + +if ((long )(int )l != l) +return -ERANGE ; + + *ret_i = (int )l; + +return 0 ; +} + +/* +* Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c. +*/ +int tst_get_prefix (const char *ip_str,int is_ipv6) +{ +char *prefix_str =NULL ; +int prefix =-1 , r; + + prefix_str =strchr (ip_str,'/' ); +if (!prefix_str) +return -1 ; + + *(prefix_str++) ='\0' ; + +if (!is_ipv6 &&strchr (prefix_str,'.' )) + prefix =tst_ipv4_mask_to_int (prefix_str); +else { + r =tst_safe_atoi (prefix_str, &prefix); +if (r !=0 ) +tst_brk_comment ("conversion error: '%s' is not integer" , + prefix_str); + } + +if (prefix <0 || ((is_ipv6 && prefix >MAX_IPV6_PREFIX ) || + (!is_ipv6 && prefix >MAX_IPV4_PREFIX ))) +tst_brk_comment ("bad %s prefix: %s" , is_ipv6 ?"IPv6" :"IPv4" , + prefix_str); + +return prefix; +} + +void tst_get_in_addr (const char *ip_str,struct in_addr *ip) +{ +if (inet_pton (AF_INET , ip_str, ip) <=0 ) +tst_brk_comment ("bad IPv4 address: '%s'" , ip_str); +} + +void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6) +{ +if (inet_pton (AF_INET6 , ip_str, ip6) <=0 ) +tst_brk_comment ("bad IPv6 address: '%s'" , ip_str); +}testcases/lib/tst_net_iface_prefix.c +5
-4@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) prefix_str =strchr (ip_str,'/' );if (prefix_str) { - prefix =get_prefix (ip_str, is_ipv6); + prefix =tst_get_prefix (ip_str, is_ipv6);tst_res_comment (TINFO ,"IP address '%s' contains prefix %d, using it and don't search for iface.\n" , ip_str, prefix);@@ -136,11 +136,12 @@ int main(int argc, char *argv[])/* checks for validity of IP string */ if (is_ipv6) -get_in6_addr (ip_str, &ip6); +tst_get_in6_addr (ip_str, &ip6);else -get_in_addr (ip_str, &ip); +tst_get_in_addr (ip_str, &ip); -print_svar_change (is_rhost ?"RHOST_IFACES" :"LHOST_IFACES" , iface); +tst_print_svar_change (is_rhost ?"RHOST_IFACES" :"LHOST_IFACES" , + iface);if (is_ipv6)print_ivar (is_rhost ?"IPV6_RPREFIX" :"IPV6_LPREFIX" , prefix);else testcases/lib/tst_net_ip_prefix.c +5
-5@@ -67,22 +67,22 @@ int main(int argc, char *argv[]) prefix_str =strchr (ip_str,'/' );if (prefix_str) - prefix =get_prefix (ip_str, is_ipv6); + prefix =tst_get_prefix (ip_str, is_ipv6);else prefix = is_ipv6 ?DEFAULT_IPV6_PREFIX :DEFAULT_IPV4_PREFIX ;/* checks for validity of IP string */ if (is_ipv6) -get_in6_addr (ip_str, &ip6); +tst_get_in6_addr (ip_str, &ip6);else -get_in_addr (ip_str, &ip); +tst_get_in_addr (ip_str, &ip);if (is_ipv6) {print_ivar (is_rhost ?"IPV6_RPREFIX" :"IPV6_LPREFIX" , prefix); -print_svar (is_rhost ?"IPV6_RHOST" :"IPV6_LHOST" , ip_str); +tst_print_svar (is_rhost ?"IPV6_RHOST" :"IPV6_LHOST" , ip_str); }else {print_ivar (is_rhost ?"IPV4_RPREFIX" :"IPV4_LPREFIX" , prefix); -print_svar (is_rhost ?"IPV4_RHOST" :"IPV4_LHOST" , ip_str); +tst_print_svar (is_rhost ?"IPV4_RHOST" :"IPV4_LHOST" , ip_str); }exit (EXIT_SUCCESS );testcases/lib/tst_net_vars.c +32
-32@@ -217,7 +217,7 @@ static char *get_ipv4_net16_unused(const struct in_addr *ip, DEFAULT_IPV4_UNUSED_PART2);sprintf (buf,"%s.0.0" , net_unused); -get_in_addr (buf, &network); +tst_get_in_addr (buf, &network);if (!is_in_subnet_ipv4 (ip, &mask, &network))return strdup (net_unused);@@ -229,7 +229,7 @@ static char *get_ipv4_net16_unused(const struct in_addr *ip, (rand() % 128) + (((ip->s_addr >> 8) & 0xff) < 128 ? 128 : 0));sprintf (buf,"%s.0.0" , net_unused); -get_in_addr (buf, &network); +tst_get_in_addr (buf, &network);if (!is_in_subnet_ipv4 (ip, &mask, &network))return strdup (net_unused);@@ -239,7 +239,7 @@ static char *get_ipv4_net16_unused(const struct in_addr *ip, < 128 ? 128 : 0), DEFAULT_IPV4_UNUSED_PART2);sprintf (buf,"%s.0.0" , net_unused); -get_in_addr (buf, &network); +tst_get_in_addr (buf, &network);if (!is_in_subnet_ipv4 (ip, &mask, &network))return strdup (net_unused);@@ -281,7 +281,7 @@ static char *get_ipv6_net32_unused(const struct in6_addr *ip6, DEFAULT_IPV6_UNUSED_PART2);sprintf (buf,"%s::" , net_unused); -get_in6_addr (buf, &network); +tst_get_in6_addr (buf, &network);if (!is_in_subnet_ipv6 (ip6, &mask, &network))return strdup (net_unused);@@ -294,7 +294,7 @@ static char *get_ipv6_net32_unused(const struct in6_addr *ip6, DEFAULT_IPV6_UNUSED_PART2);sprintf (buf,"%s::" , net_unused); -get_in6_addr (buf, &network); +tst_get_in6_addr (buf, &network);if (!is_in_subnet_ipv6 (ip6, &mask, &network))return strdup (net_unused);@@ -305,7 +305,7 @@ static char *get_ipv6_net32_unused(const struct in6_addr *ip6, 128 : 0), DEFAULT_IPV6_UNUSED_PART2);sprintf (buf,"%s::" , net_unused); -get_in6_addr (buf, &network); +tst_get_in6_addr (buf, &network);if (!is_in_subnet_ipv6 (ip6, &mask, &network))return strdup (net_unused);@@ -503,8 +503,8 @@ static void get_ipv4_info(const char *lip_str, const char *rip_str, int lprefix, lprefix_round =round_down_prefix (lprefix,0 ); rprefix_round =round_down_prefix (rprefix,0 ); -get_in_addr (lip_str, &lip); -get_in_addr (rip_str, &rip); +tst_get_in_addr (lip_str, &lip); +tst_get_in_addr (rip_str, &rip); vars.ipv4_lbroadcast =get_ipv4_broadcast (lip, lprefix); vars.ipv4_rbroadcast =get_ipv4_broadcast (rip, rprefix);@@ -530,8 +530,8 @@ static void get_ipv6_info(const char *lip_str, const char *rip_str, lprefix_round =round_down_prefix (lprefix,1 ); rprefix_round =round_down_prefix (rprefix,1 ); -get_in6_addr (lip_str, &lip); -get_in6_addr (rip_str, &rip); +tst_get_in6_addr (lip_str, &lip); +tst_get_in6_addr (rip_str, &rip); vars.ipv6_lnetmask =get_ipv6_netmask (lprefix); vars.ipv6_rnetmask =get_ipv6_netmask (rprefix);@@ -548,23 +548,23 @@ static void get_ipv6_info(const char *lip_str, const char *rip_str,static void print_vars (int is_ipv6) {if (is_ipv6) { -print_svar ("IPV6_LNETMASK" , vars.ipv6_lnetmask); -print_svar_change ("IPV6_RNETMASK" , vars.ipv6_rnetmask); -print_svar ("IPV6_LNETWORK" , vars.ipv6_lnetwork); -print_svar ("IPV6_RNETWORK" , vars.ipv6_rnetwork); -print_svar ("LHOST_IPV6_HOST" , vars.lhost_ipv6_host); -print_svar ("RHOST_IPV6_HOST" , vars.rhost_ipv6_host); -print_svar ("IPV6_NET32_UNUSED" , vars.ipv6_net32_unused); +tst_print_svar ("IPV6_LNETMASK" , vars.ipv6_lnetmask); +tst_print_svar_change ("IPV6_RNETMASK" , vars.ipv6_rnetmask); +tst_print_svar ("IPV6_LNETWORK" , vars.ipv6_lnetwork); +tst_print_svar ("IPV6_RNETWORK" , vars.ipv6_rnetwork); +tst_print_svar ("LHOST_IPV6_HOST" , vars.lhost_ipv6_host); +tst_print_svar ("RHOST_IPV6_HOST" , vars.rhost_ipv6_host); +tst_print_svar ("IPV6_NET32_UNUSED" , vars.ipv6_net32_unused); }else { -print_svar ("IPV4_LBROADCAST" , vars.ipv4_lbroadcast); -print_svar_change ("IPV4_RBROADCAST" , vars.ipv4_rbroadcast); -print_svar ("IPV4_LNETMASK" , vars.ipv4_lnetmask); -print_svar_change ("IPV4_RNETMASK" , vars.ipv4_rnetmask); -print_svar ("IPV4_LNETWORK" , vars.ipv4_lnetwork); -print_svar ("IPV4_RNETWORK" , vars.ipv4_rnetwork); -print_svar ("LHOST_IPV4_HOST" , vars.lhost_ipv4_host); -print_svar ("RHOST_IPV4_HOST" , vars.rhost_ipv4_host); -print_svar ("IPV4_NET16_UNUSED" , vars.ipv4_net16_unused); +tst_print_svar ("IPV4_LBROADCAST" , vars.ipv4_lbroadcast); +tst_print_svar_change ("IPV4_RBROADCAST" , vars.ipv4_rbroadcast); +tst_print_svar ("IPV4_LNETMASK" , vars.ipv4_lnetmask); +tst_print_svar_change ("IPV4_RNETMASK" , vars.ipv4_rnetmask); +tst_print_svar ("IPV4_LNETWORK" , vars.ipv4_lnetwork); +tst_print_svar ("IPV4_RNETWORK" , vars.ipv4_rnetwork); +tst_print_svar ("LHOST_IPV4_HOST" , vars.lhost_ipv4_host); +tst_print_svar ("RHOST_IPV4_HOST" , vars.rhost_ipv4_host); +tst_print_svar ("IPV4_NET16_UNUSED" , vars.ipv4_net16_unused); } }@@ -586,19 +586,19 @@ int main(int argc, char *argv[]) rip_str = argv[2 ]; is_ipv6 = !!strchr (lip_str,':' ); - lprefix =get_prefix (lip_str, is_ipv6); - rprefix =get_prefix (rip_str, is_ipv6); + lprefix =tst_get_prefix (lip_str, is_ipv6); + rprefix =tst_get_prefix (rip_str, is_ipv6);if (is_ipv6) -get_in6_addr (lip_str, &ip6); +tst_get_in6_addr (lip_str, &ip6);else -get_in_addr (lip_str, &ip); +tst_get_in_addr (lip_str, &ip); tmp = !!strchr (rip_str,':' );if (tmp) -get_in6_addr (rip_str, &ip6); +tst_get_in6_addr (rip_str, &ip6);else -get_in_addr (rip_str, &ip); +tst_get_in_addr (rip_str, &ip);if (is_ipv6 != tmp) tst_brk_comment("mixed IPv4 and IPv6 addresses ('%s', '%s')",Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/3 Create separate .c file for include/tst_net.h
Quoted 11 lines · Cyril Hrubis
Hi!
include/tst_net.h line 30
Quoted 7 lines
include/tst_net.h +7
-0+int tst_bit_count (uint32_t i); +int tst_mask2prefix (struct in_addr mask); +int tst_ipv4_mask_to_int (const char *prefix); +int tst_safe_atoi (const char *s,int *ret_i); +int tst_get_prefix (const char *ip_str,int is_ipv6); +void tst_get_in_addr (const char *ip_str,struct in_addr *ip); +void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);Do we need all of these exported in the public API?
Quoted 1 line
It looks to me like most of these shouldn't be exported at all.
I guess that's a question for Petr. I'll be happy to drop the functions meant to be private from the .h file and make them static in the .c file.
Signature · 7 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic
PATCH v3 1/3 Create separate .c file for include/tst_net.h
Hi!
Quoted 10 lines
Quoted 10 lines
include/tst_net.h line 30
Quoted 7 lines
include/tst_net.h +7
-0+int tst_bit_count (uint32_t i); +int tst_mask2prefix (struct in_addr mask); +int tst_ipv4_mask_to_int (const char *prefix); +int tst_safe_atoi (const char *s,int *ret_i); +int tst_get_prefix (const char *ip_str,int is_ipv6); +void tst_get_in_addr (const char *ip_str,struct in_addr *ip); +void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);Do we need all of these exported in the public API?
Quoted 4 lines
Quoted 1 line
It looks to me like most of these shouldn't be exported at all.
I guess that's a question for Petr. I'll be happy to drop the functions meant to be private from the .h file and make them static in the .c file.
Let's do that, there is no point in exporting unused functions.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/3 Create separate .c file for include/tst_net.h
Hi Martin, Cyril,
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
include/tst_net.h line 30
Quoted 7 lines
include/tst_net.h +7
-0+int tst_bit_count (uint32_t i); +int tst_mask2prefix (struct in_addr mask); +int tst_ipv4_mask_to_int (const char *prefix); +int tst_safe_atoi (const char *s,int *ret_i); +int tst_get_prefix (const char *ip_str,int is_ipv6); +void tst_get_in_addr (const char *ip_str,struct in_addr *ip); +void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);Do we need all of these exported in the public API?
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
It looks to me like most of these shouldn't be exported at all.
I guess that's a question for Petr. I'll be happy to drop the functions meant to be private from the .h file and make them static in the .c file.
Let's do that, there is no point in exporting unused functions.
When I created tst_net.h, I thought functions would be used in other tests, as they're general network functions. This is not true for tst_{brk,res}_comment() macro, MAX_IPV{4,6}_PREFIX defintions and tst_safe_atoi() which are specific tst_net_{iface,ip}_prefix.c and tst_net_vars.c. We should probably have separate header (and probably source file) for these macros and for functions which aren't needed (yet), which would be used just for tst_net_{iface,ip}_prefix.c and tst_net_vars.c and not exported by API.
tst_safe_atoi() has confusing name, because this function does not lead to tst_brk(), but uses tst_brk_comment() (it's a bit confusing, but not sure for proper name).
But maybe you meant to have all of them as private (accessible by few C sources which need them and export only these new functions Martin added in his second commit.
Kind regards,
Petr
PATCH v3 2/3 Add socket address initialization functions to tst_net library
In reply to Martin Doucha---
Changes since v1:
- new patch
Changes since v2:
- Added tst_ prefix to the new functions
include/tst_net.h | 16 +++++++++++ lib/tst_net.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+)
include/tst_net.h +16 -0
@@ -5,6 +5,9 @@#include <arpa/inet.h> #include <stdio.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <netinet/ip.h> #define MAX_IPV4_PREFIX 32#define MAX_IPV6_PREFIX 128
@@ -28,3 +31,16 @@ int tst_safe_atoi(const char *s, int *ret_i);int tst_get_prefix (const char *ip_str,int is_ipv6);void tst_get_in_addr (const char *ip_str,struct in_addr *ip);void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6); + +/* +* Find valid connection address for a given bound socket +*/ +socklen_t tst_get_connect_address (int sock,struct sockaddr_storage *addr); + +/* +* Initialize AF_INET/AF_INET6 socket address structure with address and port +*/ +void tst_init_sockaddr_inet (struct sockaddr_in *sa,const char *ip_str,uint16_t port); +void tst_init_sockaddr_inet_bin (struct sockaddr_in *sa,uint32_t ip_val,uint16_t port); +void tst_init_sockaddr_inet6 (struct sockaddr_in6 *sa,const char *ip_str,uint16_t port); +void tst_init_sockaddr_inet6_bin (struct sockaddr_in6 *sa,const struct in6_addr *ip_val,uint16_t port);
lib/tst_net.c +71 -0
79 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 3/3 Add connection tests for bind()
In reply to Martin DouchaAdd two new test programs to verify that bind() will open sockets for incoming connections. Both programs follow the same test scenario:
- Create and bind() a socket
- Wait for connection from peer thread
- Send request to peer thread
- Receive and verify response from peer thread
bind04 tests stream-oriented sockets (SOCK_STREAM and SOCK_SEQPACKET). bind05 tests datagram-oriented sockets (SOCK_DGRAM).
Both programs test the following socket types:
- AF_UNIX (pathname and abstract addresses)
- AF_INET (loopback)
- AF_INET6 (loopback)
---
Changes since v1:
- added UDPLITE and SCTP test cases
- common constants and test_case data structure moved to libbind.h
Changes since v2:
- Code style fixes
- Makefile fix
Regarding review comments about the cleanup of AF_UNIX sockets: It doesn't really matter if the socket gets explicitly unlink()ed after tst_brk(). LTP library will remove it either way when it removes the temp directory. The real issue is that in the second test case (or test iteration) with named Unix sockets, bind() will fail if the path already exists. Even when it's a socket file closed on both ends.
runtest/syscalls | 2 + testcases/kernel/syscalls/bind/.gitignore | 2 + testcases/kernel/syscalls/bind/Makefile | 2 + testcases/kernel/syscalls/bind/bind04.c | 172 ++++++++++++++++++++ testcases/kernel/syscalls/bind/bind05.c | 186 ++++++++++++++++++++++ testcases/kernel/syscalls/bind/libbind.h | 29 ++++ 6 files changed, 393 insertions(+) create mode 100644 testcases/kernel/syscalls/bind/bind04.c create mode 100644 testcases/kernel/syscalls/bind/bind05.c create mode 100644 testcases/kernel/syscalls/bind/libbind.h
runtest/syscalls +2 -0
@@ -31,6 +31,8 @@ alarm07 alarm07 bind01 bind01 bind02 bind02 bind03 bind03 +bind04 bind04 +bind05 bind05 bpf_map01 bpf_map01 bpf_prog01 bpf_prog01
testcases/kernel/syscalls/bind/.gitignore +2 -0
@@ -1,3 +1,5 @@ /bind01 /bind02 /bind03 +/bind04 +/bind05
testcases/kernel/syscalls/bind/Makefile +2 -0
@@ -5,4 +5,6 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk +bind04 bind05: CFLAGS += -pthread + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/bind/bind04.c new file +172 -0
172 lines not on this page · raw message
testcases/kernel/syscalls/bind/bind05.c new file +186 -0
186 lines not on this page · raw message
testcases/kernel/syscalls/bind/libbind.h new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 Martin Doucha <[email protected]> +*/ + +/* +* Common settings and data types for bind() connection tests +*/ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <arpa/inet.h> +#include <netinet/in.h> +#include <netinet/ip.h> + +#define MAIN_SOCKET_FILE "test.sock" +#define ABSTRACT_SOCKET_PATH "\0test.sock" +#define PEER_SOCKET_FILE "peer.sock" +#define IPV4_ADDRESS "127.0.0.1" +#define IPV6_ADDRESS "::1" +#define BUFFER_SIZE 128 + +struct test_case { +int type, protocol; +struct sockaddr *address; +socklen_t addrlen; +const char *description; +};
Signature · 1 line
2.25.1