Skip to content

Commit

Permalink
Bluetooth: Add bt_skb_sendmmsg helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Luiz Augusto von Dentz authored and Marcel Holtmann committed Sep 13, 2021
1 parent 38f64f6 commit 97e4e80
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions include/net/bluetooth/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 97e4e80

Please sign in to comment.