X-Git-Url: http://git.onelab.eu/?p=libnl.git;a=blobdiff_plain;f=lib%2Froute%2Fcls%2Fpolice.c;fp=lib%2Froute%2Fcls%2Fpolice.c;h=051c6b2a93cd9f29b9bc2057653a28d95ef0b662;hp=0000000000000000000000000000000000000000;hb=4cee2ecb3b8afa0637e6f5fe4c57985a4bc740ff;hpb=2df2fbe518d5a221ce6e3ee88a3fb23fb1b94b27 diff --git a/lib/route/cls/police.c b/lib/route/cls/police.c new file mode 100644 index 0000000..051c6b2 --- /dev/null +++ b/lib/route/cls/police.c @@ -0,0 +1,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 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @name Policer Type + * @{ + */ + +static 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)); +} + +/** @} */