~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/hwtstamp_config.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Test program for SIOC{G,S}HWTSTAMP
  3  * Copyright 2013 Solarflare Communications
  4  * Author: Ben Hutchings
  5  */
  6 
  7 #include <errno.h>
  8 #include <stdio.h>
  9 #include <stdlib.h>
 10 #include <string.h>
 11 
 12 #include <sys/socket.h>
 13 #include <sys/ioctl.h>
 14 
 15 #include <linux/if.h>
 16 #include <linux/net_tstamp.h>
 17 #include <linux/sockios.h>
 18 
 19 #include "kselftest.h"
 20 
 21 static int
 22 lookup_value(const char **names, int size, const char *name)
 23 {
 24         int value;
 25 
 26         for (value = 0; value < size; value++)
 27                 if (names[value] && strcasecmp(names[value], name) == 0)
 28                         return value;
 29 
 30         return -1;
 31 }
 32 
 33 static const char *
 34 lookup_name(const char **names, int size, int value)
 35 {
 36         return (value >= 0 && value < size) ? names[value] : NULL;
 37 }
 38 
 39 static void list_names(FILE *f, const char **names, int size)
 40 {
 41         int value;
 42 
 43         for (value = 0; value < size; value++)
 44                 if (names[value])
 45                         fprintf(f, "    %s\n", names[value]);
 46 }
 47 
 48 static const char *tx_types[] = {
 49 #define TX_TYPE(name) [HWTSTAMP_TX_ ## name] = #name
 50         TX_TYPE(OFF),
 51         TX_TYPE(ON),
 52         TX_TYPE(ONESTEP_SYNC)
 53 #undef TX_TYPE
 54 };
 55 #define N_TX_TYPES ((int)(ARRAY_SIZE(tx_types)))
 56 
 57 static const char *rx_filters[] = {
 58 #define RX_FILTER(name) [HWTSTAMP_FILTER_ ## name] = #name
 59         RX_FILTER(NONE),
 60         RX_FILTER(ALL),
 61         RX_FILTER(SOME),
 62         RX_FILTER(PTP_V1_L4_EVENT),
 63         RX_FILTER(PTP_V1_L4_SYNC),
 64         RX_FILTER(PTP_V1_L4_DELAY_REQ),
 65         RX_FILTER(PTP_V2_L4_EVENT),
 66         RX_FILTER(PTP_V2_L4_SYNC),
 67         RX_FILTER(PTP_V2_L4_DELAY_REQ),
 68         RX_FILTER(PTP_V2_L2_EVENT),
 69         RX_FILTER(PTP_V2_L2_SYNC),
 70         RX_FILTER(PTP_V2_L2_DELAY_REQ),
 71         RX_FILTER(PTP_V2_EVENT),
 72         RX_FILTER(PTP_V2_SYNC),
 73         RX_FILTER(PTP_V2_DELAY_REQ),
 74 #undef RX_FILTER
 75 };
 76 #define N_RX_FILTERS ((int)(ARRAY_SIZE(rx_filters)))
 77 
 78 static void usage(void)
 79 {
 80         fputs("Usage: hwtstamp_config if_name [tx_type rx_filter]\n"
 81               "tx_type is any of (case-insensitive):\n",
 82               stderr);
 83         list_names(stderr, tx_types, N_TX_TYPES);
 84         fputs("rx_filter is any of (case-insensitive):\n", stderr);
 85         list_names(stderr, rx_filters, N_RX_FILTERS);
 86 }
 87 
 88 int main(int argc, char **argv)
 89 {
 90         struct ifreq ifr;
 91         struct hwtstamp_config config;
 92         const char *name;
 93         int sock;
 94 
 95         if ((argc != 2 && argc != 4) || (strlen(argv[1]) >= IFNAMSIZ)) {
 96                 usage();
 97                 return 2;
 98         }
 99 
100         if (argc == 4) {
101                 config.flags = 0;
102                 config.tx_type = lookup_value(tx_types, N_TX_TYPES, argv[2]);
103                 config.rx_filter = lookup_value(rx_filters, N_RX_FILTERS, argv[3]);
104                 if (config.tx_type < 0 || config.rx_filter < 0) {
105                         usage();
106                         return 2;
107                 }
108         }
109 
110         sock = socket(AF_INET, SOCK_DGRAM, 0);
111         if (sock < 0) {
112                 perror("socket");
113                 return 1;
114         }
115 
116         strcpy(ifr.ifr_name, argv[1]);
117         ifr.ifr_data = (caddr_t)&config;
118 
119         if (ioctl(sock, (argc == 2) ? SIOCGHWTSTAMP : SIOCSHWTSTAMP, &ifr)) {
120                 perror("ioctl");
121                 return 1;
122         }
123 
124         printf("flags = %#x\n", config.flags);
125         name = lookup_name(tx_types, N_TX_TYPES, config.tx_type);
126         if (name)
127                 printf("tx_type = %s\n", name);
128         else
129                 printf("tx_type = %d\n", config.tx_type);
130         name = lookup_name(rx_filters, N_RX_FILTERS, config.rx_filter);
131         if (name)
132                 printf("rx_filter = %s\n", name);
133         else
134                 printf("rx_filter = %d\n", config.rx_filter);
135 
136         return 0;
137 }
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php