* Re: [PATCH net-next 4/7] ipv4: remove get_rttos
@ 2025-02-08 4:44 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-02-08 4:44 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250206193521.2285488-5-willemdebruijn.kernel@gmail.com>
References: <20250206193521.2285488-5-willemdebruijn.kernel@gmail.com>
TO: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
TO: netdev@vger.kernel.org
CC: davem@davemloft.net
CC: kuba@kernel.org
CC: edumazet@google.com
CC: pabeni@redhat.com
CC: Willem de Bruijn <willemb@google.com>
Hi Willem,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Willem-de-Bruijn/tcp-only-initialize-sockcm-tsflags-field/20250207-033912
base: net-next/main
patch link: https://lore.kernel.org/r/20250206193521.2285488-5-willemdebruijn.kernel%40gmail.com
patch subject: [PATCH net-next 4/7] ipv4: remove get_rttos
:::::: branch date: 33 hours ago
:::::: commit date: 33 hours ago
config: i386-randconfig-141-20250208 (https://download.01.org/0day-ci/archive/20250208/202502081210.DN5Un7Vb-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202502081210.DN5Un7Vb-lkp@intel.com/
New smatch warnings:
net/ipv4/raw.c:608 raw_sendmsg() error: uninitialized symbol 'tos'.
net/ipv4/udp.c:1444 udp_sendmsg() error: uninitialized symbol 'tos'.
net/ipv4/ping.c:781 ping_v4_sendmsg() error: uninitialized symbol 'tos'.
Old smatch warnings:
net/ipv4/udp.c:2515 __udp4_lib_mcast_deliver() warn: potential spectre issue 'udptable->hash2' [r]
net/ipv4/udp.c:2755 __udp4_lib_mcast_demux_lookup() warn: potential spectre issue 'udptable->hash' [r]
vim +/tos +608 net/ipv4/raw.c
c008ba5bdc9fa8 Herbert Xu 2014-11-07 481
1b784140474e4f Ying Xue 2015-03-02 482 static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
^1da177e4c3f41 Linus Torvalds 2005-04-16 483 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 484 struct inet_sock *inet = inet_sk(sk);
bb191c3e874650 David Ahern 2015-10-05 485 struct net *net = sock_net(sk);
^1da177e4c3f41 Linus Torvalds 2005-04-16 486 struct ipcm_cookie ipc;
^1da177e4c3f41 Linus Torvalds 2005-04-16 487 struct rtable *rt = NULL;
77968b78242ee2 David S. Miller 2011-05-08 488 struct flowi4 fl4;
c85be08fc4fa44 Guillaume Nault 2023-05-22 489 u8 tos, scope;
^1da177e4c3f41 Linus Torvalds 2005-04-16 490 int free = 0;
3ca3c68e76686b Al Viro 2006-09-27 491 __be32 daddr;
c1d18f9fa09489 Al Viro 2006-09-27 492 __be32 saddr;
959d5c11601b2b Eric Dumazet 2023-09-22 493 int uc_index, err;
f6d8bd051c391c Eric Dumazet 2011-04-21 494 struct ip_options_data opt_copy;
c008ba5bdc9fa8 Herbert Xu 2014-11-07 495 struct raw_frag_vec rfv;
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 496 int hdrincl;
^1da177e4c3f41 Linus Torvalds 2005-04-16 497
^1da177e4c3f41 Linus Torvalds 2005-04-16 498 err = -EMSGSIZE;
926d4b8122fb32 Jesper Juhl 2005-06-18 499 if (len > 0xFFFF)
^1da177e4c3f41 Linus Torvalds 2005-04-16 500 goto out;
^1da177e4c3f41 Linus Torvalds 2005-04-16 501
cafbe182a467bf Eric Dumazet 2023-08-16 502 hdrincl = inet_test_bit(HDRINCL, sk);
cafbe182a467bf Eric Dumazet 2023-08-16 503
^1da177e4c3f41 Linus Torvalds 2005-04-16 504 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 505 * Check the flags.
^1da177e4c3f41 Linus Torvalds 2005-04-16 506 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 507
^1da177e4c3f41 Linus Torvalds 2005-04-16 508 err = -EOPNOTSUPP;
^1da177e4c3f41 Linus Torvalds 2005-04-16 509 if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message */
^1da177e4c3f41 Linus Torvalds 2005-04-16 510 goto out; /* compatibility */
^1da177e4c3f41 Linus Torvalds 2005-04-16 511
^1da177e4c3f41 Linus Torvalds 2005-04-16 512 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 513 * Get and verify the address.
^1da177e4c3f41 Linus Torvalds 2005-04-16 514 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 515
^1da177e4c3f41 Linus Torvalds 2005-04-16 516 if (msg->msg_namelen) {
342dfc306fb321 Steffen Hurrle 2014-01-17 517 DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name);
^1da177e4c3f41 Linus Torvalds 2005-04-16 518 err = -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 519 if (msg->msg_namelen < sizeof(*usin))
^1da177e4c3f41 Linus Torvalds 2005-04-16 520 goto out;
^1da177e4c3f41 Linus Torvalds 2005-04-16 521 if (usin->sin_family != AF_INET) {
058bd4d2a4ff0a Joe Perches 2012-03-11 522 pr_info_once("%s: %s forgot to set AF_INET. Fix it!\n",
058bd4d2a4ff0a Joe Perches 2012-03-11 523 __func__, current->comm);
^1da177e4c3f41 Linus Torvalds 2005-04-16 524 err = -EAFNOSUPPORT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 525 if (usin->sin_family)
^1da177e4c3f41 Linus Torvalds 2005-04-16 526 goto out;
^1da177e4c3f41 Linus Torvalds 2005-04-16 527 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 528 daddr = usin->sin_addr.s_addr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 529 /* ANK: I did not forget to get protocol from port field.
^1da177e4c3f41 Linus Torvalds 2005-04-16 530 * I just do not know, who uses this weirdness.
^1da177e4c3f41 Linus Torvalds 2005-04-16 531 * IP_HDRINCL is much more convenient.
^1da177e4c3f41 Linus Torvalds 2005-04-16 532 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 533 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 534 err = -EDESTADDRREQ;
^1da177e4c3f41 Linus Torvalds 2005-04-16 535 if (sk->sk_state != TCP_ESTABLISHED)
^1da177e4c3f41 Linus Torvalds 2005-04-16 536 goto out;
c720c7e8383aff Eric Dumazet 2009-10-15 537 daddr = inet->inet_daddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 538 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 539
351782067b6be8 Willem de Bruijn 2018-07-06 540 ipcm_init_sk(&ipc, inet);
3632679d9e4f87 Nicolas Dichtel 2023-05-22 541 /* Keep backward compat */
3632679d9e4f87 Nicolas Dichtel 2023-05-22 542 if (hdrincl)
3632679d9e4f87 Nicolas Dichtel 2023-05-22 543 ipc.protocol = IPPROTO_RAW;
^1da177e4c3f41 Linus Torvalds 2005-04-16 544
^1da177e4c3f41 Linus Torvalds 2005-04-16 545 if (msg->msg_controllen) {
24025c465f77c3 Soheil Hassas Yeganeh 2016-04-02 546 err = ip_cmsg_send(sk, msg, &ipc, false);
919483096bfe75 Eric Dumazet 2016-02-04 547 if (unlikely(err)) {
919483096bfe75 Eric Dumazet 2016-02-04 548 kfree(ipc.opt);
^1da177e4c3f41 Linus Torvalds 2005-04-16 549 goto out;
919483096bfe75 Eric Dumazet 2016-02-04 550 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 551 if (ipc.opt)
^1da177e4c3f41 Linus Torvalds 2005-04-16 552 free = 1;
^1da177e4c3f41 Linus Torvalds 2005-04-16 553 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 554
^1da177e4c3f41 Linus Torvalds 2005-04-16 555 saddr = ipc.addr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 556 ipc.addr = daddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 557
f6d8bd051c391c Eric Dumazet 2011-04-21 558 if (!ipc.opt) {
f6d8bd051c391c Eric Dumazet 2011-04-21 559 struct ip_options_rcu *inet_opt;
f6d8bd051c391c Eric Dumazet 2011-04-21 560
f6d8bd051c391c Eric Dumazet 2011-04-21 561 rcu_read_lock();
f6d8bd051c391c Eric Dumazet 2011-04-21 562 inet_opt = rcu_dereference(inet->inet_opt);
f6d8bd051c391c Eric Dumazet 2011-04-21 563 if (inet_opt) {
f6d8bd051c391c Eric Dumazet 2011-04-21 564 memcpy(&opt_copy, inet_opt,
f6d8bd051c391c Eric Dumazet 2011-04-21 565 sizeof(*inet_opt) + inet_opt->opt.optlen);
f6d8bd051c391c Eric Dumazet 2011-04-21 566 ipc.opt = &opt_copy.opt;
f6d8bd051c391c Eric Dumazet 2011-04-21 567 }
f6d8bd051c391c Eric Dumazet 2011-04-21 568 rcu_read_unlock();
f6d8bd051c391c Eric Dumazet 2011-04-21 569 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 570
^1da177e4c3f41 Linus Torvalds 2005-04-16 571 if (ipc.opt) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 572 err = -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 573 /* Linux does not mangle headers on raw sockets,
^1da177e4c3f41 Linus Torvalds 2005-04-16 574 * so that IP options + IP_HDRINCL is non-sense.
^1da177e4c3f41 Linus Torvalds 2005-04-16 575 */
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 576 if (hdrincl)
^1da177e4c3f41 Linus Torvalds 2005-04-16 577 goto done;
f6d8bd051c391c Eric Dumazet 2011-04-21 578 if (ipc.opt->opt.srr) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 579 if (!daddr)
^1da177e4c3f41 Linus Torvalds 2005-04-16 580 goto done;
f6d8bd051c391c Eric Dumazet 2011-04-21 581 daddr = ipc.opt->opt.faddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 582 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 583 }
c85be08fc4fa44 Guillaume Nault 2023-05-22 584 scope = ip_sendmsg_scope(inet, &ipc, msg);
^1da177e4c3f41 Linus Torvalds 2005-04-16 585
959d5c11601b2b Eric Dumazet 2023-09-22 586 uc_index = READ_ONCE(inet->uc_index);
f97c1e0c6ebdb6 Joe Perches 2007-12-16 587 if (ipv4_is_multicast(daddr)) {
854da991733d1b Robert Shearman 2018-10-01 588 if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
02715925222c13 Eric Dumazet 2023-09-22 589 ipc.oif = READ_ONCE(inet->mc_index);
^1da177e4c3f41 Linus Torvalds 2005-04-16 590 if (!saddr)
02715925222c13 Eric Dumazet 2023-09-22 591 saddr = READ_ONCE(inet->mc_addr);
9515a2e082f914 David Ahern 2018-01-24 592 } else if (!ipc.oif) {
959d5c11601b2b Eric Dumazet 2023-09-22 593 ipc.oif = uc_index;
959d5c11601b2b Eric Dumazet 2023-09-22 594 } else if (ipv4_is_lbcast(daddr) && uc_index) {
645f08975f4944 Miaohe Lin 2020-08-27 595 /* oif is set, packet is to local broadcast
9515a2e082f914 David Ahern 2018-01-24 596 * and uc_index is set. oif is most likely set
9515a2e082f914 David Ahern 2018-01-24 597 * by sk_bound_dev_if. If uc_index != oif check if the
9515a2e082f914 David Ahern 2018-01-24 598 * oif is an L3 master and uc_index is an L3 slave.
9515a2e082f914 David Ahern 2018-01-24 599 * If so, we want to allow the send using the uc_index.
9515a2e082f914 David Ahern 2018-01-24 600 */
959d5c11601b2b Eric Dumazet 2023-09-22 601 if (ipc.oif != uc_index &&
9515a2e082f914 David Ahern 2018-01-24 602 ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
959d5c11601b2b Eric Dumazet 2023-09-22 603 uc_index)) {
959d5c11601b2b Eric Dumazet 2023-09-22 604 ipc.oif = uc_index;
9515a2e082f914 David Ahern 2018-01-24 605 }
9515a2e082f914 David Ahern 2018-01-24 606 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 607
c85be08fc4fa44 Guillaume Nault 2023-05-22 @608 flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
3632679d9e4f87 Nicolas Dichtel 2023-05-22 609 hdrincl ? ipc.protocol : sk->sk_protocol,
0e0d44ab427554 Steffen Klassert 2013-08-28 610 inet_sk_flowi_flags(sk) |
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 611 (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
e2d118a1cb5e60 Lorenzo Colitti 2016-11-04 612 daddr, saddr, 0, 0, sk->sk_uid);
ef164ae3563bf4 David S. Miller 2011-03-31 613
fc1092f5156727 Shigeru Yoshida 2024-04-30 614 fl4.fl4_icmp_type = 0;
fc1092f5156727 Shigeru Yoshida 2024-04-30 615 fl4.fl4_icmp_code = 0;
fc1092f5156727 Shigeru Yoshida 2024-04-30 616
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 617 if (!hdrincl) {
b61e9dcc5e77d5 Al Viro 2014-11-24 618 rfv.msg = msg;
c008ba5bdc9fa8 Herbert Xu 2014-11-07 619 rfv.hlen = 0;
c008ba5bdc9fa8 Herbert Xu 2014-11-07 620
c008ba5bdc9fa8 Herbert Xu 2014-11-07 621 err = raw_probe_proto_opt(&rfv, &fl4);
a27b58fed90cc5 Heiko Carstens 2006-10-30 622 if (err)
a27b58fed90cc5 Heiko Carstens 2006-10-30 623 goto done;
a27b58fed90cc5 Heiko Carstens 2006-10-30 624 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 625
3df98d79215ace Paul Moore 2020-09-27 626 security_sk_classify_flow(sk, flowi4_to_flowi_common(&fl4));
bb191c3e874650 David Ahern 2015-10-05 627 rt = ip_route_output_flow(net, &fl4, sk);
b23dd4fe42b455 David S. Miller 2011-03-02 628 if (IS_ERR(rt)) {
b23dd4fe42b455 David S. Miller 2011-03-02 629 err = PTR_ERR(rt);
4910ac6c526d28 David S. Miller 2011-03-28 630 rt = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 631 goto done;
b23dd4fe42b455 David S. Miller 2011-03-02 632 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 633
^1da177e4c3f41 Linus Torvalds 2005-04-16 634 err = -EACCES;
^1da177e4c3f41 Linus Torvalds 2005-04-16 635 if (rt->rt_flags & RTCF_BROADCAST && !sock_flag(sk, SOCK_BROADCAST))
^1da177e4c3f41 Linus Torvalds 2005-04-16 636 goto done;
^1da177e4c3f41 Linus Torvalds 2005-04-16 637
^1da177e4c3f41 Linus Torvalds 2005-04-16 638 if (msg->msg_flags & MSG_CONFIRM)
^1da177e4c3f41 Linus Torvalds 2005-04-16 639 goto do_confirm;
^1da177e4c3f41 Linus Torvalds 2005-04-16 640 back_from_confirm:
^1da177e4c3f41 Linus Torvalds 2005-04-16 641
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 642 if (hdrincl)
7ae9abfd9d6f32 Al Viro 2014-11-27 643 err = raw_send_hdrinc(sk, &fl4, msg, len,
c14ac9451c3483 Soheil Hassas Yeganeh 2016-04-02 644 &rt, msg->msg_flags, &ipc.sockc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 645
^1da177e4c3f41 Linus Torvalds 2005-04-16 646 else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 647 if (!ipc.addr)
77968b78242ee2 David S. Miller 2011-05-08 648 ipc.addr = fl4.daddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 649 lock_sock(sk);
c008ba5bdc9fa8 Herbert Xu 2014-11-07 650 err = ip_append_data(sk, &fl4, raw_getfrag,
c008ba5bdc9fa8 Herbert Xu 2014-11-07 651 &rfv, len, 0,
2e77d89b2fa8e3 Eric Dumazet 2008-11-24 652 &ipc, &rt, msg->msg_flags);
^1da177e4c3f41 Linus Torvalds 2005-04-16 653 if (err)
^1da177e4c3f41 Linus Torvalds 2005-04-16 654 ip_flush_pending_frames(sk);
6ce9e7b5fe3195 Eric Dumazet 2009-09-02 655 else if (!(msg->msg_flags & MSG_MORE)) {
77968b78242ee2 David S. Miller 2011-05-08 656 err = ip_push_pending_frames(sk, &fl4);
6b5f43ea08150e Eric Dumazet 2023-08-16 657 if (err == -ENOBUFS && !inet_test_bit(RECVERR, sk))
6ce9e7b5fe3195 Eric Dumazet 2009-09-02 658 err = 0;
6ce9e7b5fe3195 Eric Dumazet 2009-09-02 659 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 660 release_sock(sk);
^1da177e4c3f41 Linus Torvalds 2005-04-16 661 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 662 done:
^1da177e4c3f41 Linus Torvalds 2005-04-16 663 if (free)
^1da177e4c3f41 Linus Torvalds 2005-04-16 664 kfree(ipc.opt);
^1da177e4c3f41 Linus Torvalds 2005-04-16 665 ip_rt_put(rt);
^1da177e4c3f41 Linus Torvalds 2005-04-16 666
5418c6926fcb0e Jesper Juhl 2005-06-18 667 out:
5418c6926fcb0e Jesper Juhl 2005-06-18 668 if (err < 0)
5418c6926fcb0e Jesper Juhl 2005-06-18 669 return err;
5418c6926fcb0e Jesper Juhl 2005-06-18 670 return len;
^1da177e4c3f41 Linus Torvalds 2005-04-16 671
^1da177e4c3f41 Linus Torvalds 2005-04-16 672 do_confirm:
0dec879f636f11 Julian Anastasov 2017-02-06 673 if (msg->msg_flags & MSG_PROBE)
0dec879f636f11 Julian Anastasov 2017-02-06 674 dst_confirm_neigh(&rt->dst, &fl4.daddr);
^1da177e4c3f41 Linus Torvalds 2005-04-16 675 if (!(msg->msg_flags & MSG_PROBE) || len)
^1da177e4c3f41 Linus Torvalds 2005-04-16 676 goto back_from_confirm;
^1da177e4c3f41 Linus Torvalds 2005-04-16 677 err = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 678 goto done;
^1da177e4c3f41 Linus Torvalds 2005-04-16 679 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 680
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net-next 0/7] net: deduplicate cookie logic
@ 2025-02-06 19:34 Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 4/7] ipv4: remove get_rttos Willem de Bruijn
0 siblings, 1 reply; 5+ messages in thread
From: Willem de Bruijn @ 2025-02-06 19:34 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, edumazet, pabeni, Willem de Bruijn
From: Willem de Bruijn <willemb@google.com>
Reuse standard sk, ip and ipv6 cookie init handlers where possible.
Avoid repeated open coding of the same logic.
Harmonize feature sets across protocols.
Make IPv4 and IPv6 logic more alike.
Simplify adding future new fields with a single init point.
Willem de Bruijn (7):
tcp: only initialize sockcm tsflags field
net: initialize mark in sockcm_init
ipv4: initialize inet socket cookies with sockcm_init
ipv4: remove get_rttos
icmp: reflect tos through ip cookie rather than updating inet_sk
ipv6: replace ipcm6_init calls with ipcm6_init_sk
ipv6: initialize inet socket cookies with sockcm_init
include/net/ip.h | 16 +++++-----------
include/net/ipv6.h | 11 ++---------
include/net/sock.h | 1 +
net/can/raw.c | 2 +-
net/ipv4/icmp.c | 4 ++--
net/ipv4/ip_sockglue.c | 4 ++--
net/ipv4/ping.c | 1 -
net/ipv4/raw.c | 1 -
net/ipv4/tcp.c | 2 +-
net/ipv4/udp.c | 1 -
net/ipv6/ping.c | 3 ---
net/ipv6/raw.c | 15 +++------------
net/ipv6/udp.c | 10 +---------
net/l2tp/l2tp_ip6.c | 8 +-------
net/packet/af_packet.c | 9 ++++-----
15 files changed, 23 insertions(+), 65 deletions(-)
--
2.48.1.502.g6dc24dfdaf-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 4/7] ipv4: remove get_rttos
2025-02-06 19:34 [PATCH net-next 0/7] net: deduplicate cookie logic Willem de Bruijn
@ 2025-02-06 19:34 ` Willem de Bruijn
2025-02-07 0:59 ` Willem de Bruijn
2025-02-08 9:24 ` kernel test robot
0 siblings, 2 replies; 5+ messages in thread
From: Willem de Bruijn @ 2025-02-06 19:34 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, edumazet, pabeni, Willem de Bruijn
From: Willem de Bruijn <willemb@google.com>
Initialize the ip cookie tos field when initializing the cookie, in
ipcm_init_sk.
The existing code inverts the standard pattern for initializing cookie
fields. Default is to initialize the field from the sk, then possibly
overwrite that when parsing cmsgs (the unlikely case).
This field inverts that, setting the field to an illegal value and
after cmsg parsing checking whether the value is still illegal and
thus should be overridden.
Be careful to always apply mask INET_DSCP_MASK, as before.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
include/net/ip.h | 11 +++--------
net/ipv4/ip_sockglue.c | 4 ++--
net/ipv4/ping.c | 1 -
net/ipv4/raw.c | 1 -
net/ipv4/udp.c | 1 -
5 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/include/net/ip.h b/include/net/ip.h
index 6af16545b3e3..6819704e2642 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -92,7 +92,9 @@ static inline void ipcm_init(struct ipcm_cookie *ipcm)
static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
const struct inet_sock *inet)
{
- ipcm_init(ipcm);
+ *ipcm = (struct ipcm_cookie) {
+ .tos = READ_ONCE(inet->tos) & INET_DSCP_MASK,
+ };
sockcm_init(&ipcm->sockc, &inet->sk);
@@ -256,13 +258,6 @@ static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
return RT_SCOPE_UNIVERSE;
}
-static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
-{
- u8 dsfield = ipc->tos != -1 ? ipc->tos : READ_ONCE(inet->tos);
-
- return dsfield & INET_DSCP_MASK;
-}
-
/* datagram.c */
int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 6d9c5c20b1c4..98b1e4a8b72e 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -314,8 +314,8 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
return -EINVAL;
if (val < 0 || val > 255)
return -EINVAL;
- ipc->tos = val;
- ipc->sockc.priority = rt_tos2priority(ipc->tos);
+ ipc->sockc.priority = rt_tos2priority(val);
+ ipc->tos = val & INET_DSCP_MASK;
break;
case IP_PROTOCOL:
if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 619ddc087957..0215885c6df5 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -768,7 +768,6 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
}
faddr = ipc.opt->opt.faddr;
}
- tos = get_rttos(&ipc, inet);
scope = ip_sendmsg_scope(inet, &ipc, msg);
if (ipv4_is_multicast(daddr)) {
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index 4304a68d1db0..b1f3fe7962bf 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -581,7 +581,6 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
daddr = ipc.opt->opt.faddr;
}
}
- tos = get_rttos(&ipc, inet);
scope = ip_sendmsg_scope(inet, &ipc, msg);
uc_index = READ_ONCE(inet->uc_index);
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index c472c9a57cf6..97ded5f0ae6c 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1405,7 +1405,6 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
faddr = ipc.opt->opt.faddr;
connected = 0;
}
- tos = get_rttos(&ipc, inet);
scope = ip_sendmsg_scope(inet, &ipc, msg);
if (scope == RT_SCOPE_LINK)
connected = 0;
--
2.48.1.502.g6dc24dfdaf-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net-next 4/7] ipv4: remove get_rttos
2025-02-06 19:34 ` [PATCH net-next 4/7] ipv4: remove get_rttos Willem de Bruijn
@ 2025-02-07 0:59 ` Willem de Bruijn
2025-02-07 17:33 ` Willem de Bruijn
2025-02-08 9:24 ` kernel test robot
1 sibling, 1 reply; 5+ messages in thread
From: Willem de Bruijn @ 2025-02-07 0:59 UTC (permalink / raw)
To: Willem de Bruijn, netdev; +Cc: davem, kuba, edumazet, pabeni, Willem de Bruijn
Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
>
> Initialize the ip cookie tos field when initializing the cookie, in
> ipcm_init_sk.
>
> The existing code inverts the standard pattern for initializing cookie
> fields. Default is to initialize the field from the sk, then possibly
> overwrite that when parsing cmsgs (the unlikely case).
>
> This field inverts that, setting the field to an illegal value and
> after cmsg parsing checking whether the value is still illegal and
> thus should be overridden.
>
> Be careful to always apply mask INET_DSCP_MASK, as before.
>
> Signed-off-by: Willem de Bruijn <willemb@google.com>
> ---
> include/net/ip.h | 11 +++--------
> net/ipv4/ip_sockglue.c | 4 ++--
> net/ipv4/ping.c | 1 -
> net/ipv4/raw.c | 1 -
> net/ipv4/udp.c | 1 -
> 5 files changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/include/net/ip.h b/include/net/ip.h
> index 6af16545b3e3..6819704e2642 100644
> --- a/include/net/ip.h
> +++ b/include/net/ip.h
> @@ -92,7 +92,9 @@ static inline void ipcm_init(struct ipcm_cookie *ipcm)
> static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
> const struct inet_sock *inet)
> {
> - ipcm_init(ipcm);
> + *ipcm = (struct ipcm_cookie) {
> + .tos = READ_ONCE(inet->tos) & INET_DSCP_MASK,
> + };
>
> sockcm_init(&ipcm->sockc, &inet->sk);
>
> @@ -256,13 +258,6 @@ static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
> return RT_SCOPE_UNIVERSE;
> }
>
> -static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
> -{
> - u8 dsfield = ipc->tos != -1 ? ipc->tos : READ_ONCE(inet->tos);
> -
> - return dsfield & INET_DSCP_MASK;
> -}
> -
> /* datagram.c */
> int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
> int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index 6d9c5c20b1c4..98b1e4a8b72e 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c
> @@ -314,8 +314,8 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
> return -EINVAL;
> if (val < 0 || val > 255)
> return -EINVAL;
> - ipc->tos = val;
> - ipc->sockc.priority = rt_tos2priority(ipc->tos);
> + ipc->sockc.priority = rt_tos2priority(val);
> + ipc->tos = val & INET_DSCP_MASK;
> break;
> case IP_PROTOCOL:
> if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
> diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
> index 619ddc087957..0215885c6df5 100644
> --- a/net/ipv4/ping.c
> +++ b/net/ipv4/ping.c
> @@ -768,7 +768,6 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> }
> faddr = ipc.opt->opt.faddr;
> }
> - tos = get_rttos(&ipc, inet);
Here and elsewhere, subsequent code needs to use ipc.tos directly.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH net-next 4/7] ipv4: remove get_rttos
2025-02-07 0:59 ` Willem de Bruijn
@ 2025-02-07 17:33 ` Willem de Bruijn
0 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2025-02-07 17:33 UTC (permalink / raw)
To: Willem de Bruijn, Willem de Bruijn, netdev
Cc: davem, kuba, edumazet, pabeni, Willem de Bruijn
Willem de Bruijn wrote:
> Willem de Bruijn wrote:
> > From: Willem de Bruijn <willemb@google.com>
> >
> > Initialize the ip cookie tos field when initializing the cookie, in
> > ipcm_init_sk.
> >
> > The existing code inverts the standard pattern for initializing cookie
> > fields. Default is to initialize the field from the sk, then possibly
> > overwrite that when parsing cmsgs (the unlikely case).
> >
> > This field inverts that, setting the field to an illegal value and
> > after cmsg parsing checking whether the value is still illegal and
> > thus should be overridden.
> >
> > Be careful to always apply mask INET_DSCP_MASK, as before.
> >
> > Signed-off-by: Willem de Bruijn <willemb@google.com>
> > ---
> > include/net/ip.h | 11 +++--------
> > net/ipv4/ip_sockglue.c | 4 ++--
> > net/ipv4/ping.c | 1 -
> > net/ipv4/raw.c | 1 -
> > net/ipv4/udp.c | 1 -
> > 5 files changed, 5 insertions(+), 13 deletions(-)
> >
> > diff --git a/include/net/ip.h b/include/net/ip.h
> > index 6af16545b3e3..6819704e2642 100644
> > --- a/include/net/ip.h
> > +++ b/include/net/ip.h
> > @@ -92,7 +92,9 @@ static inline void ipcm_init(struct ipcm_cookie *ipcm)
> > static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,
> > const struct inet_sock *inet)
> > {
> > - ipcm_init(ipcm);
> > + *ipcm = (struct ipcm_cookie) {
> > + .tos = READ_ONCE(inet->tos) & INET_DSCP_MASK,
> > + };
> >
> > sockcm_init(&ipcm->sockc, &inet->sk);
> >
> > @@ -256,13 +258,6 @@ static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
> > return RT_SCOPE_UNIVERSE;
> > }
> >
> > -static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
> > -{
> > - u8 dsfield = ipc->tos != -1 ? ipc->tos : READ_ONCE(inet->tos);
> > -
> > - return dsfield & INET_DSCP_MASK;
> > -}
> > -
> > /* datagram.c */
> > int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
> > int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
> > diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> > index 6d9c5c20b1c4..98b1e4a8b72e 100644
> > --- a/net/ipv4/ip_sockglue.c
> > +++ b/net/ipv4/ip_sockglue.c
> > @@ -314,8 +314,8 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
> > return -EINVAL;
> > if (val < 0 || val > 255)
> > return -EINVAL;
> > - ipc->tos = val;
> > - ipc->sockc.priority = rt_tos2priority(ipc->tos);
> > + ipc->sockc.priority = rt_tos2priority(val);
> > + ipc->tos = val & INET_DSCP_MASK;
> > break;
> > case IP_PROTOCOL:
> > if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
> > diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
> > index 619ddc087957..0215885c6df5 100644
> > --- a/net/ipv4/ping.c
> > +++ b/net/ipv4/ping.c
> > @@ -768,7 +768,6 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> > }
> > faddr = ipc.opt->opt.faddr;
> > }
> > - tos = get_rttos(&ipc, inet);
>
> Here and elsewhere, subsequent code needs to use ipc.tos directly.
Actually I misunderstood the purpose of get_rttos.
It only masks the dsfield when passed to the routing layer, with
flowi4_init_output().
The other purpose of ipc->tos, to initialize iph->tos, takes the
unmasked version including ECN bits.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 4/7] ipv4: remove get_rttos
2025-02-06 19:34 ` [PATCH net-next 4/7] ipv4: remove get_rttos Willem de Bruijn
2025-02-07 0:59 ` Willem de Bruijn
@ 2025-02-08 9:24 ` kernel test robot
1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-02-08 9:24 UTC (permalink / raw)
To: Willem de Bruijn, netdev
Cc: llvm, oe-kbuild-all, davem, kuba, edumazet, pabeni,
Willem de Bruijn
Hi Willem,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Willem-de-Bruijn/tcp-only-initialize-sockcm-tsflags-field/20250207-033912
base: net-next/main
patch link: https://lore.kernel.org/r/20250206193521.2285488-5-willemdebruijn.kernel%40gmail.com
patch subject: [PATCH net-next 4/7] ipv4: remove get_rttos
config: x86_64-buildonly-randconfig-002-20250207 (https://download.01.org/0day-ci/archive/20250208/202502081713.QmBbIMec-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250208/202502081713.QmBbIMec-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502081713.QmBbIMec-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> net/ipv4/raw.c:608:52: warning: variable 'tos' is uninitialized when used here [-Wuninitialized]
608 | flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
| ^~~
net/ipv4/raw.c:489:8: note: initialize the variable 'tos' to silence this warning
489 | u8 tos, scope;
| ^
| = '\0'
1 warning generated.
--
>> net/ipv4/udp.c:1444:52: warning: variable 'tos' is uninitialized when used here [-Wuninitialized]
1444 | flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, tos, scope,
| ^~~
net/ipv4/udp.c:1284:8: note: initialize the variable 'tos' to silence this warning
1284 | u8 tos, scope;
| ^
| = '\0'
net/ipv4/udp.c:3883:27: warning: bitwise operation between different enumeration types ('enum bpf_reg_type' and 'enum bpf_type_flag') [-Wenum-enum-conversion]
3883 | PTR_TO_BTF_ID_OR_NULL | PTR_TRUSTED },
| ~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
2 warnings generated.
--
>> net/ipv4/ping.c:781:52: warning: variable 'tos' is uninitialized when used here [-Wuninitialized]
781 | flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
| ^~~
net/ipv4/ping.c:708:8: note: initialize the variable 'tos' to silence this warning
708 | u8 tos, scope;
| ^
| = '\0'
1 warning generated.
vim +/tos +608 net/ipv4/raw.c
c008ba5bdc9fa8 Herbert Xu 2014-11-07 481
1b784140474e4f Ying Xue 2015-03-02 482 static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
^1da177e4c3f41 Linus Torvalds 2005-04-16 483 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 484 struct inet_sock *inet = inet_sk(sk);
bb191c3e874650 David Ahern 2015-10-05 485 struct net *net = sock_net(sk);
^1da177e4c3f41 Linus Torvalds 2005-04-16 486 struct ipcm_cookie ipc;
^1da177e4c3f41 Linus Torvalds 2005-04-16 487 struct rtable *rt = NULL;
77968b78242ee2 David S. Miller 2011-05-08 488 struct flowi4 fl4;
c85be08fc4fa44 Guillaume Nault 2023-05-22 489 u8 tos, scope;
^1da177e4c3f41 Linus Torvalds 2005-04-16 490 int free = 0;
3ca3c68e76686b Al Viro 2006-09-27 491 __be32 daddr;
c1d18f9fa09489 Al Viro 2006-09-27 492 __be32 saddr;
959d5c11601b2b Eric Dumazet 2023-09-22 493 int uc_index, err;
f6d8bd051c391c Eric Dumazet 2011-04-21 494 struct ip_options_data opt_copy;
c008ba5bdc9fa8 Herbert Xu 2014-11-07 495 struct raw_frag_vec rfv;
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 496 int hdrincl;
^1da177e4c3f41 Linus Torvalds 2005-04-16 497
^1da177e4c3f41 Linus Torvalds 2005-04-16 498 err = -EMSGSIZE;
926d4b8122fb32 Jesper Juhl 2005-06-18 499 if (len > 0xFFFF)
^1da177e4c3f41 Linus Torvalds 2005-04-16 500 goto out;
^1da177e4c3f41 Linus Torvalds 2005-04-16 501
cafbe182a467bf Eric Dumazet 2023-08-16 502 hdrincl = inet_test_bit(HDRINCL, sk);
cafbe182a467bf Eric Dumazet 2023-08-16 503
^1da177e4c3f41 Linus Torvalds 2005-04-16 504 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 505 * Check the flags.
^1da177e4c3f41 Linus Torvalds 2005-04-16 506 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 507
^1da177e4c3f41 Linus Torvalds 2005-04-16 508 err = -EOPNOTSUPP;
^1da177e4c3f41 Linus Torvalds 2005-04-16 509 if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message */
^1da177e4c3f41 Linus Torvalds 2005-04-16 510 goto out; /* compatibility */
^1da177e4c3f41 Linus Torvalds 2005-04-16 511
^1da177e4c3f41 Linus Torvalds 2005-04-16 512 /*
^1da177e4c3f41 Linus Torvalds 2005-04-16 513 * Get and verify the address.
^1da177e4c3f41 Linus Torvalds 2005-04-16 514 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 515
^1da177e4c3f41 Linus Torvalds 2005-04-16 516 if (msg->msg_namelen) {
342dfc306fb321 Steffen Hurrle 2014-01-17 517 DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name);
^1da177e4c3f41 Linus Torvalds 2005-04-16 518 err = -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 519 if (msg->msg_namelen < sizeof(*usin))
^1da177e4c3f41 Linus Torvalds 2005-04-16 520 goto out;
^1da177e4c3f41 Linus Torvalds 2005-04-16 521 if (usin->sin_family != AF_INET) {
058bd4d2a4ff0a Joe Perches 2012-03-11 522 pr_info_once("%s: %s forgot to set AF_INET. Fix it!\n",
058bd4d2a4ff0a Joe Perches 2012-03-11 523 __func__, current->comm);
^1da177e4c3f41 Linus Torvalds 2005-04-16 524 err = -EAFNOSUPPORT;
^1da177e4c3f41 Linus Torvalds 2005-04-16 525 if (usin->sin_family)
^1da177e4c3f41 Linus Torvalds 2005-04-16 526 goto out;
^1da177e4c3f41 Linus Torvalds 2005-04-16 527 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 528 daddr = usin->sin_addr.s_addr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 529 /* ANK: I did not forget to get protocol from port field.
^1da177e4c3f41 Linus Torvalds 2005-04-16 530 * I just do not know, who uses this weirdness.
^1da177e4c3f41 Linus Torvalds 2005-04-16 531 * IP_HDRINCL is much more convenient.
^1da177e4c3f41 Linus Torvalds 2005-04-16 532 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 533 } else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 534 err = -EDESTADDRREQ;
^1da177e4c3f41 Linus Torvalds 2005-04-16 535 if (sk->sk_state != TCP_ESTABLISHED)
^1da177e4c3f41 Linus Torvalds 2005-04-16 536 goto out;
c720c7e8383aff Eric Dumazet 2009-10-15 537 daddr = inet->inet_daddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 538 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 539
351782067b6be8 Willem de Bruijn 2018-07-06 540 ipcm_init_sk(&ipc, inet);
3632679d9e4f87 Nicolas Dichtel 2023-05-22 541 /* Keep backward compat */
3632679d9e4f87 Nicolas Dichtel 2023-05-22 542 if (hdrincl)
3632679d9e4f87 Nicolas Dichtel 2023-05-22 543 ipc.protocol = IPPROTO_RAW;
^1da177e4c3f41 Linus Torvalds 2005-04-16 544
^1da177e4c3f41 Linus Torvalds 2005-04-16 545 if (msg->msg_controllen) {
24025c465f77c3 Soheil Hassas Yeganeh 2016-04-02 546 err = ip_cmsg_send(sk, msg, &ipc, false);
919483096bfe75 Eric Dumazet 2016-02-04 547 if (unlikely(err)) {
919483096bfe75 Eric Dumazet 2016-02-04 548 kfree(ipc.opt);
^1da177e4c3f41 Linus Torvalds 2005-04-16 549 goto out;
919483096bfe75 Eric Dumazet 2016-02-04 550 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 551 if (ipc.opt)
^1da177e4c3f41 Linus Torvalds 2005-04-16 552 free = 1;
^1da177e4c3f41 Linus Torvalds 2005-04-16 553 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 554
^1da177e4c3f41 Linus Torvalds 2005-04-16 555 saddr = ipc.addr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 556 ipc.addr = daddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 557
f6d8bd051c391c Eric Dumazet 2011-04-21 558 if (!ipc.opt) {
f6d8bd051c391c Eric Dumazet 2011-04-21 559 struct ip_options_rcu *inet_opt;
f6d8bd051c391c Eric Dumazet 2011-04-21 560
f6d8bd051c391c Eric Dumazet 2011-04-21 561 rcu_read_lock();
f6d8bd051c391c Eric Dumazet 2011-04-21 562 inet_opt = rcu_dereference(inet->inet_opt);
f6d8bd051c391c Eric Dumazet 2011-04-21 563 if (inet_opt) {
f6d8bd051c391c Eric Dumazet 2011-04-21 564 memcpy(&opt_copy, inet_opt,
f6d8bd051c391c Eric Dumazet 2011-04-21 565 sizeof(*inet_opt) + inet_opt->opt.optlen);
f6d8bd051c391c Eric Dumazet 2011-04-21 566 ipc.opt = &opt_copy.opt;
f6d8bd051c391c Eric Dumazet 2011-04-21 567 }
f6d8bd051c391c Eric Dumazet 2011-04-21 568 rcu_read_unlock();
f6d8bd051c391c Eric Dumazet 2011-04-21 569 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 570
^1da177e4c3f41 Linus Torvalds 2005-04-16 571 if (ipc.opt) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 572 err = -EINVAL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 573 /* Linux does not mangle headers on raw sockets,
^1da177e4c3f41 Linus Torvalds 2005-04-16 574 * so that IP options + IP_HDRINCL is non-sense.
^1da177e4c3f41 Linus Torvalds 2005-04-16 575 */
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 576 if (hdrincl)
^1da177e4c3f41 Linus Torvalds 2005-04-16 577 goto done;
f6d8bd051c391c Eric Dumazet 2011-04-21 578 if (ipc.opt->opt.srr) {
^1da177e4c3f41 Linus Torvalds 2005-04-16 579 if (!daddr)
^1da177e4c3f41 Linus Torvalds 2005-04-16 580 goto done;
f6d8bd051c391c Eric Dumazet 2011-04-21 581 daddr = ipc.opt->opt.faddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 582 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 583 }
c85be08fc4fa44 Guillaume Nault 2023-05-22 584 scope = ip_sendmsg_scope(inet, &ipc, msg);
^1da177e4c3f41 Linus Torvalds 2005-04-16 585
959d5c11601b2b Eric Dumazet 2023-09-22 586 uc_index = READ_ONCE(inet->uc_index);
f97c1e0c6ebdb6 Joe Perches 2007-12-16 587 if (ipv4_is_multicast(daddr)) {
854da991733d1b Robert Shearman 2018-10-01 588 if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
02715925222c13 Eric Dumazet 2023-09-22 589 ipc.oif = READ_ONCE(inet->mc_index);
^1da177e4c3f41 Linus Torvalds 2005-04-16 590 if (!saddr)
02715925222c13 Eric Dumazet 2023-09-22 591 saddr = READ_ONCE(inet->mc_addr);
9515a2e082f914 David Ahern 2018-01-24 592 } else if (!ipc.oif) {
959d5c11601b2b Eric Dumazet 2023-09-22 593 ipc.oif = uc_index;
959d5c11601b2b Eric Dumazet 2023-09-22 594 } else if (ipv4_is_lbcast(daddr) && uc_index) {
645f08975f4944 Miaohe Lin 2020-08-27 595 /* oif is set, packet is to local broadcast
9515a2e082f914 David Ahern 2018-01-24 596 * and uc_index is set. oif is most likely set
9515a2e082f914 David Ahern 2018-01-24 597 * by sk_bound_dev_if. If uc_index != oif check if the
9515a2e082f914 David Ahern 2018-01-24 598 * oif is an L3 master and uc_index is an L3 slave.
9515a2e082f914 David Ahern 2018-01-24 599 * If so, we want to allow the send using the uc_index.
9515a2e082f914 David Ahern 2018-01-24 600 */
959d5c11601b2b Eric Dumazet 2023-09-22 601 if (ipc.oif != uc_index &&
9515a2e082f914 David Ahern 2018-01-24 602 ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
959d5c11601b2b Eric Dumazet 2023-09-22 603 uc_index)) {
959d5c11601b2b Eric Dumazet 2023-09-22 604 ipc.oif = uc_index;
9515a2e082f914 David Ahern 2018-01-24 605 }
9515a2e082f914 David Ahern 2018-01-24 606 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 607
c85be08fc4fa44 Guillaume Nault 2023-05-22 @608 flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
3632679d9e4f87 Nicolas Dichtel 2023-05-22 609 hdrincl ? ipc.protocol : sk->sk_protocol,
0e0d44ab427554 Steffen Klassert 2013-08-28 610 inet_sk_flowi_flags(sk) |
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 611 (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
e2d118a1cb5e60 Lorenzo Colitti 2016-11-04 612 daddr, saddr, 0, 0, sk->sk_uid);
ef164ae3563bf4 David S. Miller 2011-03-31 613
fc1092f5156727 Shigeru Yoshida 2024-04-30 614 fl4.fl4_icmp_type = 0;
fc1092f5156727 Shigeru Yoshida 2024-04-30 615 fl4.fl4_icmp_code = 0;
fc1092f5156727 Shigeru Yoshida 2024-04-30 616
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 617 if (!hdrincl) {
b61e9dcc5e77d5 Al Viro 2014-11-24 618 rfv.msg = msg;
c008ba5bdc9fa8 Herbert Xu 2014-11-07 619 rfv.hlen = 0;
c008ba5bdc9fa8 Herbert Xu 2014-11-07 620
c008ba5bdc9fa8 Herbert Xu 2014-11-07 621 err = raw_probe_proto_opt(&rfv, &fl4);
a27b58fed90cc5 Heiko Carstens 2006-10-30 622 if (err)
a27b58fed90cc5 Heiko Carstens 2006-10-30 623 goto done;
a27b58fed90cc5 Heiko Carstens 2006-10-30 624 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 625
3df98d79215ace Paul Moore 2020-09-27 626 security_sk_classify_flow(sk, flowi4_to_flowi_common(&fl4));
bb191c3e874650 David Ahern 2015-10-05 627 rt = ip_route_output_flow(net, &fl4, sk);
b23dd4fe42b455 David S. Miller 2011-03-02 628 if (IS_ERR(rt)) {
b23dd4fe42b455 David S. Miller 2011-03-02 629 err = PTR_ERR(rt);
4910ac6c526d28 David S. Miller 2011-03-28 630 rt = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16 631 goto done;
b23dd4fe42b455 David S. Miller 2011-03-02 632 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 633
^1da177e4c3f41 Linus Torvalds 2005-04-16 634 err = -EACCES;
^1da177e4c3f41 Linus Torvalds 2005-04-16 635 if (rt->rt_flags & RTCF_BROADCAST && !sock_flag(sk, SOCK_BROADCAST))
^1da177e4c3f41 Linus Torvalds 2005-04-16 636 goto done;
^1da177e4c3f41 Linus Torvalds 2005-04-16 637
^1da177e4c3f41 Linus Torvalds 2005-04-16 638 if (msg->msg_flags & MSG_CONFIRM)
^1da177e4c3f41 Linus Torvalds 2005-04-16 639 goto do_confirm;
^1da177e4c3f41 Linus Torvalds 2005-04-16 640 back_from_confirm:
^1da177e4c3f41 Linus Torvalds 2005-04-16 641
8f659a03a0ba92 Mohamed Ghannam 2017-12-10 642 if (hdrincl)
7ae9abfd9d6f32 Al Viro 2014-11-27 643 err = raw_send_hdrinc(sk, &fl4, msg, len,
c14ac9451c3483 Soheil Hassas Yeganeh 2016-04-02 644 &rt, msg->msg_flags, &ipc.sockc);
^1da177e4c3f41 Linus Torvalds 2005-04-16 645
^1da177e4c3f41 Linus Torvalds 2005-04-16 646 else {
^1da177e4c3f41 Linus Torvalds 2005-04-16 647 if (!ipc.addr)
77968b78242ee2 David S. Miller 2011-05-08 648 ipc.addr = fl4.daddr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 649 lock_sock(sk);
c008ba5bdc9fa8 Herbert Xu 2014-11-07 650 err = ip_append_data(sk, &fl4, raw_getfrag,
c008ba5bdc9fa8 Herbert Xu 2014-11-07 651 &rfv, len, 0,
2e77d89b2fa8e3 Eric Dumazet 2008-11-24 652 &ipc, &rt, msg->msg_flags);
^1da177e4c3f41 Linus Torvalds 2005-04-16 653 if (err)
^1da177e4c3f41 Linus Torvalds 2005-04-16 654 ip_flush_pending_frames(sk);
6ce9e7b5fe3195 Eric Dumazet 2009-09-02 655 else if (!(msg->msg_flags & MSG_MORE)) {
77968b78242ee2 David S. Miller 2011-05-08 656 err = ip_push_pending_frames(sk, &fl4);
6b5f43ea08150e Eric Dumazet 2023-08-16 657 if (err == -ENOBUFS && !inet_test_bit(RECVERR, sk))
6ce9e7b5fe3195 Eric Dumazet 2009-09-02 658 err = 0;
6ce9e7b5fe3195 Eric Dumazet 2009-09-02 659 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 660 release_sock(sk);
^1da177e4c3f41 Linus Torvalds 2005-04-16 661 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 662 done:
^1da177e4c3f41 Linus Torvalds 2005-04-16 663 if (free)
^1da177e4c3f41 Linus Torvalds 2005-04-16 664 kfree(ipc.opt);
^1da177e4c3f41 Linus Torvalds 2005-04-16 665 ip_rt_put(rt);
^1da177e4c3f41 Linus Torvalds 2005-04-16 666
5418c6926fcb0e Jesper Juhl 2005-06-18 667 out:
5418c6926fcb0e Jesper Juhl 2005-06-18 668 if (err < 0)
5418c6926fcb0e Jesper Juhl 2005-06-18 669 return err;
5418c6926fcb0e Jesper Juhl 2005-06-18 670 return len;
^1da177e4c3f41 Linus Torvalds 2005-04-16 671
^1da177e4c3f41 Linus Torvalds 2005-04-16 672 do_confirm:
0dec879f636f11 Julian Anastasov 2017-02-06 673 if (msg->msg_flags & MSG_PROBE)
0dec879f636f11 Julian Anastasov 2017-02-06 674 dst_confirm_neigh(&rt->dst, &fl4.daddr);
^1da177e4c3f41 Linus Torvalds 2005-04-16 675 if (!(msg->msg_flags & MSG_PROBE) || len)
^1da177e4c3f41 Linus Torvalds 2005-04-16 676 goto back_from_confirm;
^1da177e4c3f41 Linus Torvalds 2005-04-16 677 err = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16 678 goto done;
^1da177e4c3f41 Linus Torvalds 2005-04-16 679 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 680
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-08 9:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-08 4:44 [PATCH net-next 4/7] ipv4: remove get_rttos kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2025-02-06 19:34 [PATCH net-next 0/7] net: deduplicate cookie logic Willem de Bruijn
2025-02-06 19:34 ` [PATCH net-next 4/7] ipv4: remove get_rttos Willem de Bruijn
2025-02-07 0:59 ` Willem de Bruijn
2025-02-07 17:33 ` Willem de Bruijn
2025-02-08 9:24 ` kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.