xref: /openbsd/usr.sbin/dvmrpd/nbrs2.c (revision 09467b48)
1 /*	$OpenBSD: nbrs2.c,v 1.4 2015/05/05 01:26:37 jsg 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/ip.h>
23 #include <arpa/inet.h>
24 
25 #include <stdlib.h>
26 #include <strings.h>
27 
28 #include "igmp.h"
29 #include "dvmrpd.h"
30 #include "dvmrp.h"
31 #include "log.h"
32 #include "dvmrpe.h"
33 
34 /* DVMRP neighbors2 packet handling */
35 int
36 send_nbrs2(struct iface *iface, struct in_addr addr, void *data, int len)
37 {
38 	struct sockaddr_in	 dst;
39 	struct ibuf		*buf;
40 	struct dvmrp_hdr	*dvmrp_hdr;
41 	int			 ret = 0;
42 
43 	log_debug("send_nbrs2: interface %s addr %s",
44 	    iface->name, inet_ntoa(addr));
45 
46 	if (iface->passive)
47 		return (0);
48 
49 	if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL)
50 		fatal("send_nbrs2");
51 
52 	/* DVMRP header */
53 	if (gen_dvmrp_hdr(buf, iface, DVMRP_CODE_GRAFT_ACK))
54 		goto fail;
55 
56 	dst.sin_family = AF_INET;
57 	dst.sin_len = sizeof(struct sockaddr_in);
58 	dst.sin_addr.s_addr = addr.s_addr;
59 
60 	/* update chksum */
61 	dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
62 	dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
63 
64 	ret = send_packet(iface, buf->buf, buf->wpos, &dst);
65 	ibuf_free(buf);
66 	return (ret);
67 fail:
68 	log_warn("send_nbrs2");
69 	ibuf_free(buf);
70 	return (-1);
71 }
72 
73 void
74 recv_nbrs2(struct nbr *nbr, char *buf, u_int16_t len)
75 {
76 	log_debug("recv_nbrs2: neighbor ID %s", inet_ntoa(nbr->id));
77 
78 	return;
79 }
80