[IPV6]: Fix sending extension headers before and including routing header.
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Sun, 20 Nov 2005 03:23:18 +0000 (12:23 +0900)
committerYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Sun, 20 Nov 2005 03:23:18 +0000 (12:23 +0900)
Based on suggestion from Masahide Nakamura <nakam@linux-ipv6.org>.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
include/net/ipv6.h
net/ipv6/exthdrs.c
net/ipv6/ip6_flowlabel.c
net/ipv6/raw.c
net/ipv6/udp.c

index 65ec86678a08e34280fdd23e7e10f2c2cbb1494f..53c76c8a69007ba0b6f9c80f852efc8994b061a3 100644 (file)
@@ -237,6 +237,8 @@ extern struct ipv6_txoptions *      ipv6_renew_options(struct sock *sk, struct ipv6_t
                                                   int newtype,
                                                   struct ipv6_opt_hdr __user *newopt,
                                                   int newoptlen);
+struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
+                                         struct ipv6_txoptions *opt);
 
 extern int ip6_frag_nqueues;
 extern atomic_t ip6_frag_mem;
index 748577b76d75a93b1f105a70faeaedffdc8a3f01..be6faf311387ce8d6f5adf1b7ec251b5b89752f2 100644 (file)
@@ -673,3 +673,22 @@ out:
        return ERR_PTR(err);
 }
 
+struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
+                                         struct ipv6_txoptions *opt)
+{
+       /*
+        * ignore the dest before srcrt unless srcrt is being included.
+        * --yoshfuji
+        */
+       if (opt && opt->dst0opt && !opt->srcrt) {
+               if (opt_space != opt) {
+                       memcpy(opt_space, opt, sizeof(*opt_space));
+                       opt = opt_space;
+               }
+               opt->opt_nflen -= ipv6_optlen(opt->dst0opt);
+               opt->dst0opt = NULL;
+       }
+
+       return opt;
+}
+
index bbbe80cdaf72a75a463aff9551e60b31e2f69061..1cf02765fb5cae2ed7882149122dd3c9996197e4 100644 (file)
@@ -225,20 +225,16 @@ struct ipv6_txoptions *fl6_merge_options(struct ipv6_txoptions * opt_space,
                                         struct ip6_flowlabel * fl,
                                         struct ipv6_txoptions * fopt)
 {
-       struct ipv6_txoptions * fl_opt = fl ? fl->opt : NULL;
-
-       if (fopt == NULL || fopt->opt_flen == 0) {
-               if (!fl_opt || !fl_opt->dst0opt || fl_opt->srcrt)
-                       return fl_opt;
-       }
-
+       struct ipv6_txoptions * fl_opt = fl->opt;
+       
+       if (fopt == NULL || fopt->opt_flen == 0)
+               return fl_opt;
+       
        if (fl_opt != NULL) {
                opt_space->hopopt = fl_opt->hopopt;
-               opt_space->dst0opt = fl_opt->srcrt ? fl_opt->dst0opt : NULL;
+               opt_space->dst0opt = fl_opt->dst0opt;
                opt_space->srcrt = fl_opt->srcrt;
                opt_space->opt_nflen = fl_opt->opt_nflen;
-               if (fl_opt->dst0opt && !fl_opt->srcrt)
-                       opt_space->opt_nflen -= ipv6_optlen(fl_opt->dst0opt);
        } else {
                if (fopt->opt_nflen == 0)
                        return fopt;
index a1265a320b1170a43e1db063d573e20944582ca2..d77d3352c96754c5b06e00f5d168762fd2dd1ddd 100644 (file)
@@ -756,7 +756,9 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
        }
        if (opt == NULL)
                opt = np->opt;
-       opt = fl6_merge_options(&opt_space, flowlabel, opt);
+       if (flowlabel)
+               opt = fl6_merge_options(&opt_space, flowlabel, opt);
+       opt = ipv6_fixup_options(&opt_space, opt);
 
        fl.proto = proto;
        rawv6_probe_proto_opt(&fl, msg);
index bf9519341fd30ad28a0b9652d09bcd7628765dc4..e2b87cc68b7b61ac6c9814867257bbdb9bfbee4f 100644 (file)
@@ -778,7 +778,9 @@ do_udp_sendmsg:
        }
        if (opt == NULL)
                opt = np->opt;
-       opt = fl6_merge_options(&opt_space, flowlabel, opt);
+       if (flowlabel)
+               opt = fl6_merge_options(&opt_space, flowlabel, opt);
+       opt = ipv6_fixup_options(&opt_space, opt);
 
        fl->proto = IPPROTO_UDP;
        ipv6_addr_copy(&fl->fl6_dst, daddr);