libnl 1.1
|
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.h> 00017 #include <netlink/route/classifier.h> 00018 #include <netlink/route/classifier-modules.h> 00019 #include <netlink/route/cls/police.h> 00020 00021 /** 00022 * @name Policer Type 00023 * @{ 00024 */ 00025 00026 static struct trans_tbl police_types[] = { 00027 __ADD(TC_POLICE_UNSPEC,unspec) 00028 __ADD(TC_POLICE_OK,ok) 00029 __ADD(TC_POLICE_RECLASSIFY,reclassify) 00030 __ADD(TC_POLICE_SHOT,shot) 00031 #ifdef TC_POLICE_PIPE 00032 __ADD(TC_POLICE_PIPE,pipe) 00033 #endif 00034 }; 00035 00036 /** 00037 * Transform a policer type number into a character string (Reentrant). 00038 * @arg type policer type 00039 * @arg buf destination buffer 00040 * @arg len buffer length 00041 * 00042 * Transforms a policer type number into a character string and stores 00043 * it in the provided buffer. 00044 * 00045 * @return The destination buffer or the type encoded in hex if no match was found. 00046 */ 00047 char * nl_police2str(int type, char *buf, size_t len) 00048 { 00049 return __type2str(type, buf, len, police_types, 00050 ARRAY_SIZE(police_types)); 00051 } 00052 00053 /** 00054 * Transform a character string into a policer type number 00055 * @arg name policer type name 00056 * 00057 * Transform the provided character string specifying a policer 00058 * type into the corresponding numeric value 00059 * 00060 * @return Policer type number or a negative value. 00061 */ 00062 int nl_str2police(const char *name) 00063 { 00064 return __str2type(name, police_types, ARRAY_SIZE(police_types)); 00065 } 00066 00067 /** @} */