Home | History | Annotate | Download | only in patches
      1 TX_RING support for TPACKET_V3 was added in this commit:
      2 
      3 commit 7f953ab2ba46e8649537942c0a64668ca2ce5cc5
      4 Author: Sowmini Varadhan <sowmini.varadhan (a] oracle.com>
      5 Date:   Tue Jan 3 06:31:47 2017 -0800
      6 
      7     af_packet: TX_RING support for TPACKET_V3
      8 
      9 which first appeared in 4.11. Do not attempt to test TX_RING
     10 support for TPACKET_V3 on kernels earlier than this.
     11 
     12 diff --git a/tools/testing/selftests/net/psock_tpacket.c b/tools/testing/selftests/net/psock_tpacket.c
     13 index e795a41c4771..c50375f51b2e 100644
     14 --- a/tools/testing/selftests/net/psock_tpacket.c
     15 +++ b/tools/testing/selftests/net/psock_tpacket.c
     16 @@ -42,6 +42,7 @@
     17  #include <sys/stat.h>
     18  #include <sys/socket.h>
     19  #include <sys/mman.h>
     20 +#include <sys/utsname.h>
     21  #include <linux/if_packet.h>
     22  #include <linux/filter.h>
     23  #include <ctype.h>
     24 @@ -844,9 +845,34 @@ static int test_tpacket(int version, int type)
     25  	return 0;
     26  }
     27  
     28 +void get_kernel_version(int *version, int *patchlevel)
     29 +{
     30 +	int ret, sublevel;
     31 +	struct utsname utsname;
     32 +
     33 +	ret = uname(&utsname);
     34 +	if (ret) {
     35 +		perror("uname");
     36 +		exit(1);
     37 +	}
     38 +
     39 +	ret = sscanf(utsname.release, "%d.%d.%d", version, patchlevel,
     40 +		     &sublevel);
     41 +	if (ret < 0) {
     42 +		perror("sscanf");
     43 +		exit(1);
     44 +	} else if (ret != 3) {
     45 +		printf("Malformed kernel version %s\n", &utsname.release);
     46 +		exit(1);
     47 +	}
     48 +}
     49 +
     50  int main(void)
     51  {
     52  	int ret = 0;
     53 +	int version, patchlevel;
     54 +
     55 +	get_kernel_version(&version, &patchlevel);
     56  
     57  	ret |= test_tpacket(TPACKET_V1, PACKET_RX_RING);
     58  	ret |= test_tpacket(TPACKET_V1, PACKET_TX_RING);
     59 @@ -855,7 +881,8 @@ int main(void)
     60  	ret |= test_tpacket(TPACKET_V2, PACKET_TX_RING);
     61  
     62  	ret |= test_tpacket(TPACKET_V3, PACKET_RX_RING);
     63 -	ret |= test_tpacket(TPACKET_V3, PACKET_TX_RING);
     64 +	if (version > 4 || (version == 4 && patchlevel >= 11))
     65 +		ret |= test_tpacket(TPACKET_V3, PACKET_TX_RING);
     66  
     67  	if (ret)
     68  		return 1;
     69