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