10 #include "wvinterface.h"
12 #include "wvstringlist.h"
14 #include <net/route.h>
17 WvIPRoute::WvIPRoute(WvStringParm _ifc,
const WvIPNet &_net,
20 : ifc(_ifc), ip(_net), gateway(_gate), table(_table), src()
29 return WvString(
"%s via %s %s %s metric %s%s",
38 bool WvIPRoute::operator== (
const WvIPRoute &r2)
const
40 return (ip.network() == r2.ip.network() && ip.netmask() == r2.ip.netmask()
41 && gateway == r2.gateway
42 && ifc == r2.ifc && metric == r2.metric
43 && table == r2.table);
51 WvIPRouteList::WvIPRouteList() : log(
"Route Table",
WvLog::Debug)
63 WvString ifc, table, gate, addr, mask, src;
68 WvStringList::Iter word(words);
73 WvFile kinfo(
"/proc/net/route", O_RDONLY);
75 while ((line = kinfo.
getline()) != NULL)
82 if (words.count() < 10)
86 word.next(); ifc = *word;
87 word.next(); addr = *word;
88 word.next(); gate = *word;
89 word.next(); flags = strtoul(*word, NULL, 16);
92 word.next(); metric = atoi(*word);
93 word.next(); mask = *word;
96 if (!(flags & RTF_UP))
101 uint32_t a = strtoul(addr, NULL, 16), m = strtoul(mask, NULL, 16);
102 uint32_t g = strtoul(gate, NULL, 16);
107 r =
new WvIPRoute(ifc, net, gw, metric,
"default");
113 const char *argv[] = {
"ip",
"route",
"list",
"table",
"all", NULL };
114 WvPipe defaults(argv[0], argv,
false,
true,
false);
120 ifc = gate = table =
"";
126 if (words.count() < 3)
131 if (*word ==
"broadcast" || *word ==
"local")
139 if (!word.next())
break;
142 if (word1 ==
"table")
144 if (word2 ==
"local")
152 else if (word1 ==
"dev")
154 else if (word1 ==
"via")
156 else if (word1 ==
"metric")
157 metric = word2.
num();
158 else if (word1 ==
"scope")
160 else if (word1 ==
"proto" && word2 ==
"kernel")
162 else if (word1 ==
"src")
165 log(WvLog::Debug,
"Unknown keyvalue: '%s' '%s' in (%s)\n",
178 log(WvLog::Debug2,
"No interface given for this route; skipped.\n");
194 if (!r.ip.
is_default() && r.table ==
"default")
207 Iter oi(old_kern), ni(*
this);
221 for (oi.rewind(); oi.next(); )
223 if (oi->metric == 99)
continue;
225 for (ni.rewind(); ni.next(); )
226 if (*ni == *oi)
break;
231 log(
"Del %s\n", *oi);
232 i.
delroute(oi->ip, oi->gateway, oi->metric, realtable(*oi));
237 for (ni.rewind(); ni.next(); )
239 for (oi.rewind(); oi.next(); )
240 if (*oi == *ni)
break;
245 log(
"Add %s\n", *ni);
246 i.
addroute(ni->ip, ni->gateway, ni->src, ni->metric,
257 for (i.rewind(); i.next(); )
259 if (i->ip.includes(addr))