~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/decnet/netfilter/dn_rtmsg.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * DECnet       An implementation of the DECnet protocol suite for the LINUX
  3  *              operating system.  DECnet is implemented using the  BSD Socket
  4  *              interface as the means of communication with the user level.
  5  *
  6  *              DECnet Routing Message Grabulator
  7  *
  8  *              (C) 2000 ChyGwyn Limited  -  http://www.chygwyn.com/
  9  *              This code may be copied under the GPL v.2 or at your option
 10  *              any later version.
 11  *
 12  * Author:      Steven Whitehouse <steve@chygwyn.com>
 13  *
 14  */
 15 #include <linux/module.h>
 16 #include <linux/skbuff.h>
 17 #include <linux/slab.h>
 18 #include <linux/init.h>
 19 #include <linux/netdevice.h>
 20 #include <linux/netfilter.h>
 21 #include <linux/spinlock.h>
 22 #include <net/netlink.h>
 23 #include <linux/netfilter_decnet.h>
 24 
 25 #include <net/sock.h>
 26 #include <net/flow.h>
 27 #include <net/dn.h>
 28 #include <net/dn_route.h>
 29 
 30 static struct sock *dnrmg = NULL;
 31 
 32 
 33 static struct sk_buff *dnrmg_build_message(struct sk_buff *rt_skb, int *errp)
 34 {
 35         struct sk_buff *skb = NULL;
 36         size_t size;
 37         sk_buff_data_t old_tail;
 38         struct nlmsghdr *nlh;
 39         unsigned char *ptr;
 40         struct nf_dn_rtmsg *rtm;
 41 
 42         size = NLMSG_ALIGN(rt_skb->len) +
 43                NLMSG_ALIGN(sizeof(struct nf_dn_rtmsg));
 44         skb = nlmsg_new(size, GFP_ATOMIC);
 45         if (!skb) {
 46                 *errp = -ENOMEM;
 47                 return NULL;
 48         }
 49         old_tail = skb->tail;
 50         nlh = nlmsg_put(skb, 0, 0, 0, size, 0);
 51         if (!nlh) {
 52                 kfree_skb(skb);
 53                 *errp = -ENOMEM;
 54                 return NULL;
 55         }
 56         rtm = (struct nf_dn_rtmsg *)nlmsg_data(nlh);
 57         rtm->nfdn_ifindex = rt_skb->dev->ifindex;
 58         ptr = NFDN_RTMSG(rtm);
 59         skb_copy_from_linear_data(rt_skb, ptr, rt_skb->len);
 60         nlh->nlmsg_len = skb->tail - old_tail;
 61         return skb;
 62 }
 63 
 64 static void dnrmg_send_peer(struct sk_buff *skb)
 65 {
 66         struct sk_buff *skb2;
 67         int status = 0;
 68         int group = 0;
 69         unsigned char flags = *skb->data;
 70 
 71         switch (flags & DN_RT_CNTL_MSK) {
 72         case DN_RT_PKT_L1RT:
 73                 group = DNRNG_NLGRP_L1;
 74                 break;
 75         case DN_RT_PKT_L2RT:
 76                 group = DNRNG_NLGRP_L2;
 77                 break;
 78         default:
 79                 return;
 80         }
 81 
 82         skb2 = dnrmg_build_message(skb, &status);
 83         if (skb2 == NULL)
 84                 return;
 85         NETLINK_CB(skb2).dst_group = group;
 86         netlink_broadcast(dnrmg, skb2, 0, group, GFP_ATOMIC);
 87 }
 88 
 89 
 90 static unsigned int dnrmg_hook(void *priv,
 91                         struct sk_buff *skb,
 92                         const struct nf_hook_state *state)
 93 {
 94         dnrmg_send_peer(skb);
 95         return NF_ACCEPT;
 96 }
 97 
 98 
 99 #define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err), NULL); return; } while (0)
100 
101 static inline void dnrmg_receive_user_skb(struct sk_buff *skb)
102 {
103         struct nlmsghdr *nlh = nlmsg_hdr(skb);
104 
105         if (skb->len < sizeof(*nlh) ||
106             nlh->nlmsg_len < sizeof(*nlh) ||
107             skb->len < nlh->nlmsg_len)
108                 return;
109 
110         if (!netlink_capable(skb, CAP_NET_ADMIN))
111                 RCV_SKB_FAIL(-EPERM);
112 
113         /* Eventually we might send routing messages too */
114 
115         RCV_SKB_FAIL(-EINVAL);
116 }
117 
118 static const struct nf_hook_ops dnrmg_ops = {
119         .hook           = dnrmg_hook,
120         .pf             = NFPROTO_DECNET,
121         .hooknum        = NF_DN_ROUTE,
122         .priority       = NF_DN_PRI_DNRTMSG,
123 };
124 
125 static int __init dn_rtmsg_init(void)
126 {
127         int rv = 0;
128         struct netlink_kernel_cfg cfg = {
129                 .groups = DNRNG_NLGRP_MAX,
130                 .input  = dnrmg_receive_user_skb,
131         };
132 
133         dnrmg = netlink_kernel_create(&init_net, NETLINK_DNRTMSG, &cfg);
134         if (dnrmg == NULL) {
135                 printk(KERN_ERR "dn_rtmsg: Cannot create netlink socket");
136                 return -ENOMEM;
137         }
138 
139         rv = nf_register_net_hook(&init_net, &dnrmg_ops);
140         if (rv) {
141                 netlink_kernel_release(dnrmg);
142         }
143 
144         return rv;
145 }
146 
147 static void __exit dn_rtmsg_fini(void)
148 {
149         nf_unregister_net_hook(&init_net, &dnrmg_ops);
150         netlink_kernel_release(dnrmg);
151 }
152 
153 
154 MODULE_DESCRIPTION("DECnet Routing Message Grabulator");
155 MODULE_AUTHOR("Steven Whitehouse <steve@chygwyn.com>");
156 MODULE_LICENSE("GPL");
157 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_DNRTMSG);
158 
159 module_init(dn_rtmsg_init);
160 module_exit(dn_rtmsg_fini);
161 
162 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp