version 1.1.1.1, 2012/02/21 17:26:12
|
version 1.1.1.2, 2012/10/09 09:22:28
|
Line 41 static void zclient_event (enum event, struct zclient
|
Line 41 static void zclient_event (enum event, struct zclient
|
|
|
extern struct thread_master *master; |
extern struct thread_master *master; |
|
|
|
char *zclient_serv_path = NULL; |
|
|
/* This file local debug flag. */ |
/* This file local debug flag. */ |
int zclient_debug = 0; |
int zclient_debug = 0; |
|
|
Line 143 zclient_reset (struct zclient *zclient)
|
Line 145 zclient_reset (struct zclient *zclient)
|
zclient_init (zclient, zclient->redist_default); |
zclient_init (zclient, zclient->redist_default); |
} |
} |
|
|
|
#ifdef HAVE_TCP_ZEBRA |
|
|
/* Make socket to zebra daemon. Return zebra socket. */ |
/* Make socket to zebra daemon. Return zebra socket. */ |
int | static int |
zclient_socket(void) |
zclient_socket(void) |
{ |
{ |
int sock; |
int sock; |
Line 175 zclient_socket(void)
|
Line 179 zclient_socket(void)
|
return sock; |
return sock; |
} |
} |
|
|
|
#else |
|
|
/* For sockaddr_un. */ |
/* For sockaddr_un. */ |
#include <sys/un.h> |
#include <sys/un.h> |
|
|
int | static int |
zclient_socket_un (const char *path) |
zclient_socket_un (const char *path) |
{ |
{ |
int ret; |
int ret; |
Line 208 zclient_socket_un (const char *path)
|
Line 214 zclient_socket_un (const char *path)
|
return sock; |
return sock; |
} |
} |
|
|
|
#endif /* HAVE_TCP_ZEBRA */ |
|
|
|
/** |
|
* Connect to zebra daemon. |
|
* @param zclient a pointer to zclient structure |
|
* @return socket fd just to make sure that connection established |
|
* @see zclient_init |
|
* @see zclient_new |
|
*/ |
|
int |
|
zclient_socket_connect (struct zclient *zclient) |
|
{ |
|
#ifdef HAVE_TCP_ZEBRA |
|
zclient->sock = zclient_socket (); |
|
#else |
|
zclient->sock = zclient_socket_un (zclient_serv_path ? zclient_serv_path : ZEBRA_SERV_PATH); |
|
#endif |
|
return zclient->sock; |
|
} |
|
|
static int |
static int |
zclient_failed(struct zclient *zclient) |
zclient_failed(struct zclient *zclient) |
{ |
{ |
Line 292 zebra_message_send (struct zclient *zclient, int comma
|
Line 318 zebra_message_send (struct zclient *zclient, int comma
|
return zclient_send_message(zclient); |
return zclient_send_message(zclient); |
} |
} |
|
|
|
static int |
|
zebra_hello_send (struct zclient *zclient) |
|
{ |
|
struct stream *s; |
|
|
|
if (zclient->redist_default) |
|
{ |
|
s = zclient->obuf; |
|
stream_reset (s); |
|
|
|
zclient_create_header (s, ZEBRA_HELLO); |
|
stream_putc (s, zclient->redist_default); |
|
stream_putw_at (s, 0, stream_get_endp (s)); |
|
return zclient_send_message(zclient); |
|
} |
|
|
|
return 0; |
|
} |
|
|
/* Make connection to zebra daemon. */ |
/* Make connection to zebra daemon. */ |
int |
int |
zclient_start (struct zclient *zclient) |
zclient_start (struct zclient *zclient) |
Line 313 zclient_start (struct zclient *zclient)
|
Line 358 zclient_start (struct zclient *zclient)
|
if (zclient->t_connect) |
if (zclient->t_connect) |
return 0; |
return 0; |
|
|
/* Make socket. */ | if (zclient_socket_connect(zclient) < 0) |
#ifdef HAVE_TCP_ZEBRA | |
zclient->sock = zclient_socket (); | |
#else | |
zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH); | |
#endif /* HAVE_TCP_ZEBRA */ | |
if (zclient->sock < 0) | |
{ |
{ |
if (zclient_debug) |
if (zclient_debug) |
zlog_debug ("zclient connection fail"); |
zlog_debug ("zclient connection fail"); |
Line 339 zclient_start (struct zclient *zclient)
|
Line 378 zclient_start (struct zclient *zclient)
|
/* Create read thread. */ |
/* Create read thread. */ |
zclient_event (ZCLIENT_READ, zclient); |
zclient_event (ZCLIENT_READ, zclient); |
|
|
|
zebra_hello_send (zclient); |
|
|
/* We need router-id information. */ |
/* We need router-id information. */ |
zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD); |
zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD); |
|
|
Line 435 zapi_ipv4_route (u_char cmd, struct zclient *zclient,
|
Line 476 zapi_ipv4_route (u_char cmd, struct zclient *zclient,
|
stream_putc (s, api->type); |
stream_putc (s, api->type); |
stream_putc (s, api->flags); |
stream_putc (s, api->flags); |
stream_putc (s, api->message); |
stream_putc (s, api->message); |
|
stream_putw (s, api->safi); |
|
|
/* Put prefix information. */ |
/* Put prefix information. */ |
psize = PSIZE (p->prefixlen); |
psize = PSIZE (p->prefixlen); |
Line 496 zapi_ipv6_route (u_char cmd, struct zclient *zclient,
|
Line 538 zapi_ipv6_route (u_char cmd, struct zclient *zclient,
|
stream_putc (s, api->type); |
stream_putc (s, api->type); |
stream_putc (s, api->flags); |
stream_putc (s, api->flags); |
stream_putc (s, api->message); |
stream_putc (s, api->message); |
|
stream_putw (s, api->safi); |
|
|
/* Put prefix information. */ |
/* Put prefix information. */ |
psize = PSIZE (p->prefixlen); |
psize = PSIZE (p->prefixlen); |
Line 611 zebra_interface_add_read (struct stream *s)
|
Line 654 zebra_interface_add_read (struct stream *s)
|
/* Lookup/create interface by name. */ |
/* Lookup/create interface by name. */ |
ifp = if_get_by_name_len (ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ)); |
ifp = if_get_by_name_len (ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ)); |
|
|
/* Read interface's index. */ | zebra_interface_if_set_value (s, ifp); |
ifp->ifindex = stream_getl (s); | |
|
|
/* Read interface's value. */ |
|
ifp->status = stream_getc (s); |
|
ifp->flags = stream_getq (s); |
|
ifp->metric = stream_getl (s); |
|
ifp->mtu = stream_getl (s); |
|
ifp->mtu6 = stream_getl (s); |
|
ifp->bandwidth = stream_getl (s); |
|
#ifdef HAVE_STRUCT_SOCKADDR_DL |
|
stream_get (&ifp->sdl, s, sizeof (ifp->sdl)); |
|
#else |
|
ifp->hw_addr_len = stream_getl (s); |
|
if (ifp->hw_addr_len) |
|
stream_get (ifp->hw_addr, s, ifp->hw_addr_len); |
|
#endif /* HAVE_STRUCT_SOCKADDR_DL */ |
|
|
|
return ifp; |
return ifp; |
} |
} |
|
|
Line 656 zebra_interface_state_read (struct stream *s)
|
Line 683 zebra_interface_state_read (struct stream *s)
|
if (! ifp) |
if (! ifp) |
return NULL; |
return NULL; |
|
|
/* Read interface's index. */ | zebra_interface_if_set_value (s, ifp); |
ifp->ifindex = stream_getl (s); | |
|
|
/* Read interface's value. */ |
|
ifp->status = stream_getc (s); |
|
ifp->flags = stream_getq (s); |
|
ifp->metric = stream_getl (s); |
|
ifp->mtu = stream_getl (s); |
|
ifp->mtu6 = stream_getl (s); |
|
ifp->bandwidth = stream_getl (s); |
|
|
|
return ifp; |
return ifp; |
} |
} |
|
|
Line 715 zebra_interface_if_set_value (struct stream *s, struct
|
Line 733 zebra_interface_if_set_value (struct stream *s, struct
|
ifp->mtu = stream_getl (s); |
ifp->mtu = stream_getl (s); |
ifp->mtu6 = stream_getl (s); |
ifp->mtu6 = stream_getl (s); |
ifp->bandwidth = stream_getl (s); |
ifp->bandwidth = stream_getl (s); |
|
#ifdef HAVE_STRUCT_SOCKADDR_DL |
|
stream_get (&ifp->sdl, s, sizeof (ifp->sdl)); |
|
#else |
|
ifp->hw_addr_len = stream_getl (s); |
|
if (ifp->hw_addr_len) |
|
stream_get (ifp->hw_addr, s, ifp->hw_addr_len); |
|
#endif /* HAVE_STRUCT_SOCKADDR_DL */ |
} |
} |
|
|
static int |
static int |
Line 796 zebra_interface_address_read (int type, struct stream
|
Line 821 zebra_interface_address_read (int type, struct stream
|
static int |
static int |
zclient_read (struct thread *thread) |
zclient_read (struct thread *thread) |
{ |
{ |
int ret; |
|
size_t already; |
size_t already; |
uint16_t length, command; |
uint16_t length, command; |
uint8_t marker, version; |
uint8_t marker, version; |
Line 891 zclient_read (struct thread *thread)
|
Line 915 zclient_read (struct thread *thread)
|
{ |
{ |
case ZEBRA_ROUTER_ID_UPDATE: |
case ZEBRA_ROUTER_ID_UPDATE: |
if (zclient->router_id_update) |
if (zclient->router_id_update) |
ret = (*zclient->router_id_update) (command, zclient, length); | (*zclient->router_id_update) (command, zclient, length); |
break; |
break; |
case ZEBRA_INTERFACE_ADD: |
case ZEBRA_INTERFACE_ADD: |
if (zclient->interface_add) |
if (zclient->interface_add) |
ret = (*zclient->interface_add) (command, zclient, length); | (*zclient->interface_add) (command, zclient, length); |
break; |
break; |
case ZEBRA_INTERFACE_DELETE: |
case ZEBRA_INTERFACE_DELETE: |
if (zclient->interface_delete) |
if (zclient->interface_delete) |
ret = (*zclient->interface_delete) (command, zclient, length); | (*zclient->interface_delete) (command, zclient, length); |
break; |
break; |
case ZEBRA_INTERFACE_ADDRESS_ADD: |
case ZEBRA_INTERFACE_ADDRESS_ADD: |
if (zclient->interface_address_add) |
if (zclient->interface_address_add) |
ret = (*zclient->interface_address_add) (command, zclient, length); | (*zclient->interface_address_add) (command, zclient, length); |
break; |
break; |
case ZEBRA_INTERFACE_ADDRESS_DELETE: |
case ZEBRA_INTERFACE_ADDRESS_DELETE: |
if (zclient->interface_address_delete) |
if (zclient->interface_address_delete) |
ret = (*zclient->interface_address_delete) (command, zclient, length); | (*zclient->interface_address_delete) (command, zclient, length); |
break; |
break; |
case ZEBRA_INTERFACE_UP: |
case ZEBRA_INTERFACE_UP: |
if (zclient->interface_up) |
if (zclient->interface_up) |
ret = (*zclient->interface_up) (command, zclient, length); | (*zclient->interface_up) (command, zclient, length); |
break; |
break; |
case ZEBRA_INTERFACE_DOWN: |
case ZEBRA_INTERFACE_DOWN: |
if (zclient->interface_down) |
if (zclient->interface_down) |
ret = (*zclient->interface_down) (command, zclient, length); | (*zclient->interface_down) (command, zclient, length); |
break; |
break; |
case ZEBRA_IPV4_ROUTE_ADD: |
case ZEBRA_IPV4_ROUTE_ADD: |
if (zclient->ipv4_route_add) |
if (zclient->ipv4_route_add) |
ret = (*zclient->ipv4_route_add) (command, zclient, length); | (*zclient->ipv4_route_add) (command, zclient, length); |
break; |
break; |
case ZEBRA_IPV4_ROUTE_DELETE: |
case ZEBRA_IPV4_ROUTE_DELETE: |
if (zclient->ipv4_route_delete) |
if (zclient->ipv4_route_delete) |
ret = (*zclient->ipv4_route_delete) (command, zclient, length); | (*zclient->ipv4_route_delete) (command, zclient, length); |
break; |
break; |
case ZEBRA_IPV6_ROUTE_ADD: |
case ZEBRA_IPV6_ROUTE_ADD: |
if (zclient->ipv6_route_add) |
if (zclient->ipv6_route_add) |
ret = (*zclient->ipv6_route_add) (command, zclient, length); | (*zclient->ipv6_route_add) (command, zclient, length); |
break; |
break; |
case ZEBRA_IPV6_ROUTE_DELETE: |
case ZEBRA_IPV6_ROUTE_DELETE: |
if (zclient->ipv6_route_delete) |
if (zclient->ipv6_route_delete) |
ret = (*zclient->ipv6_route_delete) (command, zclient, length); | (*zclient->ipv6_route_delete) (command, zclient, length); |
break; |
break; |
default: |
default: |
break; |
break; |
Line 1018 zclient_event (enum event event, struct zclient *zclie
|
Line 1042 zclient_event (enum event event, struct zclient *zclie
|
break; |
break; |
} |
} |
} |
} |
|
|
|
void |
|
zclient_serv_path_set (char *path) |
|
{ |
|
struct stat sb; |
|
|
|
/* reset */ |
|
zclient_serv_path = NULL; |
|
|
|
/* test if `path' is socket. don't set it otherwise. */ |
|
if (stat(path, &sb) == -1) |
|
{ |
|
zlog_warn ("%s: zebra socket `%s' does not exist", __func__, path); |
|
return; |
|
} |
|
|
|
if ((sb.st_mode & S_IFMT) != S_IFSOCK) |
|
{ |
|
zlog_warn ("%s: `%s' is not unix socket, sir", __func__, path); |
|
return; |
|
} |
|
|
|
/* it seems that path is unix socket */ |
|
zclient_serv_path = path; |
|
} |
|
|