Skip to content

Commit 76839e2

Browse files
juntongdengkuba-moo
authored andcommitted
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: Juntong Deng <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: Jason Xing <[email protected]> Link: https://lore.kernel.org/r/AM6PR03MB58487A9704FD150CF76F542899272@AM6PR03MB5848.eurprd03.prod.outlook.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8b6d307 commit 76839e2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

net/packet/af_packet.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
23182318
}
23192319
if (po->tp_version <= TPACKET_V2) {
23202320
if (macoff + snaplen > po->rx_ring.frame_size) {
2321-
if (po->copy_thresh &&
2321+
if (READ_ONCE(po->copy_thresh) &&
23222322
atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf) {
23232323
if (skb_shared(skb)) {
23242324
copy_skb = skb_clone(skb, GFP_ATOMIC);
@@ -3836,7 +3836,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,
38363836
if (copy_from_sockptr(&val, optval, sizeof(val)))
38373837
return -EFAULT;
38383838

3839-
pkt_sk(sk)->copy_thresh = val;
3839+
WRITE_ONCE(pkt_sk(sk)->copy_thresh, val);
38403840
return 0;
38413841
}
38423842
case PACKET_VERSION:
@@ -4090,6 +4090,9 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
40904090
case PACKET_VNET_HDR_SZ:
40914091
val = READ_ONCE(po->vnet_hdr_sz);
40924092
break;
4093+
case PACKET_COPY_THRESH:
4094+
val = READ_ONCE(pkt_sk(sk)->copy_thresh);
4095+
break;
40934096
case PACKET_VERSION:
40944097
val = po->tp_version;
40954098
break;

net/packet/diag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb)
1717
pinfo.pdi_index = po->ifindex;
1818
pinfo.pdi_version = po->tp_version;
1919
pinfo.pdi_reserve = po->tp_reserve;
20-
pinfo.pdi_copy_thresh = po->copy_thresh;
20+
pinfo.pdi_copy_thresh = READ_ONCE(po->copy_thresh);
2121
pinfo.pdi_tstamp = READ_ONCE(po->tp_tstamp);
2222

2323
pinfo.pdi_flags = 0;

0 commit comments

Comments
 (0)