Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 215438
b: refs/heads/master
c: 1e55659
h: refs/heads/master
v: v3
  • Loading branch information
Oliver Hartkopp authored and David S. Miller committed Oct 21, 2010
1 parent 7962573 commit 53dbb37
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 32a875adcdcf5f470bf967250cfd01722e23844f
refs/heads/master: 1e55659ce6ddb5247cee0b1f720d77a799902b85
12 changes: 12 additions & 0 deletions trunk/Documentation/networking/can.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This file contains
4.1.2 RAW socket option CAN_RAW_ERR_FILTER
4.1.3 RAW socket option CAN_RAW_LOOPBACK
4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
4.1.5 RAW socket returned message flags
4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
4.3 connected transport protocols (SOCK_SEQPACKET)
4.4 unconnected transport protocols (SOCK_DGRAM)
Expand Down Expand Up @@ -471,6 +472,17 @@ solution for a couple of reasons:
setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
&recv_own_msgs, sizeof(recv_own_msgs));

4.1.5 RAW socket returned message flags

When using recvmsg() call, the msg->msg_flags may contain following flags:

MSG_DONTROUTE: set when the received frame was created on the local host.

MSG_CONFIRM: set when the frame was sent via the socket it is received on.
This flag can be interpreted as a 'transmission confirmation' when the
CAN driver supports the echo of frames on driver level, see 3.2 and 6.2.
In order to receive such messages, CAN_RAW_RECV_OWN_MSGS must be set.

4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
4.3 connected transport protocols (SOCK_SEQPACKET)
4.4 unconnected transport protocols (SOCK_DGRAM)
Expand Down
33 changes: 30 additions & 3 deletions trunk/net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,39 @@ struct raw_sock {
can_err_mask_t err_mask;
};

/*
* Return pointer to store the extra msg flags for raw_recvmsg().
* We use the space of one unsigned int beyond the 'struct sockaddr_can'
* in skb->cb.
*/
static inline unsigned int *raw_flags(struct sk_buff *skb)
{
BUILD_BUG_ON(sizeof(skb->cb) <= (sizeof(struct sockaddr_can) +
sizeof(unsigned int)));

/* return pointer after struct sockaddr_can */
return (unsigned int *)(&((struct sockaddr_can *)skb->cb)[1]);
}

static inline struct raw_sock *raw_sk(const struct sock *sk)
{
return (struct raw_sock *)sk;
}

static void raw_rcv(struct sk_buff *skb, void *data)
static void raw_rcv(struct sk_buff *oskb, void *data)
{
struct sock *sk = (struct sock *)data;
struct raw_sock *ro = raw_sk(sk);
struct sockaddr_can *addr;
struct sk_buff *skb;
unsigned int *pflags;

/* check the received tx sock reference */
if (!ro->recv_own_msgs && skb->sk == sk)
if (!ro->recv_own_msgs && oskb->sk == sk)
return;

/* clone the given skb to be able to enqueue it into the rcv queue */
skb = skb_clone(skb, GFP_ATOMIC);
skb = skb_clone(oskb, GFP_ATOMIC);
if (!skb)
return;

Expand All @@ -123,6 +139,14 @@ static void raw_rcv(struct sk_buff *skb, void *data)
addr->can_family = AF_CAN;
addr->can_ifindex = skb->dev->ifindex;

/* add CAN specific message flags for raw_recvmsg() */
pflags = raw_flags(skb);
*pflags = 0;
if (oskb->sk)
*pflags |= MSG_DONTROUTE;
if (oskb->sk == sk)
*pflags |= MSG_CONFIRM;

if (sock_queue_rcv_skb(sk, skb) < 0)
kfree_skb(skb);
}
Expand Down Expand Up @@ -707,6 +731,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
}

/* assign the flags that have been recorded in raw_rcv() */
msg->msg_flags |= *(raw_flags(skb));

skb_free_datagram(sk, skb);

return size;
Expand Down

0 comments on commit 53dbb37

Please sign in to comment.