42 #include <linux/module.h>
44 #include <linux/uio.h>
45 #include <linux/net.h>
46 #include <linux/slab.h>
47 #include <linux/netdevice.h>
48 #include <linux/socket.h>
49 #include <linux/if_arp.h>
57 #define CAN_RAW_VERSION CAN_VERSION
97 static inline unsigned int *raw_flags(
struct sk_buff *
skb)
100 sizeof(
unsigned int)));
103 return (
unsigned int *)(&((
struct sockaddr_can *)skb->cb)[1]);
113 struct sock *sk = (
struct sock *)data;
117 unsigned int *pflags;
145 memset(addr, 0,
sizeof(*addr));
150 pflags = raw_flags(skb);
167 for (i = 0; i <
count; i++) {
184 static int raw_enable_errfilter(
struct net_device *dev,
struct sock *sk,
196 static void raw_disable_filters(
struct net_device *dev,
struct sock *sk,
201 for (i = 0; i <
count; i++)
206 static inline void raw_disable_errfilter(
struct net_device *dev,
216 static inline void raw_disable_allfilters(
struct net_device *dev,
221 raw_disable_filters(dev, sk, ro->
filter, ro->
count);
222 raw_disable_errfilter(dev, sk, ro->
err_mask);
225 static int raw_enable_allfilters(
struct net_device *dev,
struct sock *sk)
230 err = raw_enable_filters(dev, sk, ro->
filter, ro->
count);
232 err = raw_enable_errfilter(dev, sk, ro->
err_mask);
234 raw_disable_filters(dev, sk, ro->
filter, ro->
count);
241 unsigned long msg,
void *data)
245 struct sock *sk = &ro->
sk;
247 if (!net_eq(dev_net(dev), &
init_net))
262 raw_disable_allfilters(dev, sk);
287 static int raw_init(
struct sock *sk)
306 ro->
notifier.notifier_call = raw_notifier;
315 struct sock *sk = sock->
sk;
334 raw_disable_allfilters(dev, sk);
338 raw_disable_allfilters(
NULL, sk);
360 struct sock *sk = sock->
sk;
364 int notify_enetdown = 0;
366 if (len <
sizeof(*addr))
393 err = raw_enable_allfilters(dev, sk);
399 err = raw_enable_allfilters(
NULL, sk);
410 raw_disable_allfilters(dev, sk);
414 raw_disable_allfilters(
NULL, sk);
423 if (notify_enetdown) {
432 static int raw_getname(
struct socket *sock,
struct sockaddr *uaddr,
436 struct sock *sk = sock->
sk;
442 memset(addr, 0,
sizeof(*addr));
446 *len =
sizeof(*addr);
451 static int raw_setsockopt(
struct socket *sock,
int level,
int optname,
452 char __user *optval,
unsigned int optlen)
454 struct sock *sk = sock->
sk;
478 return PTR_ERR(filter);
479 }
else if (count == 1) {
492 err = raw_enable_filters(dev, sk, &sfilter, 1);
494 err = raw_enable_filters(dev, sk, filter,
503 raw_disable_filters(dev, sk, ro->
filter, ro->
count);
528 if (optlen !=
sizeof(err_mask))
544 err = raw_enable_errfilter(dev, sk, err_mask);
550 raw_disable_errfilter(dev, sk, ro->
err_mask);
597 static int raw_getsockopt(
struct socket *sock,
int level,
int optname,
598 char __user *optval,
int __user *optlen)
600 struct sock *sk = sock->
sk;
638 if (len >
sizeof(
int))
644 if (len >
sizeof(
int))
650 if (len >
sizeof(
int))
669 struct sock *sk = sock->
sk;
734 static int raw_recvmsg(
struct kiocb *iocb,
struct socket *sock,
737 struct sock *sk = sock->
sk;
745 flags &= ~MSG_DONTWAIT;
772 sock_recv_ts_and_drops(msg, sk, skb);
787 static const struct proto_ops raw_ops = {
789 .release = raw_release,
794 .getname = raw_getname,
799 .setsockopt = raw_setsockopt,
800 .getsockopt = raw_getsockopt,
801 .sendmsg = raw_sendmsg,
802 .recvmsg = raw_recvmsg,
810 .obj_size =
sizeof(
struct raw_sock),
814 static const struct can_proto raw_can_proto = {
821 static __init int raw_module_init(
void)
834 static __exit void raw_module_exit(
void)