diff options
author | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:03:14 +0200 |
---|---|---|
committer | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:04:07 +0200 |
commit | d62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch) | |
tree | 3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /ripngd/ripng_peer.c | |
parent | *: add indent control files (diff) | |
download | frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.tar.xz frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.zip |
*: reindentreindent-master-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'ripngd/ripng_peer.c')
-rw-r--r-- | ripngd/ripng_peer.c | 231 |
1 files changed, 105 insertions, 126 deletions
diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index f27c33f37..2a412f9b6 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -38,178 +38,157 @@ /* Linked list of RIPng peer. */ struct list *peer_list; -static struct ripng_peer * -ripng_peer_new (void) +static struct ripng_peer *ripng_peer_new(void) { - return XCALLOC (MTYPE_RIPNG_PEER, sizeof (struct ripng_peer)); + return XCALLOC(MTYPE_RIPNG_PEER, sizeof(struct ripng_peer)); } -static void -ripng_peer_free (struct ripng_peer *peer) +static void ripng_peer_free(struct ripng_peer *peer) { - XFREE (MTYPE_RIPNG_PEER, peer); + XFREE(MTYPE_RIPNG_PEER, peer); } -struct ripng_peer * -ripng_peer_lookup (struct in6_addr *addr) +struct ripng_peer *ripng_peer_lookup(struct in6_addr *addr) { - struct ripng_peer *peer; - struct listnode *node, *nnode; - - for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) - { - if (IPV6_ADDR_SAME (&peer->addr, addr)) - return peer; - } - return NULL; + struct ripng_peer *peer; + struct listnode *node, *nnode; + + for (ALL_LIST_ELEMENTS(peer_list, node, nnode, peer)) { + if (IPV6_ADDR_SAME(&peer->addr, addr)) + return peer; + } + return NULL; } -struct ripng_peer * -ripng_peer_lookup_next (struct in6_addr *addr) +struct ripng_peer *ripng_peer_lookup_next(struct in6_addr *addr) { - struct ripng_peer *peer; - struct listnode *node, *nnode; - - for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) - { - if (addr6_cmp(&peer->addr, addr) > 0) - return peer; - } - return NULL; + struct ripng_peer *peer; + struct listnode *node, *nnode; + + for (ALL_LIST_ELEMENTS(peer_list, node, nnode, peer)) { + if (addr6_cmp(&peer->addr, addr) > 0) + return peer; + } + return NULL; } /* RIPng peer is timeout. * Garbage collector. **/ -static int -ripng_peer_timeout (struct thread *t) +static int ripng_peer_timeout(struct thread *t) { - struct ripng_peer *peer; + struct ripng_peer *peer; - peer = THREAD_ARG (t); - listnode_delete (peer_list, peer); - ripng_peer_free (peer); + peer = THREAD_ARG(t); + listnode_delete(peer_list, peer); + ripng_peer_free(peer); - return 0; + return 0; } /* Get RIPng peer. At the same time update timeout thread. */ -static struct ripng_peer * -ripng_peer_get (struct in6_addr *addr) +static struct ripng_peer *ripng_peer_get(struct in6_addr *addr) { - struct ripng_peer *peer; - - peer = ripng_peer_lookup (addr); - - if (peer) - { - if (peer->t_timeout) - thread_cancel (peer->t_timeout); - } - else - { - peer = ripng_peer_new (); - peer->addr = *addr; /* XXX */ - listnode_add_sort (peer_list, peer); - } - - /* Update timeout thread. */ - peer->t_timeout = NULL; - thread_add_timer(master, ripng_peer_timeout, peer, RIPNG_PEER_TIMER_DEFAULT, - &peer->t_timeout); - - /* Last update time set. */ - time (&peer->uptime); - - return peer; + struct ripng_peer *peer; + + peer = ripng_peer_lookup(addr); + + if (peer) { + if (peer->t_timeout) + thread_cancel(peer->t_timeout); + } else { + peer = ripng_peer_new(); + peer->addr = *addr; /* XXX */ + listnode_add_sort(peer_list, peer); + } + + /* Update timeout thread. */ + peer->t_timeout = NULL; + thread_add_timer(master, ripng_peer_timeout, peer, + RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout); + + /* Last update time set. */ + time(&peer->uptime); + + return peer; } -void -ripng_peer_update (struct sockaddr_in6 *from, u_char version) +void ripng_peer_update(struct sockaddr_in6 *from, u_char version) { - struct ripng_peer *peer; - peer = ripng_peer_get (&from->sin6_addr); - peer->version = version; + struct ripng_peer *peer; + peer = ripng_peer_get(&from->sin6_addr); + peer->version = version; } -void -ripng_peer_bad_route (struct sockaddr_in6 *from) +void ripng_peer_bad_route(struct sockaddr_in6 *from) { - struct ripng_peer *peer; - peer = ripng_peer_get (&from->sin6_addr); - peer->recv_badroutes++; + struct ripng_peer *peer; + peer = ripng_peer_get(&from->sin6_addr); + peer->recv_badroutes++; } -void -ripng_peer_bad_packet (struct sockaddr_in6 *from) +void ripng_peer_bad_packet(struct sockaddr_in6 *from) { - struct ripng_peer *peer; - peer = ripng_peer_get (&from->sin6_addr); - peer->recv_badpackets++; + struct ripng_peer *peer; + peer = ripng_peer_get(&from->sin6_addr); + peer->recv_badpackets++; } /* Display peer uptime. */ -static char * -ripng_peer_uptime (struct ripng_peer *peer, char *buf, size_t len) +static char *ripng_peer_uptime(struct ripng_peer *peer, char *buf, size_t len) { - time_t uptime; - struct tm *tm; - - /* If there is no connection has been done before print `never'. */ - if (peer->uptime == 0) - { - snprintf (buf, len, "never "); - return buf; - } - - /* Get current time. */ - uptime = time (NULL); - uptime -= peer->uptime; - tm = gmtime (&uptime); - - /* Making formatted timer strings. */ + time_t uptime; + struct tm *tm; + + /* If there is no connection has been done before print `never'. */ + if (peer->uptime == 0) { + snprintf(buf, len, "never "); + return buf; + } + + /* Get current time. */ + uptime = time(NULL); + uptime -= peer->uptime; + tm = gmtime(&uptime); + +/* Making formatted timer strings. */ #define ONE_DAY_SECOND 60*60*24 #define ONE_WEEK_SECOND 60*60*24*7 - if (uptime < ONE_DAY_SECOND) - snprintf (buf, len, "%02d:%02d:%02d", - tm->tm_hour, tm->tm_min, tm->tm_sec); - else if (uptime < ONE_WEEK_SECOND) - snprintf (buf, len, "%dd%02dh%02dm", - tm->tm_yday, tm->tm_hour, tm->tm_min); - else - snprintf (buf, len, "%02dw%dd%02dh", - tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour); - return buf; + if (uptime < ONE_DAY_SECOND) + snprintf(buf, len, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, + tm->tm_sec); + else if (uptime < ONE_WEEK_SECOND) + snprintf(buf, len, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour, + tm->tm_min); + else + snprintf(buf, len, "%02dw%dd%02dh", tm->tm_yday / 7, + tm->tm_yday - ((tm->tm_yday / 7) * 7), tm->tm_hour); + return buf; } -void -ripng_peer_display (struct vty *vty) +void ripng_peer_display(struct vty *vty) { - struct ripng_peer *peer; - struct listnode *node, *nnode; + struct ripng_peer *peer; + struct listnode *node, *nnode; #define RIPNG_UPTIME_LEN 25 - char timebuf[RIPNG_UPTIME_LEN]; - - for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) - { - vty_out (vty, " %s \n%14s %10d %10d %10d %s\n", inet6_ntoa (peer->addr), - " ", - peer->recv_badpackets, peer->recv_badroutes, - ZEBRA_RIPNG_DISTANCE_DEFAULT, - ripng_peer_uptime(peer, timebuf, RIPNG_UPTIME_LEN)); - } + char timebuf[RIPNG_UPTIME_LEN]; + + for (ALL_LIST_ELEMENTS(peer_list, node, nnode, peer)) { + vty_out(vty, " %s \n%14s %10d %10d %10d %s\n", + inet6_ntoa(peer->addr), " ", peer->recv_badpackets, + peer->recv_badroutes, ZEBRA_RIPNG_DISTANCE_DEFAULT, + ripng_peer_uptime(peer, timebuf, RIPNG_UPTIME_LEN)); + } } -static int -ripng_peer_list_cmp (struct ripng_peer *p1, struct ripng_peer *p2) +static int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2) { - return addr6_cmp(&p1->addr, &p2->addr) > 0; + return addr6_cmp(&p1->addr, &p2->addr) > 0; } -void -ripng_peer_init () +void ripng_peer_init() { - peer_list = list_new (); - peer_list->cmp = (int (*)(void *, void *)) ripng_peer_list_cmp; + peer_list = list_new(); + peer_list->cmp = (int (*)(void *, void *))ripng_peer_list_cmp; } |