libnl  3.6.0
police.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
4  */
5 
6 #include <netlink-private/netlink.h>
7 #include <netlink-private/tc.h>
8 #include <netlink/netlink.h>
9 #include <netlink/utils.h>
10 #include <netlink-private/route/tc-api.h>
11 #include <netlink/route/classifier.h>
12 #include <netlink/route/cls/police.h>
13 
14 /**
15  * @name Policer Type
16  * @{
17  */
18 
19 static const struct trans_tbl police_types[] = {
20  __ADD(TC_POLICE_UNSPEC,unspec),
21  __ADD(TC_POLICE_OK,ok),
22  __ADD(TC_POLICE_RECLASSIFY,reclassify),
23  __ADD(TC_POLICE_SHOT,shot),
24 #ifdef TC_POLICE_PIPE
25  __ADD(TC_POLICE_PIPE,pipe),
26 #endif
27 };
28 
29 /**
30  * Transform a policer type number into a character string (Reentrant).
31  * @arg type policer type
32  * @arg buf destination buffer
33  * @arg len buffer length
34  *
35  * Transforms a policer type number into a character string and stores
36  * it in the provided buffer.
37  *
38  * @return The destination buffer or the type encoded in hex if no match was found.
39  */
40 char * nl_police2str(int type, char *buf, size_t len)
41 {
42  return __type2str(type, buf, len, police_types,
43  ARRAY_SIZE(police_types));
44 }
45 
46 /**
47  * Transform a character string into a policer type number
48  * @arg name policer type name
49  *
50  * Transform the provided character string specifying a policer
51  * type into the corresponding numeric value
52  *
53  * @return Policer type number or a negative value.
54  */
55 int nl_str2police(const char *name)
56 {
57  return __str2type(name, police_types, ARRAY_SIZE(police_types));
58 }
59 
60 /** @} */