diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2021-09-04 01:27:30 +0300 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2021-09-13 22:53:23 +0300 |
commit | 97e4e80299844bb5f6ce5a7540742ffbffae3d97 (patch) | |
tree | c8e4fca71001ced996198a01222c4a75eac455b5 /include/net/bluetooth/bluetooth.h | |
parent | 38f64f650dc0e44c146ff88d15a7339efa325918 (diff) | |
download | linux-97e4e80299844bb5f6ce5a7540742ffbffae3d97.tar.xz |
Bluetooth: Add bt_skb_sendmmsg helper
This works similarly to bt_skb_sendmsg but can split the msg into
multiple skb fragments which is useful for stream sockets.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'include/net/bluetooth/bluetooth.h')
-rw-r--r-- | include/net/bluetooth/bluetooth.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 11020b12a6ed..aa221c1a27c6 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -472,6 +472,44 @@ static inline struct sk_buff *bt_skb_sendmsg(struct sock *sk, return skb; } +/* Similar to bt_skb_sendmsg but can split the msg into multiple fragments + * accourding to the MTU. + */ +static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk, + struct msghdr *msg, + size_t len, size_t mtu, + size_t headroom, size_t tailroom) +{ + struct sk_buff *skb, **frag; + + skb = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); + if (IS_ERR_OR_NULL(skb)) + return skb; + + len -= skb->len; + if (!len) + return skb; + + /* Add remaining data over MTU as continuation fragments */ + frag = &skb_shinfo(skb)->frag_list; + while (len) { + struct sk_buff *tmp; + + tmp = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom); + if (IS_ERR_OR_NULL(tmp)) { + kfree_skb(skb); + return tmp; + } + + len -= tmp->len; + + *frag = tmp; + frag = &(*frag)->next; + } + + return skb; +} + int bt_to_errno(u16 code); void hci_sock_set_flag(struct sock *sk, int nr); |