]> rtime.felk.cvut.cz Git - can-eth-gw.git/commitdiff
Merge branch 'master' of rtime.felk.cvut.cz:can-eth-gw
authorRadek Matejka <radek.matejka@gmail.com>
Tue, 11 Sep 2012 13:03:07 +0000 (15:03 +0200)
committerRadek Matejka <radek.matejka@gmail.com>
Tue, 11 Sep 2012 13:03:07 +0000 (15:03 +0200)
kernel/Makefile
kernel/canethgw.c

index 624d6d0b37c7ebbf5ec9aed61dee7a5bf50628d8..7fe1007bf4be6ed60b9cabec339be9a9e1a90145 100644 (file)
@@ -1,10 +1,18 @@
 obj-m += canethgw.o
 
-all: debug
-bench:
-       make -C ../distro/kernel-bench M=`pwd`
-debug:
-       make -C ../distro/kernel-debug M=`pwd`
+-include Makefile.local
+# /usr/src/linux/_build_qemu
+
+KERNEL_DIR ?= /lib/modules/`uname -r`/build
+
+all:
+       make -C $(KERNEL_DIR) M=`pwd`
+install:
+       make -C $(KERNEL_DIR) M=`pwd` modules_install
 clean:
-       make -C ../distro/kernel-debug M=`pwd` clean
+       make -C $(KERNEL_DIR) M=`pwd` clean
 
+bench:
+       $(MAKE) KERNEL_DIR=../distro/kernel-bench
+debug:
+       $(MAKE) KERNEL_DIR=../distro/kernel-debug
index 25190f7e85ac193d0afb0f81efd62fec12a9d26f..36c38be89f4e5e66db19c2b83345614c2736707a 100644 (file)
 
 MODULE_LICENSE("GPL");
 
-static int  cegw_udp_can(void *data);
+static int  cegw_udp2can(void *data);
 static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
-               struct in_addr ipaddr, u16 port);
-static int  cegw_can_udp(void *data);
+                         struct in_addr ipaddr, u16 port);
+static int  cegw_can2udp(void *data);
 static void cegw_can_send(struct socket *can_sock, struct can_frame *cf,
-               int ifindex);
+                         int ifindex);
 static int cegw_thread_start(void *data);
 static int cegw_thread_stop(void);
 
-enum __cegw_state
-{
+enum __cegw_state {
        CEGW_RUN,
        CEGW_STOP,
        CEGW_EXIT
 };
 
-struct cegw_rule
-{
+struct cegw_rule {
        int can_ifindex;
        struct in_addr eth_ip;
        unsigned short eth_port;
        struct hlist_node list;
 };
 
-struct cegw_setting
-{
+struct cegw_setting {
        struct in_addr eth_ip;
        unsigned short eth_port;
 };
 
+
 static int cegw_state = CEGW_STOP;
 static struct socket *can_sock = NULL, *udp_sock = NULL;
 static struct task_struct *eth_to_can = NULL, *can_to_eth = NULL;
@@ -64,7 +62,7 @@ static DEFINE_MUTEX(rule_can_eth_mutex);
 static DEFINE_MUTEX(cegw_mutex);
 
 static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
-               struct in_addr ipaddr, u16 port)
+                         struct in_addr ipaddr, u16 port)
 {
        struct msghdr mh;
        struct sockaddr_in addr;
@@ -83,6 +81,7 @@ static void cegw_udp_send(struct socket *udp_sock, struct can_frame *cf,
        vec.iov_base = cf;
        vec.iov_len = sizeof(*cf);
 
+       /* FIXME: Convert endianing of cf->can_id */
        kernel_sendmsg(udp_sock, &mh, &vec, 1, sizeof(*cf));
 }
 
@@ -109,11 +108,11 @@ static void cegw_can_send(struct socket* can_sock, struct can_frame* cf,
 }
 
 /**
- * cegw_udp_can - performs udp->can routing
+ * cegw_udp2can - performs udp->can routing
  *
  * This function is run as a thread.
  */
-static int cegw_udp_can(void *data)
+static int cegw_udp2can(void *data)
 {
        struct can_frame cf;
        struct kvec vec;
@@ -123,17 +122,9 @@ static int cegw_udp_can(void *data)
        int can_ifidx;
        int recv_size;
 
-       mh.msg_name = NULL;
-       mh.msg_namelen = 0;
-       mh.msg_iov = NULL;
-       mh.msg_iovlen = 0;
-       mh.msg_control = NULL;
-       mh.msg_controllen = 0;
-       mh.msg_flags = 0;
+       memset(&mh, 0, sizeof(mh));
 
-       while (1) {
-               if (cegw_state == CEGW_STOP)
-                       break;
+       while (cegw_state != CEGW_STOP) {
                vec.iov_base = &cf;
                vec.iov_len = sizeof(cf);
                recv_size = kernel_recvmsg(udp_sock, &mh, &vec, 1,
@@ -144,6 +135,7 @@ static int cegw_udp_can(void *data)
                else if (recv_size < 0)
                        return -1;
 
+               /* FIXME: Convert endianing of cf.can_id */
                mutex_lock(&rule_eth_can_mutex);
                hlist_for_each_entry(rule, pos, &rule_eth_can, list) {
                        can_ifidx = rule->can_ifindex;
@@ -157,9 +149,11 @@ static int cegw_udp_can(void *data)
 }
 
 /**
- * cegw_can_udp - performs can->udp routing
+ * cegw_can2udp - performs can->udp routing
+ *
+ * Runs as a thread.
  */
-static int cegw_can_udp(void* data)
+static int cegw_can2udp(void* data)
 {
        struct msghdr mh;
        struct kvec vec;
@@ -177,9 +171,7 @@ static int cegw_can_udp(void* data)
        mh.msg_controllen = 0;
        mh.msg_flags = 0;
 
-       while (1) {
-               if (cegw_state == CEGW_STOP)
-                       break;
+       while (cegw_state != CEGW_STOP) {
                vec.iov_base = &cf;
                vec.iov_len = sizeof(cf);
 
@@ -246,6 +238,7 @@ static int cegw_newroute(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
                        return -ENOMEM;
                set->eth_ip   = *(struct in_addr*)nla_data(tb[CEGW_ETH_IP]);
                set->eth_port = *(unsigned short*)nla_data(tb[CEGW_ETH_PORT]);
+               /* MS: It would be better to use workqueues here. */
                kthread_run(cegw_thread_start, set, "canethgw");
                break;
        case CEGW_RULE_ETH_CAN:
@@ -536,7 +529,7 @@ static int cegw_thread_start(void *data)
        /* start threads */
        cegw_state = CEGW_RUN;
 
-       eth_to_can = kthread_create(cegw_udp_can, NULL, "canethgw");
+       eth_to_can = kthread_create(cegw_udp2can, NULL, "canethgw");
        if (IS_ERR(eth_to_can)) {
                cegw_state = CEGW_STOP;
                sock_release(udp_sock);
@@ -546,7 +539,7 @@ static int cegw_thread_start(void *data)
        get_task_struct(eth_to_can);
        wake_up_process(eth_to_can);
 
-       can_to_eth = kthread_create(cegw_can_udp, NULL, "canethgw");
+       can_to_eth = kthread_create(cegw_can2udp, NULL, "canethgw");
        if (IS_ERR(can_to_eth)) {
                cegw_state = CEGW_STOP;
                kernel_sock_shutdown(udp_sock, SHUT_RDWR);