ip: support SO_MARK cmsg
Enable setting skb->mark for UDP and RAW sockets using cmsg. This is analogous to existing support for TOS, TTL, txtime, etc. Packet sockets already support this as of commitc7d39e3263
("packet: support per-packet fwmark for af_packet sendmsg"). Similar to other fields, implement by 1. initialize the sockcm_cookie.mark from socket option sk_mark 2. optionally overwrite this in ip_cmsg_send/ip6_datagram_send_ctl 3. initialize inet_cork.mark from sockcm_cookie.mark 4. initialize each (usually just one) skb->mark from inet_cork.mark Step 1 is handled in one location for most protocols by ipcm_init_sk as of commit351782067b
("ipv4: ipcm_cookie initializers"). Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
823eb2a3c4
commit
c6af0c227a
@@ -1294,6 +1294,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
|
||||
cork->base.fragsize = mtu;
|
||||
cork->base.gso_size = ipc6->gso_size;
|
||||
cork->base.tx_flags = 0;
|
||||
cork->base.mark = ipc6->sockc.mark;
|
||||
sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags);
|
||||
|
||||
if (dst_allfrag(xfrm_dst_path(&rt->dst)))
|
||||
@@ -1764,7 +1765,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,
|
||||
hdr->daddr = *final_dst;
|
||||
|
||||
skb->priority = sk->sk_priority;
|
||||
skb->mark = sk->sk_mark;
|
||||
skb->mark = cork->base.mark;
|
||||
|
||||
skb->tstamp = cork->base.transmit_time;
|
||||
|
||||
|
@@ -646,7 +646,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
|
||||
|
||||
skb->protocol = htons(ETH_P_IPV6);
|
||||
skb->priority = sk->sk_priority;
|
||||
skb->mark = sk->sk_mark;
|
||||
skb->mark = sockc->mark;
|
||||
skb->tstamp = sockc->transmit_time;
|
||||
|
||||
skb_put(skb, length);
|
||||
@@ -810,6 +810,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
|
||||
ipcm6_init(&ipc6);
|
||||
ipc6.sockc.tsflags = sk->sk_tsflags;
|
||||
ipc6.sockc.mark = sk->sk_mark;
|
||||
|
||||
if (sin6) {
|
||||
if (addr_len < SIN6_LEN_RFC2133)
|
||||
@@ -891,6 +892,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
opt = ipv6_fixup_options(&opt_space, opt);
|
||||
|
||||
fl6.flowi6_proto = proto;
|
||||
fl6.flowi6_mark = ipc6.sockc.mark;
|
||||
|
||||
if (!hdrincl) {
|
||||
rfv.msg = msg;
|
||||
|
@@ -1230,6 +1230,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
||||
ipcm6_init(&ipc6);
|
||||
ipc6.gso_size = up->gso_size;
|
||||
ipc6.sockc.tsflags = sk->sk_tsflags;
|
||||
ipc6.sockc.mark = sk->sk_mark;
|
||||
|
||||
/* destination address check */
|
||||
if (sin6) {
|
||||
@@ -1352,7 +1353,7 @@ do_udp_sendmsg:
|
||||
if (!fl6.flowi6_oif)
|
||||
fl6.flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
|
||||
|
||||
fl6.flowi6_mark = sk->sk_mark;
|
||||
fl6.flowi6_mark = ipc6.sockc.mark;
|
||||
fl6.flowi6_uid = sk->sk_uid;
|
||||
|
||||
if (msg->msg_controllen) {
|
||||
|
Reference in New Issue
Block a user