26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <asm/unaligned.h>
32 #include <linux/if_phonet.h>
33 #include <linux/phonet.h>
49 if (pp && !try_module_get(pp->
prot->owner))
58 module_put(pp->
prot->owner);
63 static int pn_socket_create(
struct net *
net,
struct socket *
sock,
int protocol,
88 pnp = phonet_proto_get(protocol);
90 request_module(
"net-pf-%d-proto-%d",
PF_PHONET, protocol) == 0)
91 pnp = phonet_proto_get(protocol);
115 sk->sk_prot->init(sk);
119 phonet_proto_put(pnp);
125 .create = pn_socket_create,
132 const void *
saddr,
unsigned int len)
141 *media = *(
const u8 *)saddr;
145 static int pn_header_parse(
const struct sk_buff *skb,
unsigned char *haddr)
147 const u8 *media = skb_mac_header(skb);
153 .create = pn_header_create,
154 .parse = pn_header_parse,
167 if (skb->
len + 2 > 0xffff ||
179 skb_reset_transport_header(skb);
180 WARN_ON(skb_headroom(skb) & 1);
182 skb_reset_network_header(skb);
196 skb_reset_mac_header(skb);
217 static int pn_raw_send(
const void *
data,
int len,
struct net_device *dev,
229 skb_copy_to_linear_data(skb, data, len);
230 return pn_send(skb, dev, dst, src, res, 1);
240 struct net *net = sock_net(sk);
242 struct pn_sock *pn = pn_sk(sk);
248 if (target !=
NULL) {
249 dst = pn_sockaddr_get_object(target);
250 res = pn_sockaddr_get_resource(target);
255 daddr = pn_addr(dst);
258 if (sk->sk_bound_dev_if)
263 }
else if (dst == 0) {
283 src = pn_object(saddr, pn_obj(src));
285 err = pn_send(skb, dev, dst, src, res, 0);
298 static inline int can_respond(
struct sk_buff *skb)
304 if (!pskb_may_pull(skb, 3))
325 static int send_obj_unreachable(
struct sk_buff *rskb)
327 const struct phonethdr *oph = pn_hdr(rskb);
338 resp.pn_e_status = 0;
350 static int send_reset_indications(
struct sk_buff *rskb)
353 static const u8 data[4] = {
358 return pn_raw_send(data,
sizeof(data), rskb->
dev,
375 struct net *net = dev_net(dev);
381 if (!pskb_pull(skb,
sizeof(
struct phonethdr)))
386 len = get_unaligned_be16(&ph->
pn_length);
390 if ((len > skb->
len) || pskb_trim(skb, len))
392 skb_reset_transport_header(skb);
394 pn_skb_get_dst_sockaddr(skb, &
sa);
403 if (pn_sockaddr_get_object(&
sa) == 0) {
417 if (can_respond(skb)) {
418 send_obj_unreachable(skb);
419 send_reset_indications(skb);
430 pn_sockaddr_get_addr(&
sa));
434 __skb_push(skb,
sizeof(
struct phonethdr));
436 if (out_dev == dev) {
438 pn_sockaddr_get_addr(&
sa), dev->
name);
480 if (proto_tab[protocol])
493 BUG_ON(proto_tab[protocol] != pp);
502 static int __init phonet_init(
void)
514 "phonet protocol family initialization failed\n");
535 static void __exit phonet_exit(
void)