aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/rt_names.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-11-21 15:36:08 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2006-11-21 15:36:08 +0000
commit921f5df25fdb9d89bd02ac0030ebb6ca7e003f0d (patch)
treef6b5be4741c2856fa0d0f0fa148ee4d0a1fecbaa /networking/libiproute/rt_names.c
parent04b30ba3b88c721b81194cae9cb439ddba4712db (diff)
downloadbusybox-921f5df25fdb9d89bd02ac0030ebb6ca7e003f0d.tar.gz
- add 'ip rule' support. First take..
text data bss dec hex filename 2999 0 0 2999 bb7 networking/libiproute/iprule.o
Diffstat (limited to 'networking/libiproute/rt_names.c')
-rw-r--r--networking/libiproute/rt_names.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c
index c0f790754..ed21fbe26 100644
--- a/networking/libiproute/rt_names.c
+++ b/networking/libiproute/rt_names.c
@@ -240,7 +240,23 @@ int rtnl_rtrealm_a2n(uint32_t *id, char *arg)
return 0;
}
-
+#if ENABLE_FEATURE_IP_RULE
+const char * rtnl_rtrealm_n2a(int id, char *buf, int len)
+{
+ if (id<0 || id>=256) {
+ snprintf(buf, len, "%d", id);
+ return buf;
+ }
+ if (!rtnl_rtrealm_tab[id]) {
+ if (!rtnl_rtrealm_init)
+ rtnl_rtrealm_initialize();
+ }
+ if (rtnl_rtrealm_tab[id])
+ return rtnl_rtrealm_tab[id];
+ snprintf(buf, len, "%d", id);
+ return buf;
+}
+#endif
static const char * rtnl_rtdsfield_tab[256] = {
"0",
@@ -303,3 +319,66 @@ int rtnl_dsfield_a2n(uint32_t *id, char *arg)
*id = res;
return 0;
}
+
+#if ENABLE_FEATURE_IP_RULE
+static int rtnl_rttable_init;
+static const char * rtnl_rttable_tab[256] = {
+ "unspec",
+};
+static void rtnl_rttable_initialize(void)
+{
+ rtnl_rttable_init = 1;
+ rtnl_rttable_tab[255] = "local";
+ rtnl_rttable_tab[254] = "main";
+ rtnl_rttable_tab[253] = "default";
+ rtnl_tab_initialize("/etc/iproute2/rt_tables", rtnl_rttable_tab, 256);
+}
+
+const char *rtnl_rttable_n2a(int id, char *buf, int len)
+{
+ if (id < 0 || id >= 256) {
+ snprintf(buf, len, "%d", id);
+ return buf;
+ }
+ if (!rtnl_rttable_tab[id]) {
+ if (!rtnl_rttable_init)
+ rtnl_rttable_initialize();
+ }
+ if (rtnl_rttable_tab[id])
+ return rtnl_rttable_tab[id];
+ snprintf(buf, len, "%d", id);
+ return buf;
+}
+
+int rtnl_rttable_a2n(uint32_t * id, char *arg)
+{
+ static char *cache = NULL;
+ static unsigned long res;
+ char *end;
+ int i;
+
+ if (cache && strcmp(cache, arg) == 0) {
+ *id = res;
+ return 0;
+ }
+
+ if (!rtnl_rttable_init)
+ rtnl_rttable_initialize();
+
+ for (i = 0; i < 256; i++) {
+ if (rtnl_rttable_tab[i] && strcmp(rtnl_rttable_tab[i], arg) == 0) {
+ cache = (char*)rtnl_rttable_tab[i];
+ res = i;
+ *id = res;
+ return 0;
+ }
+ }
+
+ i = strtoul(arg, &end, 0);
+ if (!end || end == arg || *end || i > 255)
+ return -1;
+ *id = i;
+ return 0;
+}
+
+#endif