]> err.no Git - linux-2.6/blobdiff - net/ipv4/ip_options.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
[linux-2.6] / net / ipv4 / ip_options.c
index 7e94bf850a07fcd88db21498c05cf864523ff4ac..33126ad2cfdc8964c9350a203c3223024b6999e8 100644 (file)
@@ -45,7 +45,6 @@ void ip_options_build(struct sk_buff * skb, struct ip_options * opt,
        memcpy(&(IPCB(skb)->opt), opt, sizeof(struct ip_options));
        memcpy(iph+sizeof(struct iphdr), opt->__data, opt->optlen);
        opt = &(IPCB(skb)->opt);
-       opt->is_data = 0;
 
        if (opt->srr)
                memcpy(iph+opt->srr+iph[opt->srr+1]-4, &daddr, 4);
@@ -56,10 +55,10 @@ void ip_options_build(struct sk_buff * skb, struct ip_options * opt,
                if (opt->ts_needaddr)
                        ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, rt);
                if (opt->ts_needtime) {
-                       struct timeval tv;
+                       struct timespec tv;
                        __be32 midtime;
-                       do_gettimeofday(&tv);
-                       midtime = htonl((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000);
+                       getnstimeofday(&tv);
+                       midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC);
                        memcpy(iph+opt->ts+iph[opt->ts+2]-5, &midtime, 4);
                }
                return;
@@ -95,8 +94,6 @@ int ip_options_echo(struct ip_options * dopt, struct sk_buff * skb)
 
        memset(dopt, 0, sizeof(struct ip_options));
 
-       dopt->is_data = 1;
-
        sopt = &(IPCB(skb)->opt);
 
        if (sopt->optlen == 0) {
@@ -148,7 +145,7 @@ int ip_options_echo(struct ip_options * dopt, struct sk_buff * skb)
                                                __be32 addr;
 
                                                memcpy(&addr, sptr+soffset-1, 4);
-                                               if (inet_addr_type(&init_net, addr) != RTN_LOCAL) {
+                                               if (inet_addr_type(dev_net(skb->dst->dev), addr) != RTN_LOCAL) {
                                                        dopt->ts_needtime = 1;
                                                        soffset += 8;
                                                }
@@ -251,25 +248,22 @@ void ip_options_fragment(struct sk_buff * skb)
  * If opt == NULL, then skb->data should point to IP header.
  */
 
-int ip_options_compile(struct ip_options * opt, struct sk_buff * skb)
+int ip_options_compile(struct net *net,
+                      struct ip_options * opt, struct sk_buff * skb)
 {
        int l;
        unsigned char * iph;
        unsigned char * optptr;
        int optlen;
        unsigned char * pp_ptr = NULL;
-       struct rtable *rt = skb ? skb->rtable : NULL;
-
-       if (!opt) {
-               opt = &(IPCB(skb)->opt);
-               iph = skb_network_header(skb);
-               opt->optlen = ((struct iphdr *)iph)->ihl*4 - sizeof(struct iphdr);
-               optptr = iph + sizeof(struct iphdr);
-               opt->is_data = 0;
-       } else {
+       struct rtable *rt = NULL;
+
+       if (skb != NULL) {
+               rt = skb->rtable;
+               optptr = (unsigned char *)&(ip_hdr(skb)[1]);
+       } else
                optptr = opt->__data;
-               iph = optptr - sizeof(struct iphdr);
-       }
+       iph = optptr - sizeof(struct iphdr);
 
        for (l = opt->optlen; l > 0; ) {
                switch (*optptr) {
@@ -396,7 +390,7 @@ int ip_options_compile(struct ip_options * opt, struct sk_buff * skb)
                                        {
                                                __be32 addr;
                                                memcpy(&addr, &optptr[optptr[2]-1], 4);
-                                               if (inet_addr_type(&init_net, addr) == RTN_UNICAST)
+                                               if (inet_addr_type(net, addr) == RTN_UNICAST)
                                                        break;
                                                if (skb)
                                                        timeptr = (__be32*)&optptr[optptr[2]+3];
@@ -412,10 +406,10 @@ int ip_options_compile(struct ip_options * opt, struct sk_buff * skb)
                                        break;
                                }
                                if (timeptr) {
-                                       struct timeval tv;
+                                       struct timespec tv;
                                        __be32  midtime;
-                                       do_gettimeofday(&tv);
-                                       midtime = htonl((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000);
+                                       getnstimeofday(&tv);
+                                       midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC);
                                        memcpy(timeptr, &midtime, sizeof(__be32));
                                        opt->is_changed = 1;
                                }
@@ -513,14 +507,13 @@ static struct ip_options *ip_options_get_alloc(const int optlen)
                       GFP_KERNEL);
 }
 
-static int ip_options_get_finish(struct ip_options **optp,
+static int ip_options_get_finish(struct net *net, struct ip_options **optp,
                                 struct ip_options *opt, int optlen)
 {
        while (optlen & 3)
                opt->__data[optlen++] = IPOPT_END;
        opt->optlen = optlen;
-       opt->is_data = 1;
-       if (optlen && ip_options_compile(opt, NULL)) {
+       if (optlen && ip_options_compile(net, opt, NULL)) {
                kfree(opt);
                return -EINVAL;
        }
@@ -529,7 +522,8 @@ static int ip_options_get_finish(struct ip_options **optp,
        return 0;
 }
 
-int ip_options_get_from_user(struct ip_options **optp, unsigned char __user *data, int optlen)
+int ip_options_get_from_user(struct net *net, struct ip_options **optp,
+                            unsigned char __user *data, int optlen)
 {
        struct ip_options *opt = ip_options_get_alloc(optlen);
 
@@ -539,10 +533,11 @@ int ip_options_get_from_user(struct ip_options **optp, unsigned char __user *dat
                kfree(opt);
                return -EFAULT;
        }
-       return ip_options_get_finish(optp, opt, optlen);
+       return ip_options_get_finish(net, optp, opt, optlen);
 }
 
-int ip_options_get(struct ip_options **optp, unsigned char *data, int optlen)
+int ip_options_get(struct net *net, struct ip_options **optp,
+                  unsigned char *data, int optlen)
 {
        struct ip_options *opt = ip_options_get_alloc(optlen);
 
@@ -550,7 +545,7 @@ int ip_options_get(struct ip_options **optp, unsigned char *data, int optlen)
                return -ENOMEM;
        if (optlen)
                memcpy(opt->__data, data, optlen);
-       return ip_options_get_finish(optp, opt, optlen);
+       return ip_options_get_finish(net, optp, opt, optlen);
 }
 
 void ip_forward_options(struct sk_buff *skb)