diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sockunion.c | 19 | ||||
-rw-r--r-- | lib/sockunion.h | 1 | ||||
-rw-r--r-- | lib/vty.c | 21 | ||||
-rw-r--r-- | lib/vty.h | 7 |
4 files changed, 12 insertions, 36 deletions
diff --git a/lib/sockunion.c b/lib/sockunion.c index 59770529..cfb6f9c5 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -207,25 +207,6 @@ sockunion_str2su (const char *str) return NULL; } -char * -sockunion_su2str (union sockunion *su) -{ - char str[SU_ADDRSTRLEN]; - - switch (su->sa.sa_family) - { - case AF_INET: - inet_ntop (AF_INET, &su->sin.sin_addr, str, sizeof (str)); - break; -#ifdef HAVE_IPV6 - case AF_INET6: - inet_ntop (AF_INET6, &su->sin6.sin6_addr, str, sizeof (str)); - break; -#endif /* HAVE_IPV6 */ - } - return XSTRDUP (MTYPE_TMP, str); -} - /* Convert IPv4 compatible IPv6 address to IPv4 address. */ static void sockunion_normalise_mapped (union sockunion *su) diff --git a/lib/sockunion.h b/lib/sockunion.h index 15b97fc5..8b060586 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -94,7 +94,6 @@ extern const char *sockunion2str (union sockunion *, char *, size_t); extern int sockunion_cmp (union sockunion *, union sockunion *); extern int sockunion_same (union sockunion *, union sockunion *); -extern char *sockunion_su2str (union sockunion *su); extern union sockunion *sockunion_str2su (const char *str); extern struct in_addr sockunion_get_in_addr (union sockunion *su); extern int sockunion_accept (int sock, union sockunion *); @@ -1612,13 +1612,16 @@ vty_flush (struct thread *thread) static struct vty * vty_create (int vty_sock, union sockunion *su) { + char buf[SU_ADDRSTRLEN]; struct vty *vty; + sockunion2str(su, buf, SU_ADDRSTRLEN); + /* Allocate new vty structure and set up default values. */ vty = vty_new (); vty->fd = vty_sock; vty->type = VTY_TERM; - vty->address = sockunion_su2str (su); + strcpy (vty->address, buf); if (no_password_check) { if (restricted_mode) @@ -1693,7 +1696,7 @@ vty_accept (struct thread *thread) int accept_sock; struct prefix *p = NULL; struct access_list *acl = NULL; - char *bufp; + char buf[SU_ADDRSTRLEN]; accept_sock = THREAD_FD (thread); @@ -1719,10 +1722,8 @@ vty_accept (struct thread *thread) if ((acl = access_list_lookup (AFI_IP, vty_accesslist_name)) && (access_list_apply (acl, p) == FILTER_DENY)) { - char *buf; zlog (NULL, LOG_INFO, "Vty connection refused from %s", - (buf = sockunion_su2str (&su))); - free (buf); + sockunion2str (&su, buf, SU_ADDRSTRLEN)); close (vty_sock); /* continue accepting connections */ @@ -1741,10 +1742,8 @@ vty_accept (struct thread *thread) if ((acl = access_list_lookup (AFI_IP6, vty_ipv6_accesslist_name)) && (access_list_apply (acl, p) == FILTER_DENY)) { - char *buf; zlog (NULL, LOG_INFO, "Vty connection refused from %s", - (buf = sockunion_su2str (&su))); - free (buf); + sockunion2str (&su, buf, SU_ADDRSTRLEN)); close (vty_sock); /* continue accepting connections */ @@ -1767,9 +1766,7 @@ vty_accept (struct thread *thread) safe_strerror (errno)); zlog (NULL, LOG_INFO, "Vty connection from %s", - (bufp = sockunion_su2str (&su))); - if (bufp) - XFREE (MTYPE_TMP, bufp); + sockunion2str (&su, buf, SU_ADDRSTRLEN)); vty_create (vty_sock, &su); @@ -2193,8 +2190,6 @@ vty_close (struct vty *vty) if (vty->fd > 0) close (vty->fd); - if (vty->address) - XFREE (MTYPE_TMP, vty->address); if (vty->buf) XFREE (MTYPE_VTY, vty->buf); @@ -23,6 +23,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "thread.h" #include "log.h" +#include "sockunion.h" #define VTY_BUFSIZ 512 #define VTY_MAXHIST 20 @@ -39,9 +40,6 @@ struct vty /* Node status of this vty */ int node; - /* What address is this vty comming from. */ - char *address; - /* Failure count */ int fail; @@ -118,6 +116,9 @@ struct vty /* Timeout seconds and thread. */ unsigned long v_timeout; struct thread *t_timeout; + + /* What address is this vty comming from. */ + char address[SU_ADDRSTRLEN]; }; /* Integrated configuration file. */ |