diff options
author | Willem de Bruijn <willemb@google.com> | 2019-09-11 15:50:51 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-09-13 15:44:19 -0400 |
commit | c6af0c227a22bb6bb8ff72f043e0fb6d99fd6515 (patch) | |
tree | 12f4f3b38877b029a5342e2a8f63d8131dad9b27 /net/ipv6 | |
parent | 823eb2a3c4c7f1b3e749f0dddb70bf8b09a76a10 (diff) |
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 commit c7d39e32632e
("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 commit 351782067b6b ("ipv4: ipcm_cookie initializers").
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/ip6_output.c | 3 | ||||
-rw-r--r-- | net/ipv6/raw.c | 4 | ||||
-rw-r--r-- | net/ipv6/udp.c | 3 |
3 files changed, 7 insertions, 3 deletions
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 8e49fd62eea9..89a4c7c2e25d 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c | |||
@@ -1294,6 +1294,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, | |||
1294 | cork->base.fragsize = mtu; | 1294 | cork->base.fragsize = mtu; |
1295 | cork->base.gso_size = ipc6->gso_size; | 1295 | cork->base.gso_size = ipc6->gso_size; |
1296 | cork->base.tx_flags = 0; | 1296 | cork->base.tx_flags = 0; |
1297 | cork->base.mark = ipc6->sockc.mark; | ||
1297 | sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags); | 1298 | sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags); |
1298 | 1299 | ||
1299 | if (dst_allfrag(xfrm_dst_path(&rt->dst))) | 1300 | if (dst_allfrag(xfrm_dst_path(&rt->dst))) |
@@ -1764,7 +1765,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, | |||
1764 | hdr->daddr = *final_dst; | 1765 | hdr->daddr = *final_dst; |
1765 | 1766 | ||
1766 | skb->priority = sk->sk_priority; | 1767 | skb->priority = sk->sk_priority; |
1767 | skb->mark = sk->sk_mark; | 1768 | skb->mark = cork->base.mark; |
1768 | 1769 | ||
1769 | skb->tstamp = cork->base.transmit_time; | 1770 | skb->tstamp = cork->base.transmit_time; |
1770 | 1771 | ||
diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 8a6131991e38..6e1888ee4036 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c | |||
@@ -646,7 +646,7 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length, | |||
646 | 646 | ||
647 | skb->protocol = htons(ETH_P_IPV6); | 647 | skb->protocol = htons(ETH_P_IPV6); |
648 | skb->priority = sk->sk_priority; | 648 | skb->priority = sk->sk_priority; |
649 | skb->mark = sk->sk_mark; | 649 | skb->mark = sockc->mark; |
650 | skb->tstamp = sockc->transmit_time; | 650 | skb->tstamp = sockc->transmit_time; |
651 | 651 | ||
652 | skb_put(skb, length); | 652 | skb_put(skb, length); |
@@ -810,6 +810,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) | |||
810 | 810 | ||
811 | ipcm6_init(&ipc6); | 811 | ipcm6_init(&ipc6); |
812 | ipc6.sockc.tsflags = sk->sk_tsflags; | 812 | ipc6.sockc.tsflags = sk->sk_tsflags; |
813 | ipc6.sockc.mark = sk->sk_mark; | ||
813 | 814 | ||
814 | if (sin6) { | 815 | if (sin6) { |
815 | if (addr_len < SIN6_LEN_RFC2133) | 816 | if (addr_len < SIN6_LEN_RFC2133) |
@@ -891,6 +892,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) | |||
891 | opt = ipv6_fixup_options(&opt_space, opt); | 892 | opt = ipv6_fixup_options(&opt_space, opt); |
892 | 893 | ||
893 | fl6.flowi6_proto = proto; | 894 | fl6.flowi6_proto = proto; |
895 | fl6.flowi6_mark = ipc6.sockc.mark; | ||
894 | 896 | ||
895 | if (!hdrincl) { | 897 | if (!hdrincl) { |
896 | rfv.msg = msg; | 898 | rfv.msg = msg; |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 827fe7385078..2c8beb3896d1 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -1230,6 +1230,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) | |||
1230 | ipcm6_init(&ipc6); | 1230 | ipcm6_init(&ipc6); |
1231 | ipc6.gso_size = up->gso_size; | 1231 | ipc6.gso_size = up->gso_size; |
1232 | ipc6.sockc.tsflags = sk->sk_tsflags; | 1232 | ipc6.sockc.tsflags = sk->sk_tsflags; |
1233 | ipc6.sockc.mark = sk->sk_mark; | ||
1233 | 1234 | ||
1234 | /* destination address check */ | 1235 | /* destination address check */ |
1235 | if (sin6) { | 1236 | if (sin6) { |
@@ -1352,7 +1353,7 @@ do_udp_sendmsg: | |||
1352 | if (!fl6.flowi6_oif) | 1353 | if (!fl6.flowi6_oif) |
1353 | fl6.flowi6_oif = np->sticky_pktinfo.ipi6_ifindex; | 1354 | fl6.flowi6_oif = np->sticky_pktinfo.ipi6_ifindex; |
1354 | 1355 | ||
1355 | fl6.flowi6_mark = sk->sk_mark; | 1356 | fl6.flowi6_mark = ipc6.sockc.mark; |
1356 | fl6.flowi6_uid = sk->sk_uid; | 1357 | fl6.flowi6_uid = sk->sk_uid; |
1357 | 1358 | ||
1358 | if (msg->msg_controllen) { | 1359 | if (msg->msg_controllen) { |