On 22.09.2010 16:53, Kurt Van Dijck wrote: > On Wed, Sep 22, 2010 at 04:16:50PM +0200, [email protected] wrote:
>>> For self-received messages, the originating socket (sk_buff->sk) is >>> set. I think it's only accessible in kernel. Using this would IMO >>> avoid adding code in difficult places, and limit such feature to >>> adding code in easy places. > More exactly, self-received messages originating from a socket have > this member set. It is possible from kernelspace to inject CAN messages > without any socket, but I guess that's beyond scope. But if we would use skb->sk to distinguish internal from external originated traffic, we need to make sure that internally generated traffic also sets skb->sk correctly. E.g. in bcm.c this is already done: http://lxr.linux.no/#linux+v2.6.35.5/net/can/bcm.c#L268 In raw.c this is done here: http://lxr.linux.no/#linux+v2.6.35.5/net/can/raw.c#L663 >> Hmm, the sk_buff->sk for the message is like motherland for the >> person? >> So the self-reception messages are the "fellow citizens" and the >> rest are foreigners? 8) > Put like that, self-reception messages have their passport (different > sockets in the system ~ different countries ...), and messages not > originating on the system, but received from outside, well, they're > alien, they come from somewhere undefined and have no passport :-) Very nice analogy :-) To stick on the code in candump.c the field msg.msg_flags could contain a bit MSG_DONTROUTE after recvmsg(), whenever the CAN frames are not routed inside the system. In raw.c this (untested) patch could set the flag according to an available sk reference. When we have an 'alien' from outside our system the bit would be set. So far MSG_DONTROUTE is only used in sendmsg() - if this tiny patch fits your needs we need to see, if it's ok for the netdev guys to use this flag in the receive path for CAN also. Best regards, Oliver diff --git a/net/can/raw.c b/net/can/raw.c index 7d77e67..3348c7e 100644 --- a/net/can/raw.c +++ b/net/can/raw.c @@ -694,6 +694,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock, else size = skb->len; + if (!skb->sk) + msg->msg_flags |= MSG_DONTROUTE; + err = memcpy_toiovec(msg->msg_iov, skb->data, size); if (err < 0) { skb_free_datagram(sk, skb); _______________________________________________ Socketcan-core mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-core
