1 /*
2 * lib/route/cls/police.c Policer
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
7 * of the License.
8 *
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10 */
11
12 #include <netlink-local.h>
13 #include <netlink-tc.h>
14 #include <netlink/netlink.h>
15 #include <netlink/utils.h>
16 #include <netlink/route/tc.h>
17 #include <netlink/route/classifier.h>
18 #include <netlink/route/classifier-modules.h>
19 #include <netlink/route/cls/police.h>
20
21 /**
22 * @name Policer Type
23 * @{
24 */
25
26 static struct trans_tbl police_types[] = {
27 __ADD(TC_POLICE_UNSPEC,unspec)
28 __ADD(TC_POLICE_OK,ok)
29 __ADD(TC_POLICE_RECLASSIFY,reclassify)
30 __ADD(TC_POLICE_SHOT,shot)
31 #ifdef TC_POLICE_PIPE
32 __ADD(TC_POLICE_PIPE,pipe)
33 #endif
34 };
35
36 /**
37 * Transform a policer type number into a character string (Reentrant).
38 * @arg type policer type
39 * @arg buf destination buffer
40 * @arg len buffer length
41 *
42 * Transforms a policer type number into a character string and stores
43 * it in the provided buffer.
44 *
45 * @return The destination buffer or the type encoded in hex if no match was found.
46 */
nl_police2str(int type,char * buf,size_t len)47 char * nl_police2str(int type, char *buf, size_t len)
48 {
49 return __type2str(type, buf, len, police_types,
50 ARRAY_SIZE(police_types));
51 }
52
53 /**
54 * Transform a character string into a policer type number
55 * @arg name policer type name
56 *
57 * Transform the provided character string specifying a policer
58 * type into the corresponding numeric value
59 *
60 * @return Policer type number or a negative value.
61 */
nl_str2police(const char * name)62 int nl_str2police(const char *name)
63 {
64 return __str2type(name, police_types, ARRAY_SIZE(police_types));
65 }
66
67 /** @} */
68