2 * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 /* RIPng support added by Vincent Jardin <vincent.jardin@6wind.com>
22 * Copyright (C) 2002 6WIND
34 #include "ripngd/ripngd.h"
35 #include "ripngd/ripng_nexthop.h"
37 DEFINE_MTYPE_STATIC(RIPNGD
, RIPNG_PEER
, "RIPng peer");
39 static struct ripng_peer
*ripng_peer_new(void)
41 return XCALLOC(MTYPE_RIPNG_PEER
, sizeof(struct ripng_peer
));
44 static void ripng_peer_free(struct ripng_peer
*peer
)
46 THREAD_OFF(peer
->t_timeout
);
47 XFREE(MTYPE_RIPNG_PEER
, peer
);
50 struct ripng_peer
*ripng_peer_lookup(struct ripng
*ripng
, struct in6_addr
*addr
)
52 struct ripng_peer
*peer
;
53 struct listnode
*node
, *nnode
;
55 for (ALL_LIST_ELEMENTS(ripng
->peer_list
, node
, nnode
, peer
)) {
56 if (IPV6_ADDR_SAME(&peer
->addr
, addr
))
62 struct ripng_peer
*ripng_peer_lookup_next(struct ripng
*ripng
,
63 struct in6_addr
*addr
)
65 struct ripng_peer
*peer
;
66 struct listnode
*node
, *nnode
;
68 for (ALL_LIST_ELEMENTS(ripng
->peer_list
, node
, nnode
, peer
)) {
69 if (addr6_cmp(&peer
->addr
, addr
) > 0)
75 /* RIPng peer is timeout.
78 static void ripng_peer_timeout(struct thread
*t
)
80 struct ripng_peer
*peer
;
83 listnode_delete(peer
->ripng
->peer_list
, peer
);
84 ripng_peer_free(peer
);
87 /* Get RIPng peer. At the same time update timeout thread. */
88 static struct ripng_peer
*ripng_peer_get(struct ripng
*ripng
,
89 struct in6_addr
*addr
)
91 struct ripng_peer
*peer
;
93 peer
= ripng_peer_lookup(ripng
, addr
);
96 THREAD_OFF(peer
->t_timeout
);
98 peer
= ripng_peer_new();
101 listnode_add_sort(ripng
->peer_list
, peer
);
104 /* Update timeout thread. */
105 thread_add_timer(master
, ripng_peer_timeout
, peer
,
106 RIPNG_PEER_TIMER_DEFAULT
, &peer
->t_timeout
);
108 /* Last update time set. */
114 void ripng_peer_update(struct ripng
*ripng
, struct sockaddr_in6
*from
,
117 struct ripng_peer
*peer
;
118 peer
= ripng_peer_get(ripng
, &from
->sin6_addr
);
119 peer
->version
= version
;
122 void ripng_peer_bad_route(struct ripng
*ripng
, struct sockaddr_in6
*from
)
124 struct ripng_peer
*peer
;
125 peer
= ripng_peer_get(ripng
, &from
->sin6_addr
);
126 peer
->recv_badroutes
++;
129 void ripng_peer_bad_packet(struct ripng
*ripng
, struct sockaddr_in6
*from
)
131 struct ripng_peer
*peer
;
132 peer
= ripng_peer_get(ripng
, &from
->sin6_addr
);
133 peer
->recv_badpackets
++;
136 /* Display peer uptime. */
137 static char *ripng_peer_uptime(struct ripng_peer
*peer
, char *buf
, size_t len
)
141 /* If there is no connection has been done before print `never'. */
142 if (peer
->uptime
== 0) {
143 snprintf(buf
, len
, "never ");
147 /* Get current time. */
149 uptime
-= peer
->uptime
;
151 frrtime_to_interval(uptime
, buf
, len
);
156 void ripng_peer_display(struct vty
*vty
, struct ripng
*ripng
)
158 struct ripng_peer
*peer
;
159 struct listnode
*node
, *nnode
;
160 #define RIPNG_UPTIME_LEN 25
161 char timebuf
[RIPNG_UPTIME_LEN
];
163 for (ALL_LIST_ELEMENTS(ripng
->peer_list
, node
, nnode
, peer
)) {
164 vty_out(vty
, " %pI6 \n%14s %10d %10d %10d %s\n",
165 &peer
->addr
, " ", peer
->recv_badpackets
,
166 peer
->recv_badroutes
, ZEBRA_RIPNG_DISTANCE_DEFAULT
,
167 ripng_peer_uptime(peer
, timebuf
, RIPNG_UPTIME_LEN
));
171 int ripng_peer_list_cmp(struct ripng_peer
*p1
, struct ripng_peer
*p2
)
173 return memcmp(&p1
->addr
, &p2
->addr
, sizeof(struct in6_addr
));
176 void ripng_peer_list_del(void *arg
)
178 ripng_peer_free(arg
);