History

net: use sk_is_tcp() in more places

Move sk_is_tcp() to include/net/sock.h and use it where we can.

Eric Dumazet committed 5 years ago

Commit 42f67ee1 parent 37354404 files · +9 −14Browse files

Unified · Split

4 files
  1. include/linux/skmsg.h +0 −6
  2. include/net/sock.h +5 −0
  3. net/core/skbuff.c +2 −4
  4. net/core/sock.c +2 −4
include/linux/skmsg.h+0−6
@@ -507,12 +507,6 @@ static inline bool sk_psock_strp_enabled(struct sk_psock *psock) · 506 unmodified lines
507507 return !!psock->saved_data_ready;
508508 }
509509
510−static inline bool sk_is_tcp(const struct sock *sk)
511−{
512− return sk->sk_type == SOCK_STREAM &&
513− sk->sk_protocol == IPPROTO_TCP;
514−}
515−
516510 static inline bool sk_is_udp(const struct sock *sk)
517511 {
518512 return sk->sk_type == SOCK_DGRAM &&
include/net/sock.h+5−0
@@ -2638,6 +2638,11 @@ static inline void skb_setup_tx_timestamp(struct sk_buff *skb, __u16 tsflags) · 2637 unmodified lines
26382638 &skb_shinfo(skb)->tskey);
26392639 }
26402640
2641+static inline bool sk_is_tcp(const struct sock *sk)
2642+{
2643+ return sk->sk_type == SOCK_STREAM && sk->sk_protocol == IPPROTO_TCP;
2644+}
2645+
26412646 /**
26422647 * sk_eat_skb - Release a skb if it is no longer needed
26432648 * @sk: socket to eat this skb from
net/core/skbuff.c+2−4
@@ -4849,8 +4849,7 @@ static void __skb_complete_tx_timestamp(struct sk_buff *skb, · 4848 unmodified lines
48494849 serr->header.h4.iif = skb->dev ? skb->dev->ifindex : 0;
48504850 if (sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID) {
48514851 serr->ee.ee_data = skb_shinfo(skb)->tskey;
4852− if (sk->sk_protocol == IPPROTO_TCP &&
4853− sk->sk_type == SOCK_STREAM)
4852+ if (sk_is_tcp(sk))
48544853 serr->ee.ee_data -= sk->sk_tskey;
48554854 }
48564855
@@ -4919,8 +4918,7 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, · 62 unmodified lines
49194918 if (tsonly) {
49204919 #ifdef CONFIG_INET
49214920 if ((sk->sk_tsflags & SOF_TIMESTAMPING_OPT_STATS) &&
4922− sk->sk_protocol == IPPROTO_TCP &&
4923− sk->sk_type == SOCK_STREAM) {
4921+ sk_is_tcp(sk)) {
49244922 skb = tcp_get_timestamping_opt_stats(sk, orig_skb,
49254923 ack_skb);
49264924 opt_stats = true;
net/core/sock.c+2−4
@@ -872,8 +872,7 @@ int sock_set_timestamping(struct sock *sk, int optname, · 871 unmodified lines
872872
873873 if (val & SOF_TIMESTAMPING_OPT_ID &&
874874 !(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)) {
875− if (sk->sk_protocol == IPPROTO_TCP &&
876− sk->sk_type == SOCK_STREAM) {
875+ if (sk_is_tcp(sk)) {
877876 if ((1 << sk->sk_state) &
878877 (TCPF_CLOSE | TCPF_LISTEN))
879878 return -EINVAL;
@@ -1370,8 +1369,7 @@ set_sndbuf: · 490 unmodified lines
13701369
13711370 case SO_ZEROCOPY:
13721371 if (sk->sk_family == PF_INET || sk->sk_family == PF_INET6) {
1373− if (!((sk->sk_type == SOCK_STREAM &&
1374− sk->sk_protocol == IPPROTO_TCP) ||
1372+ if (!(sk_is_tcp(sk) ||
13751373 (sk->sk_type == SOCK_DGRAM &&
13761374 sk->sk_protocol == IPPROTO_UDP)))
13771375 ret = -ENOTSUPP;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t