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.
6 * DECnet Raw Sockets Interface
8 * Author: Steve Whitehouse <SteveW@ACM.org>
12 * Steve Whitehouse - connect() function.
13 * Steve Whitehouse - SMP changes, removed MOP stubs. MOP will
17 #include <linux/config.h>
18 #include <linux/net.h>
19 #include <linux/skbuff.h>
20 #include <linux/netdevice.h>
21 #include <linux/socket.h>
22 #include <linux/sockios.h>
26 #include <net/dn_raw.h>
27 #include <net/dn_route.h>
29 static rwlock_t dn_raw_hash_lock
= RW_LOCK_UNLOCKED
;
30 static struct sock
*dn_raw_nsp_sklist
= NULL
;
31 static struct sock
*dn_raw_routing_sklist
= NULL
;
33 static void dn_raw_hash(struct sock
*sk
)
37 switch(sk
->protocol
) {
39 skp
= &dn_raw_nsp_sklist
;
42 skp
= &dn_raw_routing_sklist
;
45 printk(KERN_DEBUG
"dn_raw_hash: Unknown protocol\n");
49 write_lock_bh(&dn_raw_hash_lock
);
53 write_unlock_bh(&dn_raw_hash_lock
);
56 static void dn_raw_unhash(struct sock
*sk
)
58 struct sock
**skp
= sk
->pprev
;
63 write_lock_bh(&dn_raw_hash_lock
);
65 skp
= &((*skp
)->next
);
67 write_unlock_bh(&dn_raw_hash_lock
);
73 static void dn_raw_autobind(struct sock
*sk
)
79 static int dn_raw_release(struct socket
*sock
)
81 struct sock
*sk
= sock
->sk
;
86 if (!sk
->dead
) sk
->state_change(sk
);
99 * Bind does odd things with raw sockets. Its basically used to filter
100 * the incoming packets, but this differs with the different layers
101 * at which you extract packets.
103 * For Routing layer sockets, the object name is a host ordered unsigned
104 * short which is a mask for the 16 different types of possible routing
105 * packet. I'd like to also select by destination address of the packets
106 * but alas, this is rather too difficult to do at the moment.
108 static int dn_raw_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
110 struct sock
*sk
= sock
->sk
;
111 struct sockaddr_dn
*addr
= (struct sockaddr_dn
*)uaddr
;
113 if (addr_len
!= sizeof(struct sockaddr_dn
))
119 switch(sk
->protocol
) {
121 if (dn_ntohs(addr
->sdn_objnamel
) && (dn_ntohs(addr
->sdn_objnamel
) != 2))
123 /* Fall through here */
125 if (dn_ntohs(addr
->sdn_add
.a_len
) && (dn_ntohs(addr
->sdn_add
.a_len
) != 2))
129 return -EPROTONOSUPPORT
;
132 if (dn_ntohs(addr
->sdn_objnamel
) > (DN_MAXOBJL
-1))
135 if (dn_ntohs(addr
->sdn_add
.a_len
) > DN_MAXADDL
)
138 memcpy(&sk
->protinfo
.dn
.addr
, addr
, sizeof(struct sockaddr_dn
));
146 * This is to allow send() and write() to work. You set the destination address
147 * with this function.
149 static int dn_raw_connect(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
, int flags
)
151 struct sock
*sk
= sock
->sk
;
152 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
153 struct sockaddr_dn
*saddr
= (struct sockaddr_dn
*)uaddr
;
159 if (addr_len
!= sizeof(struct sockaddr_dn
))
162 if (saddr
->sdn_family
!= AF_DECnet
)
165 if (dn_ntohs(saddr
->sdn_objnamel
) > (DN_MAXOBJL
-1))
168 if (dn_ntohs(saddr
->sdn_add
.a_len
) > DN_MAXADDL
)
174 if ((err
= dn_route_output(&sk
->dst_cache
, dn_saddr2dn(saddr
), dn_saddr2dn(&scp
->addr
), 0)) < 0)
177 memcpy(&scp
->peer
, saddr
, sizeof(struct sockaddr_dn
));
187 static int dn_raw_sendmsg(struct socket
*sock
, struct msghdr
*hdr
, int size
,
188 struct scm_cookie
*scm
)
190 struct sock
*sk
= sock
->sk
;
195 if (sk
->protocol
!= DNPROTO_NSP
)
202 * This works fine, execpt that it doesn't report the originating address
203 * or anything at the moment.
205 static int dn_raw_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
206 int flags
, struct scm_cookie
*scm
)
208 struct sock
*sk
= sock
->sk
;
218 if ((skb
= skb_recv_datagram(sk
, flags
& ~MSG_DONTWAIT
, flags
& MSG_DONTWAIT
, &err
)) == NULL
)
225 msg
->msg_flags
|= MSG_TRUNC
;
228 if ((err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
)) != 0) {
229 if (flags
& MSG_PEEK
)
230 atomic_dec(&skb
->users
);
232 skb_queue_head(&sk
->receive_queue
, skb
);
237 skb_free_datagram(sk
, skb
);
242 return copied
? copied
: err
;
245 struct proto_ops dn_raw_proto_ops
= {
266 #ifdef CONFIG_PROC_FS
267 int dn_raw_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
274 read_lock_bh(&dn_raw_hash_lock
);
275 for(sk
= dn_raw_nsp_sklist
; sk
; sk
= sk
->next
) {
276 len
+= sprintf(buffer
+len
, "NSP\n");
285 if (pos
> offset
+ length
)
290 for(sk
= dn_raw_routing_sklist
; sk
; sk
= sk
->next
) {
291 len
+= sprintf(buffer
+len
, "ROU\n");
300 if (pos
> offset
+ length
)
305 read_unlock_bh(&dn_raw_hash_lock
);
307 *start
= buffer
+ (offset
- begin
);
308 len
-= (offset
- begin
);
310 if (len
> length
) len
= length
;
314 #endif /* CONFIG_PROC_FS */
316 void dn_raw_rx_nsp(struct sk_buff
*skb
)
319 struct sk_buff
*skb2
;
321 read_lock(&dn_raw_hash_lock
);
322 for(sk
= dn_raw_nsp_sklist
; sk
!= NULL
; sk
= sk
->next
) {
323 if (skb
->len
> sock_rspace(sk
))
327 if ((skb2
= skb_clone(skb
, GFP_ATOMIC
)) != NULL
) {
328 skb_set_owner_r(skb2
, sk
);
329 skb_queue_tail(&sk
->receive_queue
, skb2
);
330 sk
->data_ready(sk
, skb
->len
);
333 read_unlock(&dn_raw_hash_lock
);
336 void dn_raw_rx_routing(struct sk_buff
*skb
)
339 struct sk_buff
*skb2
;
340 struct dn_skb_cb
*cb
= (struct dn_skb_cb
*)skb
->cb
;
341 unsigned short rt_flagmask
;
342 unsigned short objnamel
;
345 read_lock(&dn_raw_hash_lock
);
346 for(sk
= dn_raw_routing_sklist
; sk
!= NULL
; sk
= sk
->next
) {
347 if (skb
->len
> sock_rspace(sk
))
351 scp
= &sk
->protinfo
.dn
;
353 rt_flagmask
= dn_ntohs(*(unsigned short *)scp
->addr
.sdn_objname
);
354 objnamel
= dn_ntohs(scp
->addr
.sdn_objnamel
);
356 if ((objnamel
== 2) && (!((1 << (cb
->rt_flags
& 0x0f)) & rt_flagmask
)))
359 if ((skb2
= skb_clone(skb
, GFP_ATOMIC
)) != NULL
) {
360 skb_set_owner_r(skb2
, sk
);
361 skb_queue_tail(&sk
->receive_queue
, skb2
);
362 sk
->data_ready(sk
, skb
->len
);
365 read_unlock(&dn_raw_hash_lock
);