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