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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/networking/timestamping/hwtstamp_config.c

Version: ~ [ linux-5.1-rc1 ] ~ [ linux-5.0.3 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.30 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.107 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.164 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.176 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.136 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.63 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ 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 static int
 20 lookup_value(const char **names, int size, const char *name)
 21 {
 22         int value;
 23 
 24         for (value = 0; value < size; value++)
 25                 if (names[value] && strcasecmp(names[value], name) == 0)
 26                         return value;
 27 
 28         return -1;
 29 }
 30 
 31 static const char *
 32 lookup_name(const char **names, int size, int value)
 33 {
 34         return (value >= 0 && value < size) ? names[value] : NULL;
 35 }
 36 
 37 static void list_names(FILE *f, const char **names, int size)
 38 {
 39         int value;
 40 
 41         for (value = 0; value < size; value++)
 42                 if (names[value])
 43                         fprintf(f, "    %s\n", names[value]);
 44 }
 45 
 46 static const char *tx_types[] = {
 47 #define TX_TYPE(name) [HWTSTAMP_TX_ ## name] = #name
 48         TX_TYPE(OFF),
 49         TX_TYPE(ON),
 50         TX_TYPE(ONESTEP_SYNC)
 51 #undef TX_TYPE
 52 };
 53 #define N_TX_TYPES ((int)(sizeof(tx_types) / sizeof(tx_types[0])))
 54 
 55 static const char *rx_filters[] = {
 56 #define RX_FILTER(name) [HWTSTAMP_FILTER_ ## name] = #name
 57         RX_FILTER(NONE),
 58         RX_FILTER(ALL),
 59         RX_FILTER(SOME),
 60         RX_FILTER(PTP_V1_L4_EVENT),
 61         RX_FILTER(PTP_V1_L4_SYNC),
 62         RX_FILTER(PTP_V1_L4_DELAY_REQ),
 63         RX_FILTER(PTP_V2_L4_EVENT),
 64         RX_FILTER(PTP_V2_L4_SYNC),
 65         RX_FILTER(PTP_V2_L4_DELAY_REQ),
 66         RX_FILTER(PTP_V2_L2_EVENT),
 67         RX_FILTER(PTP_V2_L2_SYNC),
 68         RX_FILTER(PTP_V2_L2_DELAY_REQ),
 69         RX_FILTER(PTP_V2_EVENT),
 70         RX_FILTER(PTP_V2_SYNC),
 71         RX_FILTER(PTP_V2_DELAY_REQ),
 72 #undef RX_FILTER
 73 };
 74 #define N_RX_FILTERS ((int)(sizeof(rx_filters) / sizeof(rx_filters[0])))
 75 
 76 static void usage(void)
 77 {
 78         fputs("Usage: hwtstamp_config if_name [tx_type rx_filter]\n"
 79               "tx_type is any of (case-insensitive):\n",
 80               stderr);
 81         list_names(stderr, tx_types, N_TX_TYPES);
 82         fputs("rx_filter is any of (case-insensitive):\n", stderr);
 83         list_names(stderr, rx_filters, N_RX_FILTERS);
 84 }
 85 
 86 int main(int argc, char **argv)
 87 {
 88         struct ifreq ifr;
 89         struct hwtstamp_config config;
 90         const char *name;
 91         int sock;
 92 
 93         if ((argc != 2 && argc != 4) || (strlen(argv[1]) >= IFNAMSIZ)) {
 94                 usage();
 95                 return 2;
 96         }
 97 
 98         if (argc == 4) {
 99                 config.flags = 0;
100                 config.tx_type = lookup_value(tx_types, N_TX_TYPES, argv[2]);
101                 config.rx_filter = lookup_value(rx_filters, N_RX_FILTERS, argv[3]);
102                 if (config.tx_type < 0 || config.rx_filter < 0) {
103                         usage();
104                         return 2;
105                 }
106         }
107 
108         sock = socket(AF_INET, SOCK_DGRAM, 0);
109         if (sock < 0) {
110                 perror("socket");
111                 return 1;
112         }
113 
114         strcpy(ifr.ifr_name, argv[1]);
115         ifr.ifr_data = (caddr_t)&config;
116 
117         if (ioctl(sock, (argc == 2) ? SIOCGHWTSTAMP : SIOCSHWTSTAMP, &ifr)) {
118                 perror("ioctl");
119                 return 1;
120         }
121 
122         printf("flags = %#x\n", config.flags);
123         name = lookup_name(tx_types, N_TX_TYPES, config.tx_type);
124         if (name)
125                 printf("tx_type = %s\n", name);
126         else
127                 printf("tx_type = %d\n", config.tx_type);
128         name = lookup_name(rx_filters, N_RX_FILTERS, config.rx_filter);
129         if (name)
130                 printf("rx_filter = %s\n", name);
131         else
132                 printf("rx_filter = %d\n", config.rx_filter);
133 
134         return 0;
135 }
136 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp