Commit 76839e2f authored by Juntong Deng's avatar Juntong Deng Committed by Jakub Kicinski

net/packet: Add getsockopt support for PACKET_COPY_THRESH

Currently getsockopt does not support PACKET_COPY_THRESH,
and we are unable to get the value of PACKET_COPY_THRESH
socket option through getsockopt.

This patch adds getsockopt support for PACKET_COPY_THRESH.

In addition, this patch converts access to copy_thresh to
READ_ONCE/WRITE_ONCE.
Signed-off-by: default avatarJuntong Deng <juntong.deng@outlook.com>
Reviewed-by: default avatarWillem de Bruijn <willemb@google.com>
Reviewed-by: default avatarJason Xing <kerneljasonxing@gmail.com>
Link: https://lore.kernel.org/r/AM6PR03MB58487A9704FD150CF76F542899272@AM6PR03MB5848.eurprd03.prod.outlook.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8b6d307f
...@@ -2318,7 +2318,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -2318,7 +2318,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
} }
if (po->tp_version <= TPACKET_V2) { if (po->tp_version <= TPACKET_V2) {
if (macoff + snaplen > po->rx_ring.frame_size) { if (macoff + snaplen > po->rx_ring.frame_size) {
if (po->copy_thresh && if (READ_ONCE(po->copy_thresh) &&
atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf) { atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf) {
if (skb_shared(skb)) { if (skb_shared(skb)) {
copy_skb = skb_clone(skb, GFP_ATOMIC); copy_skb = skb_clone(skb, GFP_ATOMIC);
...@@ -3836,7 +3836,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval, ...@@ -3836,7 +3836,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,
if (copy_from_sockptr(&val, optval, sizeof(val))) if (copy_from_sockptr(&val, optval, sizeof(val)))
return -EFAULT; return -EFAULT;
pkt_sk(sk)->copy_thresh = val; WRITE_ONCE(pkt_sk(sk)->copy_thresh, val);
return 0; return 0;
} }
case PACKET_VERSION: case PACKET_VERSION:
...@@ -4090,6 +4090,9 @@ static int packet_getsockopt(struct socket *sock, int level, int optname, ...@@ -4090,6 +4090,9 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
case PACKET_VNET_HDR_SZ: case PACKET_VNET_HDR_SZ:
val = READ_ONCE(po->vnet_hdr_sz); val = READ_ONCE(po->vnet_hdr_sz);
break; break;
case PACKET_COPY_THRESH:
val = READ_ONCE(pkt_sk(sk)->copy_thresh);
break;
case PACKET_VERSION: case PACKET_VERSION:
val = po->tp_version; val = po->tp_version;
break; break;
......
...@@ -17,7 +17,7 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb) ...@@ -17,7 +17,7 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb)
pinfo.pdi_index = po->ifindex; pinfo.pdi_index = po->ifindex;
pinfo.pdi_version = po->tp_version; pinfo.pdi_version = po->tp_version;
pinfo.pdi_reserve = po->tp_reserve; pinfo.pdi_reserve = po->tp_reserve;
pinfo.pdi_copy_thresh = po->copy_thresh; pinfo.pdi_copy_thresh = READ_ONCE(po->copy_thresh);
pinfo.pdi_tstamp = READ_ONCE(po->tp_tstamp); pinfo.pdi_tstamp = READ_ONCE(po->tp_tstamp);
pinfo.pdi_flags = 0; pinfo.pdi_flags = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment