xref: /openbsd/usr.sbin/dvmrpd/nbrs2.c (revision 35f7e862)
1 /*	$OpenBSD: nbrs2.c,v 1.5 2023/06/26 10:08:56 claudio 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
send_nbrs2(struct iface * iface,struct in_addr addr,void * data,int len)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 	int			 ret = 0;
41 
42 	log_debug("send_nbrs2: interface %s addr %s",
43 	    iface->name, inet_ntoa(addr));
44 
45 	if (iface->passive)
46 		return (0);
47 
48 	if ((buf = ibuf_open(iface->mtu - sizeof(struct ip))) == NULL)
49 		fatal("send_nbrs2");
50 
51 	/* DVMRP header */
52 	if (gen_dvmrp_hdr(buf, iface, DVMRP_CODE_GRAFT_ACK))
53 		goto fail;
54 
55 	dst.sin_family = AF_INET;
56 	dst.sin_len = sizeof(struct sockaddr_in);
57 	dst.sin_addr.s_addr = addr.s_addr;
58 
59 	ret = send_packet(iface, buf, &dst);
60 	ibuf_free(buf);
61 	return (ret);
62 fail:
63 	log_warn("send_nbrs2");
64 	ibuf_free(buf);
65 	return (-1);
66 }
67 
68 void
recv_nbrs2(struct nbr * nbr,char * buf,u_int16_t len)69 recv_nbrs2(struct nbr *nbr, char *buf, u_int16_t len)
70 {
71 	log_debug("recv_nbrs2: neighbor ID %s", inet_ntoa(nbr->id));
72 
73 	return;
74 }
75