xref: /openbsd/usr.sbin/dvmrpd/ask_nbrs2.c (revision 404b540a)
1 /*	$OpenBSD: ask_nbrs2.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */
2 
3 /*
4  * Copyright (c) 2006 Esben Norby <norby@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <netinet/in_systm.h>
23 #include <netinet/ip.h>
24 #include <arpa/inet.h>
25 
26 #include <stdlib.h>
27 #include <strings.h>
28 
29 #include "igmp.h"
30 #include "dvmrpd.h"
31 #include "dvmrp.h"
32 #include "log.h"
33 #include "dvmrpe.h"
34 
35 /* DVMRP ask neighbors2 packet handling */
36 int
37 send_ask_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len)
38 {
39 	struct sockaddr_in	 dst;
40 	struct buf		*buf;
41 	struct dvmrp_hdr	*dvmrp_hdr;
42 	int			 ret = 0;
43 
44 	log_debug("send_ask_nbrs2: interface %s addr %s",
45 	    iface->name, inet_ntoa(addr));
46 
47 	if (iface->passive)
48 		return (0);
49 
50 	if ((buf = buf_open(iface->mtu - sizeof(struct ip))) == NULL)
51 		fatal("send_ask_nbrs2");
52 
53 	/* DVMRP header */
54 	if (gen_dvmrp_hdr(buf, iface, DVMRP_CODE_GRAFT_ACK))
55 		goto fail;
56 
57 	dst.sin_family = AF_INET;
58 	dst.sin_len = sizeof(struct sockaddr_in);
59 	dst.sin_addr.s_addr = addr.s_addr;
60 
61 	/* update chksum */
62 	dvmrp_hdr = buf_seek(buf, 0, sizeof(dvmrp_hdr));
63 	dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
64 
65 	ret = send_packet(iface, buf->buf, buf->wpos, &dst);
66 	buf_free(buf);
67 	return (ret);
68 fail:
69 	log_warn("send_ask_nbrs2");
70 	buf_free(buf);
71 	return (-1);
72 }
73 
74 void
75 recv_ask_nbrs2(struct nbr *nbr, char *buf, u_int16_t len)
76 {
77 	log_debug("recv_ask_nbrs2: neighbor ID %s", inet_ntoa(nbr->id));
78 
79 	return;
80 }
81