police.c

00001 /*
00002  * lib/route/cls/police.c       Policer
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 #include <netlink-local.h>
00013 #include <netlink-tc.h>
00014 #include <netlink/netlink.h>
00015 #include <netlink/utils.h>
00016 #include <netlink/route/tc-api.h>
00017 #include <netlink/route/classifier.h>
00018 #include <netlink/route/cls/police.h>
00019 
00020 /**
00021  * @name Policer Type
00022  * @{
00023  */
00024 
00025 static const struct trans_tbl police_types[] = {
00026         __ADD(TC_POLICE_UNSPEC,unspec)
00027         __ADD(TC_POLICE_OK,ok)
00028         __ADD(TC_POLICE_RECLASSIFY,reclassify)
00029         __ADD(TC_POLICE_SHOT,shot)
00030 #ifdef TC_POLICE_PIPE
00031         __ADD(TC_POLICE_PIPE,pipe)
00032 #endif
00033 };
00034 
00035 /**
00036  * Transform a policer type number into a character string (Reentrant).
00037  * @arg type            policer type
00038  * @arg buf             destination buffer
00039  * @arg len             buffer length
00040  *
00041  * Transforms a policer type number into a character string and stores
00042  * it in the provided buffer.
00043  *
00044  * @return The destination buffer or the type encoded in hex if no match was found.
00045  */
00046 char * nl_police2str(int type, char *buf, size_t len)
00047 {
00048         return __type2str(type, buf, len, police_types,
00049                           ARRAY_SIZE(police_types));
00050 }
00051 
00052 /**
00053  * Transform a character string into a policer type number
00054  * @arg name            policer type name
00055  *
00056  * Transform the provided character string specifying a policer
00057  * type into the corresponding numeric value
00058  *
00059  * @return Policer type number or a negative value.
00060  */
00061 int nl_str2police(const char *name)
00062 {
00063         return __str2type(name, police_types, ARRAY_SIZE(police_types));
00064 }
00065 
00066 /** @} */