[PATCH] Fixes in ipv4 networking code

Vladimir V. Ivanov (vlad@elis.tusur.ru)
Tue, 5 Jan 1999 16:32:28 +0700


Hello,

My small patch against 2.2.0-pre4 solves the following problems
(at least for me) :

1. "ip route get <SOMETHING>" never returns flowid. Fixed.
2. Flowid setting in rules doesn't work. Fixed.
3. Routes with THROW flag doesn't work. Fixed.
4. Sometimes "ip route get <SOMETHING>" returns an unknown error code,
looks like a very big number. Fixed.

Have fun !

--- CUT HERE ---
--- include/net/ip_fib.h.orig Sat Nov 14 01:49:14 1998
+++ include/net/ip_fib.h Tue Jan 5 11:09:35 1999
@@ -78,7 +78,27 @@


#ifdef CONFIG_IP_MULTIPLE_TABLES
-struct fib_rule;
+struct fib_rule
+{
+ struct fib_rule *r_next;
+ u32 r_preference;
+ unsigned char r_table;
+ unsigned char r_action;
+ unsigned char r_dst_len;
+ unsigned char r_src_len;
+ u32 r_src;
+ u32 r_srcmask;
+ u32 r_dst;
+ u32 r_dstmask;
+ u32 r_srcmap;
+ u8 r_flags;
+ u8 r_tos;
+ int r_ifindex;
+#ifdef CONFIG_NET_CLS_ROUTE
+ __u32 r_tclassid;
+#endif
+ char r_ifname[IFNAMSIZ];
+};
#endif

struct fib_result
--- net/ipv4/route.c.orig Mon Jan 4 23:18:38 1999
+++ net/ipv4/route.c Tue Jan 5 11:12:14 1999
@@ -970,7 +970,7 @@

if (1) {
u32 src_map = saddr;
- if (res.r)
+ if (res.r->r_action == RTN_NAT)
src_map = fib_rules_policy(saddr, &res, &flags);

if (res.type == RTN_NAT) {
@@ -1524,6 +1524,10 @@
r->rtm_src_len = 32;
RTA_PUT(skb, RTA_SRC, 4, &rt->key.src);
}
+#ifdef CONFIG_NET_CLS_ROUTE
+ if (rt->u.dst.tclassid)
+ RTA_PUT(skb, RTA_FLOW, 4, &rt->u.dst.tclassid);
+#endif
if (rt->u.dst.dev)
RTA_PUT(skb, RTA_OIF, sizeof(int), &rt->u.dst.dev->ifindex);
if (rt->key.iif)
@@ -1627,7 +1631,7 @@
end_bh_atomic();
rt = (struct rtable*)skb->dst;
if (!err && rt->u.dst.error)
- err = rt->u.dst.error;
+ err = -rt->u.dst.error;
} else {
int oif = 0;
if (rta[RTA_OIF-1])
--- net/ipv4/ip_nat_dumb.c.orig Mon Jan 4 23:06:58 1999
+++ net/ipv4/ip_nat_dumb.c Tue Jan 5 11:09:35 1999
@@ -44,7 +44,6 @@
#include <net/route.h>
#include <net/ip_fib.h>

-
int
ip_do_nat(struct sk_buff *skb)
{
@@ -120,7 +119,7 @@
*/
if (fib_lookup(&key, &res) != 0)
return 0;
- if (res.r)
+ if (res.r->r_action == RTN_NAT)
ciph->daddr = fib_rules_policy(ciph->daddr, &res, &flags);
}
else
--- net/ipv4/fib_rules.c.orig Sat Nov 14 01:49:15 1998
+++ net/ipv4/fib_rules.c Tue Jan 5 11:09:35 1999
@@ -48,28 +48,6 @@

#define FRprintk(a...)

-struct fib_rule
-{
- struct fib_rule *r_next;
- u32 r_preference;
- unsigned char r_table;
- unsigned char r_action;
- unsigned char r_dst_len;
- unsigned char r_src_len;
- u32 r_src;
- u32 r_srcmask;
- u32 r_dst;
- u32 r_dstmask;
- u32 r_srcmap;
- u8 r_flags;
- u8 r_tos;
- int r_ifindex;
-#ifdef CONFIG_NET_CLS_ROUTE
- __u32 r_tclassid;
-#endif
- char r_ifname[IFNAMSIZ];
-};
-
static struct fib_rule default_rule = { NULL, 0x7FFF, RT_TABLE_DEFAULT, RTN_UNICAST, };
static struct fib_rule main_rule = { &default_rule, 0x7FFE, RT_TABLE_MAIN, RTN_UNICAST, };
static struct fib_rule local_rule = { &main_rule, 0, RT_TABLE_LOCAL, RTN_UNICAST, };
@@ -204,19 +182,16 @@
u32 fib_rules_policy(u32 saddr, struct fib_result *res, unsigned *flags)
{
struct fib_rule *r = res->r;
+ int addrtype = inet_addr_type(r->r_srcmap);

- if (r->r_action == RTN_NAT) {
- int addrtype = inet_addr_type(r->r_srcmap);
-
- if (addrtype == RTN_NAT) {
- /* Packet is from translated source; remember it */
- saddr = (saddr&~r->r_srcmask)|r->r_srcmap;
- *flags |= RTCF_SNAT;
- } else if (addrtype == RTN_LOCAL || r->r_srcmap == 0) {
- /* Packet is from masqueraded source; remember it */
- saddr = r->r_srcmap;
- *flags |= RTCF_MASQ;
- }
+ if (addrtype == RTN_NAT) {
+ /* Packet is from translated source; remember it */
+ saddr = (saddr&~r->r_srcmask)|r->r_srcmap;
+ *flags |= RTCF_SNAT;
+ } else if (addrtype == RTN_LOCAL || r->r_srcmap == 0) {
+ /* Packet is from masqueraded source; remember it */
+ saddr = r->r_srcmap;
+ *flags |= RTCF_MASQ;
}
return saddr;
}
@@ -273,8 +248,6 @@
FRprintk("tb %d r %d ", r->r_table, r->r_action);
switch (r->r_action) {
case RTN_UNICAST:
- policy = NULL;
- break;
case RTN_NAT:
policy = r;
break;
--- net/ipv4/fib_hash.c.orig Sat Nov 14 01:49:15 1998
+++ net/ipv4/fib_hash.c Tue Jan 5 11:11:06 1999
@@ -295,7 +295,7 @@
res->prefix = &fz_prefix(f->fn_key, fz);
return 0;
}
- if (err < 0)
+ if (err < 0 || err == 1)
return err;
}
}
--- CUT HERE ---

Best regards, Vladimir Ivanov
E-mail: mailto:vlad@elis.tusur.ru
World Wide Web: http://elis.tusur.ru/~vlad

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/