Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / include / net / route.h
index 7a851de..4bacfbe 100644 (file)
@@ -7,7 +7,7 @@
  *
  * Version:    @(#)route.h     1.0.4   05/27/93
  *
- * Authors:    Ross Biro, <bir7@leland.Stanford.Edu>
+ * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  * Fixes:
  *             Alan Cox        :       Reformatted. Added ip_rt_local()
 #ifndef _ROUTE_H
 #define _ROUTE_H
 
-#include <linux/config.h>
 #include <net/dst.h>
 #include <net/inetpeer.h>
 #include <net/flow.h>
+#include <net/inet_sock.h>
 #include <linux/in_route.h>
 #include <linux/rtnetlink.h>
 #include <linux/route.h>
 #include <linux/ip.h>
 #include <linux/cache.h>
+#include <linux/vs_network.h>
+#include <linux/in.h>
 
 #ifndef __KERNEL__
 #warning This file is not supposed to be used outside of kernel.
@@ -44,8 +46,9 @@
 /* RTO_CONN is not used (being alias for 0), but preserved not to break
  * some modules referring to it. */
 
-#define RT_CONN_FLAGS(sk)   (RT_TOS(inet_sk(sk)->tos) | sk->sk_localroute)
+#define RT_CONN_FLAGS(sk)   (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE))
 
+struct fib_nh;
 struct inet_peer;
 struct rtable
 {
@@ -55,8 +58,11 @@ struct rtable
                struct rtable           *rt_next;
        } u;
 
+       struct in_device        *idev;
+       
        unsigned                rt_flags;
-       unsigned                rt_type;
+       __u16                   rt_type;
+       __u16                   rt_multipath_alg;
 
        __u32                   rt_dst; /* Path destination     */
        __u32                   rt_src; /* Path source          */
@@ -71,11 +77,6 @@ struct rtable
        /* Miscellaneous cached information */
        __u32                   rt_spec_dst; /* RFC1122 specific destination */
        struct inet_peer        *peer; /* long-living peer info */
-
-#ifdef CONFIG_IP_ROUTE_NAT
-       __u32                   rt_src_map;
-       __u32                   rt_dst_map;
-#endif
 };
 
 struct ip_rt_acct
@@ -106,16 +107,12 @@ struct rt_cache_stat
         unsigned int out_hlist_search;
 };
 
-extern struct rt_cache_stat *rt_cache_stat;
-#define RT_CACHE_STAT_INC(field)                                         \
-               (per_cpu_ptr(rt_cache_stat, smp_processor_id())->field++)
-
 extern struct ip_rt_acct *ip_rt_acct;
 
 struct in_device;
 extern int             ip_rt_init(void);
 extern void            ip_rt_redirect(u32 old_gw, u32 dst, u32 new_gw,
-                                      u32 src, u8 tos, struct net_device *dev);
+                                      u32 src, struct net_device *dev);
 extern void            ip_rt_advice(struct rtable **rp, int advice);
 extern void            rt_cache_flush(int how);
 extern int             __ip_route_output_key(struct rtable **, const struct flowi *flp);
@@ -127,10 +124,13 @@ extern void               ip_rt_send_redirect(struct sk_buff *skb);
 
 extern unsigned                inet_addr_type(u32 addr);
 extern void            ip_rt_multicast_event(struct in_device *);
-extern int             ip_rt_ioctl(unsigned int cmd, void *arg);
+extern int             ip_rt_ioctl(unsigned int cmd, void __user *arg);
 extern void            ip_rt_get_source(u8 *src, struct rtable *rt);
 extern int             ip_rt_dump(struct sk_buff *skb,  struct netlink_callback *cb);
 
+struct in_ifaddr;
+extern void fib_add_ifaddr(struct in_ifaddr *);
+
 static inline void ip_rt_put(struct rtable * rt)
 {
        if (rt)
@@ -146,6 +146,59 @@ static inline char rt_tos2priority(u8 tos)
        return ip_tos2prio[IPTOS_TOS(tos)>>1];
 }
 
+#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
+
+static inline int ip_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
+{
+       int err;
+       int i, n = nxi->nbipv4;
+       u32 ipv4root = nxi->ipv4[0];
+
+       if (ipv4root == 0)
+               return 0;
+
+       if (fl->fl4_src == 0) {
+               if (n > 1) {
+                       u32 foundsrc;
+
+                       err = __ip_route_output_key(rp, fl);
+                       if (err) {
+                               fl->fl4_src = ipv4root;
+                               err = __ip_route_output_key(rp, fl);
+                       }
+                       if (err)
+                               return err;
+
+                       foundsrc = (*rp)->rt_src;
+                       ip_rt_put(*rp);
+
+                       for (i=0; i<n; i++){
+                               u32 mask = nxi->mask[i];
+                               u32 ipv4 = nxi->ipv4[i];
+                               u32 net4 = ipv4 & mask;
+
+                               if (foundsrc == ipv4) {
+                                       fl->fl4_src = ipv4;
+                                       break;
+                               }
+                               if (!fl->fl4_src && (foundsrc & mask) == net4)
+                                       fl->fl4_src = ipv4;
+                       }
+               }
+               if (fl->fl4_src == 0)
+                       fl->fl4_src = (fl->fl4_dst == IPI_LOOPBACK)
+                               ? IPI_LOOPBACK : ipv4root;
+       } else {
+               for (i=0; i<n; i++) {
+                       if (nxi->ipv4[i] == fl->fl4_src)
+                               break;
+               }
+               if (i == n)
+                       return -EPERM;
+       }
+       return 0;
+}
+
 static inline int ip_route_connect(struct rtable **rp, u32 dst,
                                   u32 src, u32 tos, int oif, u8 protocol,
                                   u16 sport, u16 dport, struct sock *sk)
@@ -160,7 +213,27 @@ static inline int ip_route_connect(struct rtable **rp, u32 dst,
                                         .dport = dport } } };
 
        int err;
-       if (!dst || !src) {
+       struct nx_info *nx_info = current->nx_info;
+
+       if (sk)
+               nx_info = sk->sk_nx_info;
+       vxdprintk(VXD_CBIT(net, 4),
+               "ip_route_connect(%p) %p,%p;%lx",
+               sk, nx_info, sk->sk_socket,
+               (sk->sk_socket?sk->sk_socket->flags:0));
+
+       if (nx_info) {
+               err = ip_find_src(nx_info, rp, &fl);
+               if (err)
+                       return err;
+               if (fl.fl4_dst == IPI_LOOPBACK && !vx_check(0, VX_ADMIN))
+                       fl.fl4_dst = nx_info->ipv4[0];
+#ifdef CONFIG_VSERVER_REMAP_SADDR
+               if (fl.fl4_src == IPI_LOOPBACK && !vx_check(0, VX_ADMIN))
+                       fl.fl4_src = nx_info->ipv4[0];
+#endif
+       }
+       if (!fl.fl4_dst || !fl.fl4_src) {
                err = __ip_route_output_key(rp, &fl);
                if (err)
                        return err;
@@ -172,8 +245,8 @@ static inline int ip_route_connect(struct rtable **rp, u32 dst,
        return ip_route_output_flow(rp, &fl, sk, 0);
 }
 
-static inline int ip_route_newports(struct rtable **rp, u16 sport, u16 dport,
-                                   struct sock *sk)
+static inline int ip_route_newports(struct rtable **rp, u8 protocol,
+                                   u16 sport, u16 dport, struct sock *sk)
 {
        if (sport != (*rp)->fl.fl_ip_sport ||
            dport != (*rp)->fl.fl_ip_dport) {
@@ -182,6 +255,7 @@ static inline int ip_route_newports(struct rtable **rp, u16 sport, u16 dport,
                memcpy(&fl, &(*rp)->fl, sizeof(fl));
                fl.fl_ip_sport = sport;
                fl.fl_ip_dport = dport;
+               fl.proto = protocol;
                ip_rt_put(*rp);
                *rp = NULL;
                return ip_route_output_flow(rp, &fl, sk, 0);
@@ -200,4 +274,6 @@ static inline struct inet_peer *rt_get_peer(struct rtable *rt)
        return rt->peer;
 }
 
+extern ctl_table ipv4_route_table[];
+
 #endif /* _ROUTE_H */