--- zzzz-none-000/linux-5.15.111/net/packet/af_packet.c 2023-05-11 14:00:40.000000000 +0000 +++ puma7-arm-6670-761/linux-5.15.111/net/packet/af_packet.c 2024-02-07 09:28:10.000000000 +0000 @@ -46,6 +46,11 @@ * Copyright (C) 2011, */ +/* + * Includes Intel Corporation's changes/modifications dated: 2017. + * Changed/modified portions - Copyright (c) 2017, Intel Corporation. + */ + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include @@ -1909,6 +1914,41 @@ } /* +* Intel Extension: +* Pass information received in cmsg to the skb +*/ +#ifdef CONFIG_TI_AUXDATA_SOCKOPT +static int packet_cmsg_send(struct sk_buff *skb, struct msghdr *msg){ + struct cmsghdr *cmsg; + + for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { + if (!CMSG_OK(msg, cmsg)) + return -EINVAL; + if (cmsg->cmsg_level != SOL_PACKET) + continue; + switch (cmsg->cmsg_type) { + + case TI_AUXDATA: + { + struct ti_auxdata *ti_aux; + if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct ti_auxdata))) + return -EINVAL; + ti_aux = (struct ti_auxdata *)CMSG_DATA(cmsg); + /* Now copy supported TI auxilliary data to skb */ +#ifdef CONFIG_TI_META_DATA + skb->ti_meta_info = ti_aux->ti_meta_info; + skb->ti_meta_info2 = ti_aux->ti_meta_info2; +#endif + break; + } + } + } + + return 0; +} +#endif + +/* * Output a raw packet to a device layer. This bypasses all the other * protocol layers and you must therefore supply it with a complete frame */ @@ -2022,6 +2062,13 @@ skb->mark = sk->sk_mark; skb->tstamp = sockc.transmit_time; +#ifdef CONFIG_TI_AUXDATA_SOCKOPT + if (pkt_sk(sk)->ti_auxdata) { + if((err = packet_cmsg_send(skb, msg))){ + goto out_unlock; + } + } +#endif skb_setup_tx_timestamp(skb, sockc.tsflags); if (unlikely(extra_len == 4)) @@ -2828,6 +2875,14 @@ __packet_set_status(po, ph, TP_STATUS_SENDING); packet_inc_pending(&po->tx_ring); +#ifdef CONFIG_TI_AUXDATA_SOCKOPT + if (po->ti_auxdata) { + if ((err = packet_cmsg_send(skb, msg))) { + goto out_status; + } + } +#endif + status = TP_STATUS_SEND_REQUEST; /* Paired with WRITE_ONCE() in packet_setsockopt() */ err = READ_ONCE(po->xmit)(skb); @@ -3033,6 +3088,14 @@ virtio_net_hdr_set_proto(skb, &vnet_hdr); } +#ifdef CONFIG_TI_AUXDATA_SOCKOPT + if (po->ti_auxdata) { + if ((err = packet_cmsg_send(skb, msg))) { + goto out_unlock; + } + } +#endif + /* Paired with WRITE_ONCE() in packet_setsockopt() */ err = READ_ONCE(po->xmit)(skb); if (unlikely(err != 0)) { @@ -3510,6 +3573,21 @@ put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux); } +/* +* TI extension - Copy TI metadata and other desired layer 2 info +* into a cmsg that userspace can read +*/ +#ifdef CONFIG_TI_AUXDATA_SOCKOPT + if (pkt_sk(sk)->ti_auxdata) { + struct ti_auxdata ti_aux; +#ifdef CONFIG_TI_META_DATA + ti_aux.ti_meta_info = skb->ti_meta_info; + ti_aux.ti_meta_info2 = skb->ti_meta_info2; +#endif + put_cmsg(msg, SOL_PACKET, TI_AUXDATA, sizeof(ti_aux), &ti_aux); + } +#endif + /* * Free or return the buffer as appropriate. Again this * hides all the races and re-entrancy issues from us. @@ -3872,6 +3950,20 @@ packet_sock_flag_set(po, PACKET_SOCK_AUXDATA, val); return 0; } +#ifdef CONFIG_TI_AUXDATA_SOCKOPT + case TI_AUXDATA: + { + int val; + + if (optlen < sizeof(val)) + return -EINVAL; + if (copy_from_sockptr(&val, optval, sizeof(val))) + return -EFAULT; + + po->ti_auxdata = !!val; + return 0; + } +#endif case PACKET_ORIGDEV: { int val; @@ -4029,6 +4121,11 @@ case PACKET_AUXDATA: val = packet_sock_flag(po, PACKET_SOCK_AUXDATA); break; +#ifdef CONFIG_TI_AUXDATA_SOCKOPT + case TI_AUXDATA: + val = po->ti_auxdata; + break; +#endif case PACKET_ORIGDEV: val = packet_sock_flag(po, PACKET_SOCK_ORIGDEV); break;