summaryrefslogtreecommitdiff
path: root/usr.sbin/eigrpd/hello.c
blob: c422cdfe21ff06dba3cb1af186a407961ae43287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*	$OpenBSD: hello.c,v 1.2 2015/10/05 01:59:33 renato Exp $ */

/*
 * Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <string.h>
#include <arpa/inet.h>

#include "eigrpd.h"
#include "eigrp.h"
#include "log.h"
#include "eigrpe.h"

/* hello packet handling */

void
send_hello(struct eigrp_iface *ei, struct seq_addr_head *seq_addr_list,
    uint32_t mcast_seq, int peerterm)
{
	struct eigrp		*eigrp = ei->eigrp;
	struct ibuf		*buf;
	uint8_t			 flags = 0;

	if ((buf = ibuf_dynamic(PKG_DEF_SIZE,
	    IP_MAXPACKET - sizeof(struct ip))) == NULL)
		fatal("send_hello");

	/* EIGRP header */
	if (gen_eigrp_hdr(buf, EIGRP_OPC_HELLO, flags, 0, eigrp->as))
		goto fail;

	if (gen_parameter_tlv(buf, ei, peerterm))
		goto fail;

	if (gen_sw_version_tlv(buf))
		goto fail;

	if (seq_addr_list && !TAILQ_EMPTY(seq_addr_list) &&
	    gen_sequence_tlv(buf, seq_addr_list))
		goto fail;

	if (mcast_seq && gen_mcast_seq_tlv(buf, mcast_seq))
		goto fail;

	/* send unreliably */
	send_packet(ei, NULL, 0, buf);
	ibuf_free(buf);
	return;
fail:
	log_warnx("%s: failed to send message", __func__);
	ibuf_free(buf);
}

void
recv_hello(struct eigrp_iface *ei, union eigrpd_addr *src, struct nbr *nbr,
    struct tlv_parameter *tp)
{
	/*
	 * Some old Cisco routers seems to use the "parameters tlv" with all
	 * K-values set to 255 (except k6) to inform that the neighbor has been
	 * reset. The "peer termination" tlv described in the draft for the same
	 * purpose is probably something introduced recently. Let's check for
	 * this case to maintain backward compatibility.
	 */
	if (tp->kvalues[0] == 255 && tp->kvalues[1] == 255 &&
	    tp->kvalues[2] == 255 && tp->kvalues[3] == 255 &&
	    tp->kvalues[4] == 255 && tp->kvalues[5] == 0) {
		if (nbr) {
			log_debug("%s: peer temination", __func__);
			nbr_del(nbr);
		}
		return;
	}

	if (nbr == NULL) {
		if (memcmp(ei->eigrp->kvalues, tp->kvalues, 6) != 0) {
			log_debug("%s: k-values don't match (nbr %s)",
			    __func__, log_addr(ei->eigrp->af, src));
			return;
		}

		nbr = nbr_new(ei, src, ntohs(tp->holdtime), 0);

		/* send an expedited hello */
		send_hello(ei, NULL, 0, 0);

		send_update(nbr->ei, nbr, EIGRP_HDR_FLAG_INIT, 0, NULL);
	}
}