summaryrefslogtreecommitdiff
path: root/lib/route/cls/police.c
blob: f2cd45ad6e89c97b2391d40b26d2863dcfc3c641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * lib/route/cls/police.c	Policer
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation version 2.1
 *	of the License.
 *
 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
 */

#include <netlink-local.h>
#include <netlink-tc.h>
#include <netlink/netlink.h>
#include <netlink/utils.h>
#include <netlink/route/tc.h>
#include <netlink/route/classifier.h>
#include <netlink/route/classifier-modules.h>
#include <netlink/route/cls/police.h>

/**
 * @name Policer Type
 * @{
 */

static const struct trans_tbl police_types[] = {
	__ADD(TC_POLICE_UNSPEC,unspec)
	__ADD(TC_POLICE_OK,ok)
	__ADD(TC_POLICE_RECLASSIFY,reclassify)
	__ADD(TC_POLICE_SHOT,shot)
#ifdef TC_POLICE_PIPE
	__ADD(TC_POLICE_PIPE,pipe)
#endif
};

/**
 * Transform a policer type number into a character string (Reentrant).
 * @arg type		policer type
 * @arg buf		destination buffer
 * @arg len		buffer length
 *
 * Transforms a policer type number into a character string and stores
 * it in the provided buffer.
 *
 * @return The destination buffer or the type encoded in hex if no match was found.
 */
char * nl_police2str(int type, char *buf, size_t len)
{
	return __type2str(type, buf, len, police_types,
			  ARRAY_SIZE(police_types));
}

/**
 * Transform a character string into a policer type number
 * @arg name		policer type name
 *
 * Transform the provided character string specifying a policer
 * type into the corresponding numeric value
 *
 * @return Policer type number or a negative value.
 */
int nl_str2police(const char *name)
{
	return __str2type(name, police_types, ARRAY_SIZE(police_types));
}

/** @} */