hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/net/ipv4/ip_options.c
....@@ -47,32 +47,32 @@
4747 unsigned char *iph = skb_network_header(skb);
4848
4949 memcpy(&(IPCB(skb)->opt), opt, sizeof(struct ip_options));
50
- memcpy(iph+sizeof(struct iphdr), opt->__data, opt->optlen);
50
+ memcpy(iph + sizeof(struct iphdr), opt->__data, opt->optlen);
5151 opt = &(IPCB(skb)->opt);
5252
5353 if (opt->srr)
54
- memcpy(iph+opt->srr+iph[opt->srr+1]-4, &daddr, 4);
54
+ memcpy(iph + opt->srr + iph[opt->srr + 1] - 4, &daddr, 4);
5555
5656 if (!is_frag) {
5757 if (opt->rr_needaddr)
58
- ip_rt_get_source(iph+opt->rr+iph[opt->rr+2]-5, skb, rt);
58
+ ip_rt_get_source(iph + opt->rr + iph[opt->rr + 2] - 5, skb, rt);
5959 if (opt->ts_needaddr)
60
- ip_rt_get_source(iph+opt->ts+iph[opt->ts+2]-9, skb, rt);
60
+ ip_rt_get_source(iph + opt->ts + iph[opt->ts + 2] - 9, skb, rt);
6161 if (opt->ts_needtime) {
6262 __be32 midtime;
6363
6464 midtime = inet_current_timestamp();
65
- memcpy(iph+opt->ts+iph[opt->ts+2]-5, &midtime, 4);
65
+ memcpy(iph + opt->ts + iph[opt->ts + 2] - 5, &midtime, 4);
6666 }
6767 return;
6868 }
6969 if (opt->rr) {
70
- memset(iph+opt->rr, IPOPT_NOP, iph[opt->rr+1]);
70
+ memset(iph + opt->rr, IPOPT_NOP, iph[opt->rr + 1]);
7171 opt->rr = 0;
7272 opt->rr_needaddr = 0;
7373 }
7474 if (opt->ts) {
75
- memset(iph+opt->ts, IPOPT_NOP, iph[opt->ts+1]);
75
+ memset(iph + opt->ts, IPOPT_NOP, iph[opt->ts + 1]);
7676 opt->ts = 0;
7777 opt->ts_needaddr = opt->ts_needtime = 0;
7878 }
....@@ -473,6 +473,7 @@
473473 *info = htonl((pp_ptr-iph)<<24);
474474 return -EINVAL;
475475 }
476
+EXPORT_SYMBOL(__ip_options_compile);
476477
477478 int ip_options_compile(struct net *net,
478479 struct ip_options *opt, struct sk_buff *skb)
....@@ -494,39 +495,47 @@
494495 void ip_options_undo(struct ip_options *opt)
495496 {
496497 if (opt->srr) {
497
- unsigned char *optptr = opt->__data+opt->srr-sizeof(struct iphdr);
498
- memmove(optptr+7, optptr+3, optptr[1]-7);
499
- memcpy(optptr+3, &opt->faddr, 4);
498
+ unsigned char *optptr = opt->__data + opt->srr - sizeof(struct iphdr);
499
+
500
+ memmove(optptr + 7, optptr + 3, optptr[1] - 7);
501
+ memcpy(optptr + 3, &opt->faddr, 4);
500502 }
501503 if (opt->rr_needaddr) {
502
- unsigned char *optptr = opt->__data+opt->rr-sizeof(struct iphdr);
504
+ unsigned char *optptr = opt->__data + opt->rr - sizeof(struct iphdr);
505
+
503506 optptr[2] -= 4;
504
- memset(&optptr[optptr[2]-1], 0, 4);
507
+ memset(&optptr[optptr[2] - 1], 0, 4);
505508 }
506509 if (opt->ts) {
507
- unsigned char *optptr = opt->__data+opt->ts-sizeof(struct iphdr);
510
+ unsigned char *optptr = opt->__data + opt->ts - sizeof(struct iphdr);
511
+
508512 if (opt->ts_needtime) {
509513 optptr[2] -= 4;
510
- memset(&optptr[optptr[2]-1], 0, 4);
511
- if ((optptr[3]&0xF) == IPOPT_TS_PRESPEC)
514
+ memset(&optptr[optptr[2] - 1], 0, 4);
515
+ if ((optptr[3] & 0xF) == IPOPT_TS_PRESPEC)
512516 optptr[2] -= 4;
513517 }
514518 if (opt->ts_needaddr) {
515519 optptr[2] -= 4;
516
- memset(&optptr[optptr[2]-1], 0, 4);
520
+ memset(&optptr[optptr[2] - 1], 0, 4);
517521 }
518522 }
519523 }
520524
521
-static struct ip_options_rcu *ip_options_get_alloc(const int optlen)
525
+int ip_options_get(struct net *net, struct ip_options_rcu **optp,
526
+ sockptr_t data, int optlen)
522527 {
523
- return kzalloc(sizeof(struct ip_options_rcu) + ((optlen + 3) & ~3),
524
- GFP_KERNEL);
525
-}
528
+ struct ip_options_rcu *opt;
526529
527
-static int ip_options_get_finish(struct net *net, struct ip_options_rcu **optp,
528
- struct ip_options_rcu *opt, int optlen)
529
-{
530
+ opt = kzalloc(sizeof(struct ip_options_rcu) + ((optlen + 3) & ~3),
531
+ GFP_KERNEL);
532
+ if (!opt)
533
+ return -ENOMEM;
534
+ if (optlen && copy_from_sockptr(opt->opt.__data, data, optlen)) {
535
+ kfree(opt);
536
+ return -EFAULT;
537
+ }
538
+
530539 while (optlen & 3)
531540 opt->opt.__data[optlen++] = IPOPT_END;
532541 opt->opt.optlen = optlen;
....@@ -537,32 +546,6 @@
537546 kfree(*optp);
538547 *optp = opt;
539548 return 0;
540
-}
541
-
542
-int ip_options_get_from_user(struct net *net, struct ip_options_rcu **optp,
543
- unsigned char __user *data, int optlen)
544
-{
545
- struct ip_options_rcu *opt = ip_options_get_alloc(optlen);
546
-
547
- if (!opt)
548
- return -ENOMEM;
549
- if (optlen && copy_from_user(opt->opt.__data, data, optlen)) {
550
- kfree(opt);
551
- return -EFAULT;
552
- }
553
- return ip_options_get_finish(net, optp, opt, optlen);
554
-}
555
-
556
-int ip_options_get(struct net *net, struct ip_options_rcu **optp,
557
- unsigned char *data, int optlen)
558
-{
559
- struct ip_options_rcu *opt = ip_options_get_alloc(optlen);
560
-
561
- if (!opt)
562
- return -ENOMEM;
563
- if (optlen)
564
- memcpy(opt->opt.__data, data, optlen);
565
- return ip_options_get_finish(net, optp, opt, optlen);
566549 }
567550
568551 void ip_forward_options(struct sk_buff *skb)