blob: 6dc4743c333fd443cc18eaa34c4f5ac72852843e [file] [log] [blame]
Jan Engelhardt0720c122008-01-20 13:22:42 +00001#include <stdbool.h>
2#include <stdint.h>
3#include <stdio.h>
Jan Engelhardtef18e812008-08-04 12:47:48 +02004#include <linux/ip.h>
Jan Engelhardt0720c122008-01-20 13:22:42 +00005
Jan Engelhardt350661a2010-01-31 22:42:52 +01006#ifndef IPTOS_NORMALSVC
7# define IPTOS_NORMALSVC 0
8#endif
9
Jan Engelhardt0720c122008-01-20 13:22:42 +000010struct tos_value_mask {
11 uint8_t value, mask;
12};
13
14static const struct tos_symbol_info {
15 unsigned char value;
16 const char *name;
17} tos_symbol_names[] = {
18 {IPTOS_LOWDELAY, "Minimize-Delay"},
19 {IPTOS_THROUGHPUT, "Maximize-Throughput"},
20 {IPTOS_RELIABILITY, "Maximize-Reliability"},
21 {IPTOS_MINCOST, "Minimize-Cost"},
22 {IPTOS_NORMALSVC, "Normal-Service"},
Jan Engelhardt32b8e612010-07-23 21:16:14 +020023 {},
Jan Engelhardt0720c122008-01-20 13:22:42 +000024};
25
Jan Engelhardt0720c122008-01-20 13:22:42 +000026static bool tos_try_print_symbolic(const char *prefix,
Jan Engelhardt7ac40522011-01-07 12:34:04 +010027 uint8_t value, uint8_t mask)
Jan Engelhardt0720c122008-01-20 13:22:42 +000028{
29 const struct tos_symbol_info *symbol;
30
31 if (mask != 0x3F)
32 return false;
33
34 for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
35 if (value == symbol->value) {
Jan Engelhardt73866352010-12-18 02:04:59 +010036 printf(" %s%s", prefix, symbol->name);
Jan Engelhardt0720c122008-01-20 13:22:42 +000037 return true;
38 }
39
40 return false;
41}