diff options
author | Remi Denis-Courmont <remi.denis-courmont@nokia.com> | 2008-09-22 23:09:13 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-09-22 23:09:13 -0400 |
commit | be0c52bfed7f7828494fa00060efd5d758e92580 (patch) | |
tree | 1261d101dee4c1d440d1d90c974c62339a556843 /net/phonet/af_phonet.c | |
parent | 87ab4e20b445c6d2d2727ab4f96fa17f7259511e (diff) |
Phonet: emit errors when a packet cannot be delivered locally
When there is no listener socket for a received packet, send an error
back to the sender.
Signed-off-by: Remi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/phonet/af_phonet.c')
-rw-r--r-- | net/phonet/af_phonet.c | 96 |
1 files changed, 92 insertions, 4 deletions
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c index 50dc258d5aa2..1d8df6b7e3df 100644 --- a/net/phonet/af_phonet.c +++ b/net/phonet/af_phonet.c | |||
@@ -132,7 +132,7 @@ EXPORT_SYMBOL(phonet_header_ops); | |||
132 | * Prepends an ISI header and sends a datagram. | 132 | * Prepends an ISI header and sends a datagram. |
133 | */ | 133 | */ |
134 | static int pn_send(struct sk_buff *skb, struct net_device *dev, | 134 | static int pn_send(struct sk_buff *skb, struct net_device *dev, |
135 | u16 dst, u16 src, u8 res) | 135 | u16 dst, u16 src, u8 res, u8 irq) |
136 | { | 136 | { |
137 | struct phonethdr *ph; | 137 | struct phonethdr *ph; |
138 | int err; | 138 | int err; |
@@ -163,7 +163,10 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev, | |||
163 | skb_reset_mac_header(skb); | 163 | skb_reset_mac_header(skb); |
164 | skb->pkt_type = PACKET_LOOPBACK; | 164 | skb->pkt_type = PACKET_LOOPBACK; |
165 | skb_orphan(skb); | 165 | skb_orphan(skb); |
166 | netif_rx_ni(skb); | 166 | if (irq) |
167 | netif_rx(skb); | ||
168 | else | ||
169 | netif_rx_ni(skb); | ||
167 | err = 0; | 170 | err = 0; |
168 | } else { | 171 | } else { |
169 | err = dev_hard_header(skb, dev, ntohs(skb->protocol), | 172 | err = dev_hard_header(skb, dev, ntohs(skb->protocol), |
@@ -181,6 +184,19 @@ drop: | |||
181 | return err; | 184 | return err; |
182 | } | 185 | } |
183 | 186 | ||
187 | static int pn_raw_send(const void *data, int len, struct net_device *dev, | ||
188 | u16 dst, u16 src, u8 res) | ||
189 | { | ||
190 | struct sk_buff *skb = alloc_skb(MAX_PHONET_HEADER + len, GFP_ATOMIC); | ||
191 | if (skb == NULL) | ||
192 | return -ENOMEM; | ||
193 | |||
194 | skb_reserve(skb, MAX_PHONET_HEADER); | ||
195 | __skb_put(skb, len); | ||
196 | skb_copy_to_linear_data(skb, data, len); | ||
197 | return pn_send(skb, dev, dst, src, res, 1); | ||
198 | } | ||
199 | |||
184 | /* | 200 | /* |
185 | * Create a Phonet header for the skb and send it out. Returns | 201 | * Create a Phonet header for the skb and send it out. Returns |
186 | * non-zero error code if failed. The skb is freed then. | 202 | * non-zero error code if failed. The skb is freed then. |
@@ -211,7 +227,7 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb, | |||
211 | src = pn_object(saddr, pn_obj(src)); | 227 | src = pn_object(saddr, pn_obj(src)); |
212 | 228 | ||
213 | err = pn_send(skb, dev, pn_sockaddr_get_object(target), | 229 | err = pn_send(skb, dev, pn_sockaddr_get_object(target), |
214 | src, pn_sockaddr_get_resource(target)); | 230 | src, pn_sockaddr_get_resource(target), 0); |
215 | dev_put(dev); | 231 | dev_put(dev); |
216 | return err; | 232 | return err; |
217 | 233 | ||
@@ -223,6 +239,73 @@ drop: | |||
223 | } | 239 | } |
224 | EXPORT_SYMBOL(pn_skb_send); | 240 | EXPORT_SYMBOL(pn_skb_send); |
225 | 241 | ||
242 | /* Do not send an error message in response to an error message */ | ||
243 | static inline int can_respond(struct sk_buff *skb) | ||
244 | { | ||
245 | const struct phonethdr *ph; | ||
246 | const struct phonetmsg *pm; | ||
247 | u8 submsg_id; | ||
248 | |||
249 | if (!pskb_may_pull(skb, 3)) | ||
250 | return 0; | ||
251 | |||
252 | ph = pn_hdr(skb); | ||
253 | if (phonet_address_get(skb->dev, ph->pn_rdev) != ph->pn_rdev) | ||
254 | return 0; /* we are not the destination */ | ||
255 | if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5)) | ||
256 | return 0; | ||
257 | |||
258 | ph = pn_hdr(skb); /* re-acquires the pointer */ | ||
259 | pm = pn_msg(skb); | ||
260 | if (pm->pn_msg_id != PN_COMMON_MESSAGE) | ||
261 | return 1; | ||
262 | submsg_id = (ph->pn_res == PN_PREFIX) | ||
263 | ? pm->pn_e_submsg_id : pm->pn_submsg_id; | ||
264 | if (submsg_id != PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP && | ||
265 | pm->pn_e_submsg_id != PN_COMM_SERVICE_NOT_IDENTIFIED_RESP) | ||
266 | return 1; | ||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | static int send_obj_unreachable(struct sk_buff *rskb) | ||
271 | { | ||
272 | const struct phonethdr *oph = pn_hdr(rskb); | ||
273 | const struct phonetmsg *opm = pn_msg(rskb); | ||
274 | struct phonetmsg resp; | ||
275 | |||
276 | memset(&resp, 0, sizeof(resp)); | ||
277 | resp.pn_trans_id = opm->pn_trans_id; | ||
278 | resp.pn_msg_id = PN_COMMON_MESSAGE; | ||
279 | if (oph->pn_res == PN_PREFIX) { | ||
280 | resp.pn_e_res_id = opm->pn_e_res_id; | ||
281 | resp.pn_e_submsg_id = PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP; | ||
282 | resp.pn_e_orig_msg_id = opm->pn_msg_id; | ||
283 | resp.pn_e_status = 0; | ||
284 | } else { | ||
285 | resp.pn_submsg_id = PN_COMM_ISA_ENTITY_NOT_REACHABLE_RESP; | ||
286 | resp.pn_orig_msg_id = opm->pn_msg_id; | ||
287 | resp.pn_status = 0; | ||
288 | } | ||
289 | return pn_raw_send(&resp, sizeof(resp), rskb->dev, | ||
290 | pn_object(oph->pn_sdev, oph->pn_sobj), | ||
291 | pn_object(oph->pn_rdev, oph->pn_robj), | ||
292 | oph->pn_res); | ||
293 | } | ||
294 | |||
295 | static int send_reset_indications(struct sk_buff *rskb) | ||
296 | { | ||
297 | struct phonethdr *oph = pn_hdr(rskb); | ||
298 | static const u8 data[4] = { | ||
299 | 0x00 /* trans ID */, 0x10 /* subscribe msg */, | ||
300 | 0x00 /* subscription count */, 0x00 /* dummy */ | ||
301 | }; | ||
302 | |||
303 | return pn_raw_send(data, sizeof(data), rskb->dev, | ||
304 | pn_object(oph->pn_sdev, 0x00), | ||
305 | pn_object(oph->pn_rdev, oph->pn_robj), 0x10); | ||
306 | } | ||
307 | |||
308 | |||
226 | /* packet type functions */ | 309 | /* packet type functions */ |
227 | 310 | ||
228 | /* | 311 | /* |
@@ -260,8 +343,13 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev, | |||
260 | goto out; /* currently, we cannot be device 0 */ | 343 | goto out; /* currently, we cannot be device 0 */ |
261 | 344 | ||
262 | sk = pn_find_sock_by_sa(&sa); | 345 | sk = pn_find_sock_by_sa(&sa); |
263 | if (sk == NULL) | 346 | if (sk == NULL) { |
347 | if (can_respond(skb)) { | ||
348 | send_obj_unreachable(skb); | ||
349 | send_reset_indications(skb); | ||
350 | } | ||
264 | goto out; | 351 | goto out; |
352 | } | ||
265 | 353 | ||
266 | /* Push data to the socket (or other sockets connected to it). */ | 354 | /* Push data to the socket (or other sockets connected to it). */ |
267 | return sk_receive_skb(sk, skb, 0); | 355 | return sk_receive_skb(sk, skb, 0); |