]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv4/fib_semantics.c
[PATCH] knfsd: nfsd: store export path in export
[linux-2.6-omap-h63xx.git] / net / ipv4 / fib_semantics.c
index 340f9db389e576bced2c25d4c8c0683975893a9b..884d176e0082f3a230b9fa360ba4dc37518f2cb9 100644 (file)
@@ -203,7 +203,7 @@ static inline unsigned int fib_info_hashfn(const struct fib_info *fi)
        unsigned int val = fi->fib_nhs;
 
        val ^= fi->fib_protocol;
-       val ^= fi->fib_prefsrc;
+       val ^= (__force u32)fi->fib_prefsrc;
        val ^= fi->fib_priority;
 
        return (val ^ (val >> 7) ^ (val >> 12)) & mask;
@@ -248,7 +248,7 @@ static inline unsigned int fib_devindex_hashfn(unsigned int val)
    Used only by redirect accept routine.
  */
 
-int ip_fib_check_default(u32 gw, struct net_device *dev)
+int ip_fib_check_default(__be32 gw, struct net_device *dev)
 {
        struct hlist_head *head;
        struct hlist_node *node;
@@ -273,7 +273,7 @@ int ip_fib_check_default(u32 gw, struct net_device *dev)
        return -1;
 }
 
-void rtmsg_fib(int event, u32 key, struct fib_alias *fa,
+void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
               int dst_len, u32 tb_id, struct nl_info *info)
 {
        struct sk_buff *skb;
@@ -286,7 +286,7 @@ void rtmsg_fib(int event, u32 key, struct fib_alias *fa,
                goto errout;
 
        err = fib_dump_info(skb, info->pid, seq, event, tb_id,
-                           fa->fa_type, fa->fa_scope, &key, dst_len,
+                           fa->fa_type, fa->fa_scope, key, dst_len,
                            fa->fa_tos, fa->fa_info, 0);
        if (err < 0) {
                kfree_skb(skb);
@@ -374,7 +374,7 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
                        struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
 
                        nla = nla_find(attrs, attrlen, RTA_GATEWAY);
-                       nh->nh_gw = nla ? nla_get_u32(nla) : 0;
+                       nh->nh_gw = nla ? nla_get_be32(nla) : 0;
 #ifdef CONFIG_NET_CLS_ROUTE
                        nla = nla_find(attrs, attrlen, RTA_FLOW);
                        nh->nh_tclassid = nla ? nla_get_u32(nla) : 0;
@@ -427,7 +427,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi)
                        struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
 
                        nla = nla_find(attrs, attrlen, RTA_GATEWAY);
-                       if (nla && nla_get_u32(nla) != nh->nh_gw)
+                       if (nla && nla_get_be32(nla) != nh->nh_gw)
                                return 1;
 #ifdef CONFIG_NET_CLS_ROUTE
                        nla = nla_find(attrs, attrlen, RTA_FLOW);
@@ -568,11 +568,11 @@ out:
        return 0;
 }
 
-static inline unsigned int fib_laddr_hashfn(u32 val)
+static inline unsigned int fib_laddr_hashfn(__be32 val)
 {
        unsigned int mask = (fib_hash_size - 1);
 
-       return (val ^ (val >> 7) ^ (val >> 14)) & mask;
+       return ((__force u32)val ^ ((__force u32)val >> 7) ^ ((__force u32)val >> 14)) & mask;
 }
 
 static struct hlist_head *fib_hash_alloc(int bytes)
@@ -847,7 +847,7 @@ failure:
 
 /* Note! fib_semantic_match intentionally uses  RCU list functions. */
 int fib_semantic_match(struct list_head *head, const struct flowi *flp,
-                      struct fib_result *res, __u32 zone, __u32 mask, 
+                      struct fib_result *res, __be32 zone, __be32 mask,
                        int prefixlen)
 {
        struct fib_alias *fa;
@@ -914,8 +914,7 @@ out_fill_res:
        res->fi = fa->fa_info;
 #ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
        res->netmask = mask;
-       res->network = zone &
-               (0xFFFFFFFF >> (32 - prefixlen));
+       res->network = zone & inet_make_mask(prefixlen);
 #endif
        atomic_inc(&res->fi->fib_clntref);
        return 0;
@@ -923,84 +922,92 @@ out_fill_res:
 
 /* Find appropriate source address to this destination */
 
-u32 __fib_res_prefsrc(struct fib_result *res)
+__be32 __fib_res_prefsrc(struct fib_result *res)
 {
        return inet_select_addr(FIB_RES_DEV(*res), FIB_RES_GW(*res), res->scope);
 }
 
-int
-fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
-             u32 tb_id, u8 type, u8 scope, void *dst, int dst_len, u8 tos,
-             struct fib_info *fi, unsigned int flags)
+int fib_dump_info(struct sk_buff *skb, u32 pid, u32 seq, int event,
+                 u32 tb_id, u8 type, u8 scope, __be32 dst, int dst_len, u8 tos,
+                 struct fib_info *fi, unsigned int flags)
 {
+       struct nlmsghdr *nlh;
        struct rtmsg *rtm;
-       struct nlmsghdr  *nlh;
-       unsigned char    *b = skb->tail;
 
-       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*rtm), flags);
-       rtm = NLMSG_DATA(nlh);
+       nlh = nlmsg_put(skb, pid, seq, event, sizeof(*rtm), flags);
+       if (nlh == NULL)
+               return -ENOBUFS;
+
+       rtm = nlmsg_data(nlh);
        rtm->rtm_family = AF_INET;
        rtm->rtm_dst_len = dst_len;
        rtm->rtm_src_len = 0;
        rtm->rtm_tos = tos;
        rtm->rtm_table = tb_id;
-       RTA_PUT_U32(skb, RTA_TABLE, tb_id);
+       NLA_PUT_U32(skb, RTA_TABLE, tb_id);
        rtm->rtm_type = type;
        rtm->rtm_flags = fi->fib_flags;
        rtm->rtm_scope = scope;
-       if (rtm->rtm_dst_len)
-               RTA_PUT(skb, RTA_DST, 4, dst);
        rtm->rtm_protocol = fi->fib_protocol;
+
+       if (rtm->rtm_dst_len)
+               NLA_PUT_BE32(skb, RTA_DST, dst);
+
        if (fi->fib_priority)
-               RTA_PUT(skb, RTA_PRIORITY, 4, &fi->fib_priority);
+               NLA_PUT_U32(skb, RTA_PRIORITY, fi->fib_priority);
+
        if (rtnetlink_put_metrics(skb, fi->fib_metrics) < 0)
-               goto rtattr_failure;
+               goto nla_put_failure;
+
        if (fi->fib_prefsrc)
-               RTA_PUT(skb, RTA_PREFSRC, 4, &fi->fib_prefsrc);
+               NLA_PUT_BE32(skb, RTA_PREFSRC, fi->fib_prefsrc);
+
        if (fi->fib_nhs == 1) {
                if (fi->fib_nh->nh_gw)
-                       RTA_PUT(skb, RTA_GATEWAY, 4, &fi->fib_nh->nh_gw);
+                       NLA_PUT_BE32(skb, RTA_GATEWAY, fi->fib_nh->nh_gw);
+
                if (fi->fib_nh->nh_oif)
-                       RTA_PUT(skb, RTA_OIF, sizeof(int), &fi->fib_nh->nh_oif);
+                       NLA_PUT_U32(skb, RTA_OIF, fi->fib_nh->nh_oif);
 #ifdef CONFIG_NET_CLS_ROUTE
                if (fi->fib_nh[0].nh_tclassid)
-                       RTA_PUT(skb, RTA_FLOW, 4, &fi->fib_nh[0].nh_tclassid);
+                       NLA_PUT_U32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid);
 #endif
        }
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
        if (fi->fib_nhs > 1) {
-               struct rtnexthop *nhp;
-               struct rtattr *mp_head;
-               if (skb_tailroom(skb) <= RTA_SPACE(0))
-                       goto rtattr_failure;
-               mp_head = (struct rtattr*)skb_put(skb, RTA_SPACE(0));
+               struct rtnexthop *rtnh;
+               struct nlattr *mp;
+
+               mp = nla_nest_start(skb, RTA_MULTIPATH);
+               if (mp == NULL)
+                       goto nla_put_failure;
 
                for_nexthops(fi) {
-                       if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
-                               goto rtattr_failure;
-                       nhp = (struct rtnexthop*)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
-                       nhp->rtnh_flags = nh->nh_flags & 0xFF;
-                       nhp->rtnh_hops = nh->nh_weight-1;
-                       nhp->rtnh_ifindex = nh->nh_oif;
+                       rtnh = nla_reserve_nohdr(skb, sizeof(*rtnh));
+                       if (rtnh == NULL)
+                               goto nla_put_failure;
+
+                       rtnh->rtnh_flags = nh->nh_flags & 0xFF;
+                       rtnh->rtnh_hops = nh->nh_weight - 1;
+                       rtnh->rtnh_ifindex = nh->nh_oif;
+
                        if (nh->nh_gw)
-                               RTA_PUT(skb, RTA_GATEWAY, 4, &nh->nh_gw);
+                               NLA_PUT_BE32(skb, RTA_GATEWAY, nh->nh_gw);
 #ifdef CONFIG_NET_CLS_ROUTE
                        if (nh->nh_tclassid)
-                               RTA_PUT(skb, RTA_FLOW, 4, &nh->nh_tclassid);
+                               NLA_PUT_U32(skb, RTA_FLOW, nh->nh_tclassid);
 #endif
-                       nhp->rtnh_len = skb->tail - (unsigned char*)nhp;
+                       /* length of rtnetlink header + attributes */
+                       rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *) rtnh;
                } endfor_nexthops(fi);
-               mp_head->rta_type = RTA_MULTIPATH;
-               mp_head->rta_len = skb->tail - (u8*)mp_head;
+
+               nla_nest_end(skb, mp);
        }
 #endif
-       nlh->nlmsg_len = skb->tail - b;
-       return skb->len;
+       return nlmsg_end(skb, nlh);
 
-nlmsg_failure:
-rtattr_failure:
-       skb_trim(skb, b - skb->data);
-       return -1;
+nla_put_failure:
+       return nlmsg_cancel(skb, nlh);
 }
 
 /*
@@ -1010,7 +1017,7 @@ rtattr_failure:
    - device went down -> we must shutdown all nexthops going via it.
  */
 
-int fib_sync_down(u32 local, struct net_device *dev, int force)
+int fib_sync_down(__be32 local, struct net_device *dev, int force)
 {
        int ret = 0;
        int scope = RT_SCOPE_NOWHERE;