/* Master of threads. */
extern struct zebra_t zebrad;
-int in_cksum (void *ptr, int nbytes);
extern int irdp_sock;
-int irdp_send_thread(struct thread *t_advert);
-char *inet_2a(u_int32_t a, char *b);
-void irdp_advert_off(struct interface *ifp);
+static const char *
+inet_2a(u_int32_t a, char *b)
+{
+ sprintf(b, "%u.%u.%u.%u",
+ (a ) & 0xFF,
+ (a>> 8) & 0xFF,
+ (a>>16) & 0xFF,
+ (a>>24) & 0xFF);
+ return b;
+}
-char b1[16], b2[16], b3[16], b4[16]; /* For inet_2a */
-struct prefix *irdp_get_prefix(struct interface *ifp)
+static struct prefix *
+irdp_get_prefix(struct interface *ifp)
{
struct listnode *node;
struct connected *ifc;
if (ifp->connected)
- LIST_LOOP (ifp->connected, ifc, node)
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
return ifc->address;
return NULL;
}
/* Join to the add/leave multicast group. */
-int if_group (struct interface *ifp,
+static int
+if_group (struct interface *ifp,
int sock,
u_int32_t group,
int add_leave)
struct ip_mreq m;
struct prefix *p;
int ret;
+ char b1[INET_ADDRSTRLEN];
zi = ifp->info;
- bzero (&m, sizeof (m));
+ memset (&m, 0, sizeof (m));
m.imr_multiaddr.s_addr = htonl (group);
p = irdp_get_prefix(ifp);
if (ret < 0)
zlog_warn ("IRDP: %s can't setsockopt %s: %s",
add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group",
- inet_2a(group, b1),
- strerror (errno));
+ inet_2a(group, b1),
+ safe_strerror (errno));
return ret;
}
-int if_add_group (struct interface *ifp)
+static int
+if_add_group (struct interface *ifp)
{
struct zebra_if *zi= ifp->info;
struct irdp_interface *irdp = &zi->irdp;
int ret;
+ char b1[INET_ADDRSTRLEN];
ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
if (ret < 0) {
}
if(irdp->flags & IF_DEBUG_MISC )
- zlog_warn("IRDP: Adding group %s for %s\n",
- inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
- ifp->name);
+ zlog_debug("IRDP: Adding group %s for %s",
+ inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
+ ifp->name);
return 0;
}
-int if_drop_group (struct interface *ifp)
+
+static int
+if_drop_group (struct interface *ifp)
{
struct zebra_if *zi= ifp->info;
struct irdp_interface *irdp = &zi->irdp;
int ret;
+ char b1[INET_ADDRSTRLEN];
ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP);
if (ret < 0)
return ret;
if(irdp->flags & IF_DEBUG_MISC)
- zlog_warn("IRDP: Leaving group %s for %s\n",
- inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
- ifp->name);
+ zlog_debug("IRDP: Leaving group %s for %s",
+ inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
+ ifp->name);
return 0;
}
-struct interface *get_iflist_ifp(unsigned int idx)
-{
- struct listnode *node;
- struct interface *ifp;
-
- LIST_LOOP (iflist, ifp, node)
- if(ifp->ifindex == idx)
- return ifp;
-
- return NULL;
-}
-
-void
+static void
if_set_defaults(struct interface *ifp)
{
struct zebra_if *zi=ifp->info;
}
-struct Adv *Adv_new ()
+static struct Adv *Adv_new (void)
{
- struct Adv *new;
- new = XMALLOC (MTYPE_TMP, sizeof (struct Adv));
- memset (new, 0, sizeof (struct Adv));
- return new;
+ return XCALLOC (MTYPE_TMP, sizeof (struct Adv));
}
-void Adv_free (struct Adv *adv)
+static void
+Adv_free (struct Adv *adv)
{
XFREE (MTYPE_TMP, adv);
}
-void irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
+static void
+irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
{
struct zebra_if *zi= ifp->info;
struct irdp_interface *irdp = &zi->irdp;
u_int32_t timer, seed;
if (irdp->flags & IF_ACTIVE ) {
- zlog_warn("IRDP: Interface is already active %s\n", ifp->name);
+ zlog_warn("IRDP: Interface is already active %s", ifp->name);
+ return;
+ }
+ if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
+ zlog_warn("IRDP: Cannot activate interface %s (cannot create "
+ "IRDP socket)", ifp->name);
return;
}
irdp->flags |= IF_ACTIVE;
if_add_update(ifp);
if (! (ifp->flags & IFF_UP)) {
- zlog_warn("IRDP: Interface is down %s\n", ifp->name);
+ zlog_warn("IRDP: Interface is down %s", ifp->name);
}
/* Shall we cancel if_start if if_add_group fails? */
if_add_group(ifp);
if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) {
- zlog_warn("IRDP: Interface not multicast enabled %s\n", ifp->name);
+ zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name);
}
}
seed = 0;
if( ifp->connected)
- LIST_LOOP (ifp->connected, ifc, node)
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
{
seed = ifc->address->u.prefix4.s_addr;
break;
if(irdp->flags & IF_DEBUG_MISC)
- zlog_warn("IRDP: Init timer for %s set to %u\n",
- ifp->name,
- timer);
+ zlog_debug("IRDP: Init timer for %s set to %u",
+ ifp->name,
+ timer);
irdp->t_advertise = thread_add_timer(zebrad.master,
irdp_send_thread,
timer);
}
-void irdp_if_stop(struct interface *ifp)
+static void
+irdp_if_stop(struct interface *ifp)
{
struct zebra_if *zi=ifp->info;
struct irdp_interface *irdp=&zi->irdp;
}
if (! (irdp->flags & IF_ACTIVE )) {
- zlog_warn("Interface is not active %s\n", ifp->name);
+ zlog_warn("Interface is not active %s", ifp->name);
return;
}
}
-void irdp_if_shutdown(struct interface *ifp)
+static void
+irdp_if_shutdown(struct interface *ifp)
{
struct zebra_if *zi= ifp->info;
struct irdp_interface *irdp = &zi->irdp;
if (irdp->flags & IF_SHUTDOWN ) {
- zlog_warn("IRDP: Interface is already shutdown %s\n", ifp->name);
+ zlog_warn("IRDP: Interface is already shutdown %s", ifp->name);
return;
}
irdp_advert_off(ifp);
}
-void irdp_if_no_shutdown(struct interface *ifp)
+static void
+irdp_if_no_shutdown(struct interface *ifp)
{
struct zebra_if *zi= ifp->info;
struct irdp_interface *irdp = &zi->irdp;
if (! (irdp->flags & IF_SHUTDOWN )) {
- zlog_warn("IRDP: Interface is not shutdown %s\n", ifp->name);
+ zlog_warn("IRDP: Interface is not shutdown %s", ifp->name);
return;
}
struct irdp_interface *irdp=&zi->irdp;
struct Adv *adv;
struct listnode *node;
+ char b1[INET_ADDRSTRLEN];
if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {
vty_out (vty, " ip irdp preference %ld%s",
irdp->Preference, VTY_NEWLINE);
- LIST_LOOP (irdp->AdvPrefList, adv, node)
+ for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
vty_out (vty, " ip irdp address %s preference %d%s",
inet_2a(adv->ip.s_addr, b1),
adv->pref,
return CMD_WARNING;
}
+/* DEFUN needs to be fixed for negative ranages...
+ * "ip irdp preference <-2147483648-2147483647>",
+ * Be positive for now. :-)
+ */
+
DEFUN (ip_irdp_preference,
ip_irdp_preference_cmd,
-
- /* DEFUN needs to be fixed for negative ranages...
- Be positive for now. :-)
-
- "ip irdp preference <-2147483648-2147483647>",
- */
-
-
"ip irdp preference <0-2147483647>",
IP_STR
"ICMP Router discovery on this interface\n"
pref = atoi(argv[1]);
- LIST_LOOP (irdp->AdvPrefList, adv, node)
+ for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
if(adv->ip.s_addr == ip.s_addr)
return CMD_SUCCESS;
pref = atoi(argv[1]);
- for (node = listhead (irdp->AdvPrefList); node; node = nnode)
+ for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv))
{
- nnode = node->next;
- adv = getdata (node);
-
if(adv->ip.s_addr == ip.s_addr )
{
listnode_delete(irdp->AdvPrefList, adv);
}
void
-irdp_if_init ()
+irdp_init ()
{
install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd);
install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd);