summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--HACKING4
-rw-r--r--Makefile.am4
-rw-r--r--SERVICES1
-rw-r--r--bgpd/Makefile.am1
-rw-r--r--bgpd/bgp_advertise.c4
-rw-r--r--bgpd/bgp_advertise.h32
-rw-r--r--bgpd/bgp_attr.c10
-rw-r--r--bgpd/bgp_attr.h2
-rw-r--r--bgpd/bgp_dump.c12
-rw-r--r--bgpd/bgp_fsm.c2
-rw-r--r--bgpd/bgp_main.c22
-rw-r--r--bgpd/bgp_network.c73
-rw-r--r--bgpd/bgp_nexthop.c3
-rw-r--r--bgpd/bgp_packet.c80
-rw-r--r--bgpd/bgp_route.c901
-rw-r--r--bgpd/bgp_vty.c418
-rw-r--r--bgpd/bgp_zebra.c25
-rw-r--r--bgpd/bgpd.c3
-rw-r--r--bgpd/bgpd.h7
-rwxr-xr-xconfigure.ac104
-rw-r--r--doc/.gitignore1
-rw-r--r--doc/Makefile.am2
-rw-r--r--doc/install.texi1
-rw-r--r--doc/ipv6.texi10
-rw-r--r--doc/pimd.8108
-rw-r--r--doc/texinfo.tex7086
-rw-r--r--isisd/Makefile.am12
-rw-r--r--isisd/isis_adjacency.c2
-rw-r--r--isisd/isis_bpf.c3
-rw-r--r--isisd/isis_circuit.c70
-rw-r--r--isisd/isis_circuit.h1
-rw-r--r--isisd/isis_common.h1
-rw-r--r--isisd/isis_csm.c9
-rw-r--r--isisd/isis_dlpi.c3
-rw-r--r--isisd/isis_lsp.c23
-rw-r--r--isisd/isis_lsp.h1
-rw-r--r--isisd/isis_main.c25
-rw-r--r--isisd/isis_pdu.c278
-rw-r--r--isisd/isis_pdu.h5
-rw-r--r--isisd/isis_pfpacket.c7
-rw-r--r--isisd/isis_spf.c65
-rw-r--r--isisd/isis_tlv.c8
-rw-r--r--isisd/isisd.c13
-rw-r--r--isisd/isisd.h2
-rw-r--r--lib/Makefile.am14
-rw-r--r--lib/checksum.c53
-rw-r--r--lib/command.c340
-rw-r--r--lib/command.h4
-rw-r--r--lib/if.c2
-rw-r--r--lib/if.h7
-rw-r--r--lib/log.c83
-rw-r--r--lib/log.h2
-rw-r--r--lib/md5.c73
-rw-r--r--lib/md5.h3
-rw-r--r--lib/memory.c15
-rw-r--r--lib/memtypes.c18
-rw-r--r--lib/paths.c65
-rw-r--r--lib/paths.h34
-rw-r--r--lib/prefix.c54
-rw-r--r--lib/prefix.h2
-rw-r--r--lib/route_types.awk187
-rwxr-xr-xlib/route_types.pl199
-rw-r--r--lib/route_types.txt19
-rw-r--r--lib/sockunion.c34
-rw-r--r--lib/sockunion.h2
-rw-r--r--lib/stream.c26
-rw-r--r--lib/stream.h4
-rw-r--r--lib/thread.c274
-rw-r--r--lib/thread.h13
-rw-r--r--lib/vty.c31
-rw-r--r--lib/workqueue.c17
-rw-r--r--lib/zclient.c36
-rw-r--r--lib/zclient.h12
-rw-r--r--lib/zebra.h66
-rw-r--r--m4/.gitignore1
-rwxr-xr-xmkinstalldirs101
-rw-r--r--ospf6d/Makefile.am1
-rw-r--r--ospf6d/ospf6_asbr.c75
-rw-r--r--ospf6d/ospf6_interface.c28
-rw-r--r--ospf6d/ospf6_main.c24
-rw-r--r--ospfd/Makefile.am2
-rw-r--r--ospfd/ospf_abr.c45
-rw-r--r--ospfd/ospf_ase.c104
-rw-r--r--ospfd/ospf_ase.h2
-rw-r--r--ospfd/ospf_interface.c42
-rw-r--r--ospfd/ospf_interface.h11
-rw-r--r--ospfd/ospf_lsa.c24
-rw-r--r--ospfd/ospf_main.c20
-rw-r--r--ospfd/ospf_nsm.c24
-rw-r--r--ospfd/ospf_nsm.h2
-rw-r--r--ospfd/ospf_packet.c117
-rw-r--r--ospfd/ospf_packet.h1
-rw-r--r--ospfd/ospf_route.c67
-rw-r--r--ospfd/ospf_route.h6
-rw-r--r--ospfd/ospf_spf.c163
-rw-r--r--ospfd/ospf_vty.c267
-rw-r--r--ospfd/ospf_zebra.c26
-rw-r--r--ospfd/ospf_zebra.h2
-rw-r--r--ospfd/ospfd.c281
-rw-r--r--ospfd/ospfd.h13
-rw-r--r--pimd/.gitignore19
-rw-r--r--pimd/AUTHORS9
-rw-r--r--pimd/CAVEATS137
-rw-r--r--pimd/COMMANDS66
-rw-r--r--pimd/COPYING340
-rw-r--r--pimd/DEBUG61
-rw-r--r--pimd/LINUX_KERNEL_MROUTE_MFC26
-rw-r--r--pimd/Makefile.am76
-rw-r--r--pimd/README157
-rw-r--r--pimd/TODO373
-rw-r--r--pimd/pim_assert.c804
-rw-r--r--pimd/pim_assert.h75
-rw-r--r--pimd/pim_cmd.c4284
-rw-r--r--pimd/pim_cmd.h62
-rw-r--r--pimd/pim_hello.c529
-rw-r--r--pimd/pim_hello.h46
-rw-r--r--pimd/pim_iface.c1134
-rw-r--r--pimd/pim_iface.h160
-rw-r--r--pimd/pim_ifchannel.c893
-rw-r--r--pimd/pim_ifchannel.h145
-rw-r--r--pimd/pim_igmp.c1413
-rw-r--r--pimd/pim_igmp.h175
-rw-r--r--pimd/pim_igmp_join.c65
-rw-r--r--pimd/pim_igmp_join.h32
-rw-r--r--pimd/pim_igmpv3.c1728
-rw-r--r--pimd/pim_igmpv3.h100
-rw-r--r--pimd/pim_int.c44
-rw-r--r--pimd/pim_int.h31
-rw-r--r--pimd/pim_join.c430
-rw-r--r--pimd/pim_join.h43
-rw-r--r--pimd/pim_macro.c437
-rw-r--r--pimd/pim_macro.h44
-rw-r--r--pimd/pim_main.c298
-rw-r--r--pimd/pim_mroute.c448
-rw-r--r--pimd/pim_mroute.h178
-rw-r--r--pimd/pim_msg.c106
-rw-r--r--pimd/pim_msg.h52
-rw-r--r--pimd/pim_neighbor.c715
-rw-r--r--pimd/pim_neighbor.h74
-rw-r--r--pimd/pim_oil.c140
-rw-r--r--pimd/pim_oil.h53
-rw-r--r--pimd/pim_pim.c734
-rw-r--r--pimd/pim_pim.h71
-rw-r--r--pimd/pim_rand.c60
-rw-r--r--pimd/pim_rand.h30
-rw-r--r--pimd/pim_rpf.c254
-rw-r--r--pimd/pim_rpf.h36
-rw-r--r--pimd/pim_signals.c85
-rw-r--r--pimd/pim_signals.h28
-rw-r--r--pimd/pim_sock.c389
-rw-r--r--pimd/pim_sock.h57
-rw-r--r--pimd/pim_ssmpingd.c448
-rw-r--r--pimd/pim_ssmpingd.h45
-rw-r--r--pimd/pim_str.c46
-rw-r--r--pimd/pim_str.h32
-rw-r--r--pimd/pim_time.c151
-rw-r--r--pimd/pim_time.h39
-rw-r--r--pimd/pim_tlv.c726
-rw-r--r--pimd/pim_tlv.h133
-rw-r--r--pimd/pim_upstream.c686
-rw-r--r--pimd/pim_upstream.h122
-rw-r--r--pimd/pim_util.c159
-rw-r--r--pimd/pim_util.h43
-rw-r--r--pimd/pim_version.c25
-rw-r--r--pimd/pim_version.h30
-rw-r--r--pimd/pim_vty.c173
-rw-r--r--pimd/pim_vty.h32
-rw-r--r--pimd/pim_zebra.c1188
-rw-r--r--pimd/pim_zebra.h40
-rw-r--r--pimd/pim_zlookup.c456
-rw-r--r--pimd/pim_zlookup.h47
-rw-r--r--pimd/pimd.c134
-rw-r--r--pimd/pimd.conf.sample41
-rw-r--r--pimd/pimd.h138
-rwxr-xr-xpimd/quagga-bootstrap.sh21
-rwxr-xr-xpimd/quagga-build.sh10
-rwxr-xr-xpimd/quagga-configure.sh10
-rwxr-xr-xpimd/quagga-git-add.sh12
-rwxr-xr-xpimd/quagga-memtypes.sh22
-rwxr-xr-xpimd/savannah-git-clone.sh27
-rw-r--r--pimd/test_igmpv3_join.c149
-rw-r--r--ports/Makefile1
-rw-r--r--ports/pkg/DESCR1
-rw-r--r--redhat/quagga.spec.in11
-rw-r--r--ripd/Makefile.am1
-rw-r--r--ripd/rip_main.c22
-rw-r--r--ripd/ripd.h4
-rw-r--r--ripngd/Makefile.am1
-rw-r--r--ripngd/ripng_main.c22
-rw-r--r--ripngd/ripngd.h4
-rw-r--r--vtysh/Makefile.am3
-rw-r--r--vtysh/vtysh.c34
-rw-r--r--vtysh/vtysh.h5
-rw-r--r--vtysh/vtysh_main.c22
-rw-r--r--zebra/Makefile.am2
-rw-r--r--zebra/connected.c105
-rw-r--r--zebra/connected.h11
-rw-r--r--zebra/if_ioctl.c6
-rw-r--r--zebra/if_ioctl_solaris.c4
-rw-r--r--zebra/if_proc.c2
-rw-r--r--zebra/interface.c356
-rw-r--r--zebra/interface.h14
-rw-r--r--zebra/ioctl.c63
-rw-r--r--zebra/kernel_null.c2
-rw-r--r--zebra/kernel_socket.c54
-rw-r--r--zebra/main.c22
-rw-r--r--zebra/redistribute.c46
-rw-r--r--zebra/rib.h31
-rw-r--r--zebra/rt_ioctl.c2
-rw-r--r--zebra/rt_netlink.c227
-rw-r--r--zebra/rt_socket.c7
-rw-r--r--zebra/rtadv.c137
-rw-r--r--zebra/rtadv.h14
-rw-r--r--zebra/test_main.c11
-rw-r--r--zebra/zebra_rib.c294
-rw-r--r--zebra/zebra_vty.c504
-rw-r--r--zebra/zserv.c96
-rw-r--r--zebra/zserv.h7
219 files changed, 28137 insertions, 9525 deletions
diff --git a/.gitignore b/.gitignore
index 25a842b5..cafe4db8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ INSTALL
depcomp
missing
install-sh
+mkinstalldirs
autom4te*.cache
configure.lineno
configure
diff --git a/HACKING b/HACKING
index 5a207274..d9cd19d8 100644
--- a/HACKING
+++ b/HACKING
@@ -316,15 +316,17 @@ Daemons which are in a testing phase are
ospf6d
isisd
+ pimd
watchquagga
IMPORT OR UPDATE VENDOR SPECIFIC ROUTING PROTOCOLS
-The source code of Quagga is based on two vendors:
+The source code of Quagga is based on these vendors:
zebra_org (http://www.zebra.org/)
isisd_sf (http://isisd.sf.net/)
+ qpimd (http://http://savannah.nongnu.org/projects/qpimd/)
To import code from further sources, e.g. for archival purposes without
necessarily having to review and/or fix some changeset, create a branch from
diff --git a/Makefile.am b/Makefile.am
index 007758f2..6e9172c4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,11 +2,11 @@
SUBDIRS = lib @ZEBRA@ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ \
@ISISD@ @WATCHQUAGGA@ @VTYSH@ @OSPFCLIENT@ @DOC@ m4 @pkgsrcdir@ \
- redhat @SOLARIS@
+ redhat @SOLARIS@ @PIMD@
DIST_SUBDIRS = lib zebra bgpd ripd ripngd ospfd ospf6d \
isisd watchquagga vtysh ospfclient doc m4 pkgsrc redhat tests \
- solaris
+ solaris pimd
EXTRA_DIST = aclocal.m4 SERVICES TODO REPORTING-BUGS INSTALL.quagga.txt \
update-autotools \
diff --git a/SERVICES b/SERVICES
index 9c3546bc..c69d0c1a 100644
--- a/SERVICES
+++ b/SERVICES
@@ -17,3 +17,4 @@ bgpd 2605/tcp
ospf6d 2606/tcp
ospfapi 2607/tcp
isisd 2608/tcp
+pimd 2611/tcp
diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am
index 1b17d386..56a9fb8f 100644
--- a/bgpd/Makefile.am
+++ b/bgpd/Makefile.am
@@ -1,7 +1,6 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
INSTALL_SDATA=@INSTALL@ -m 600
AM_CFLAGS = $(PICFLAGS)
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c
index 87eb7ac7..4163ab96 100644
--- a/bgpd/bgp_advertise.c
+++ b/bgpd/bgp_advertise.c
@@ -263,7 +263,7 @@ bgp_adj_out_set (struct bgp_node *rn, struct peer *peer, struct prefix *p,
/* Add new advertisement to advertisement attribute list. */
bgp_advertise_add (adv->baa, adv);
- FIFO_ADD (&peer->sync[afi][safi]->update, &adv->fifo);
+ FIFO_ADD (&peer->sync[afi][safi]->update, adv);
}
void
@@ -297,7 +297,7 @@ bgp_adj_out_unset (struct bgp_node *rn, struct peer *peer, struct prefix *p,
adv->adj = adj;
/* Add to synchronization entry for withdraw announcement. */
- FIFO_ADD (&peer->sync[afi][safi]->withdraw, &adv->fifo);
+ FIFO_ADD (&peer->sync[afi][safi]->withdraw, adv);
/* Schedule packet write. */
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h
index 4ebde907..53427eb3 100644
--- a/bgpd/bgp_advertise.h
+++ b/bgpd/bgp_advertise.h
@@ -102,6 +102,38 @@ struct bgp_synchronize
struct bgp_advertise_fifo withdraw_low;
};
+static inline void FIFO_INIT(struct bgp_advertise_fifo *fifo)
+{
+ fifo->next = fifo->prev = (struct bgp_advertise *) fifo;
+}
+
+static inline void FIFO_ADD(struct bgp_advertise_fifo *fifo,
+ struct bgp_advertise *node)
+{
+ node->fifo.next = (struct bgp_advertise *) fifo;
+ node->fifo.prev = fifo->prev;
+ fifo->prev = fifo->prev->next = node;
+}
+
+static inline void FIFO_DEL(struct bgp_advertise *node)
+{
+ struct bgp_advertise_fifo *fifo = &node->fifo;
+
+ fifo->prev->next = fifo->next;
+ fifo->next->prev = fifo->prev;
+}
+
+static inline int FIFO_EMPTY(const struct bgp_advertise_fifo *fifo)
+{
+ return (fifo->next == (const struct bgp_advertise *) fifo);
+}
+
+static inline struct bgp_advertise *FIFO_HEAD(struct bgp_advertise_fifo *fifo)
+{
+ return FIFO_EMPTY(fifo) ? NULL : fifo->next;
+}
+
+
/* BGP adjacency linked list. */
#define BGP_INFO_ADD(N,A,TYPE) \
do { \
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 5e7536ae..2de60031 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -2353,7 +2353,7 @@ bgp_attr_finish (void)
/* Make attribute packet. */
void
bgp_dump_routes_attr (struct stream *s, struct attr *attr,
- struct prefix *prefix)
+ struct prefix *prefix, uint16_t flags)
{
unsigned long cp;
unsigned long len;
@@ -2494,6 +2494,14 @@ bgp_dump_routes_attr (struct stream *s, struct attr *attr,
stream_putl (s, attr->pathlimit.as);
}
+ /* Quagga extended dump attribute. */
+ stream_putc (s, BGP_ATTR_FLAG_OPTIONAL);
+ stream_putc (s, BGP_ATTR_QUAGGA_DUMPEXT);
+ stream_putc (s, 3);
+ /* put a version byte to allow clean extensions */
+ stream_putc (s, 0);
+ stream_putw (s, flags);
+
/* Return total size of attribute. */
len = stream_get_endp (s) - cp - 2;
stream_putw_at (s, cp, len);
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index ed8753bd..a09ed61c 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -163,7 +163,7 @@ extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
struct prefix *p, afi_t, safi_t,
struct prefix_rd *, u_char *);
extern void bgp_dump_routes_attr (struct stream *, struct attr *,
- struct prefix *);
+ struct prefix *, uint16_t);
extern int attrhash_cmp (const void *, const void *);
extern unsigned int attrhash_key_make (void *);
extern void attr_show_all (struct vty *);
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index 8087a403..2f5c83af 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -199,6 +199,7 @@ bgp_dump_routes_index_table(struct bgp *bgp)
struct listnode *node;
uint16_t peerno = 0;
struct stream *obuf;
+ struct in_addr localhost = { htonl(INADDR_LOOPBACK) };
obuf = bgp_dump_obuf;
stream_reset (obuf);
@@ -221,8 +222,15 @@ bgp_dump_routes_index_table(struct bgp *bgp)
}
/* Peer count */
- stream_putw (obuf, listcount(bgp->peer));
+ stream_putw (obuf, listcount(bgp->peer) + 1);
+ /* Peer #0 entry reflects locally originated routes */
+ stream_putc (obuf, TABLE_DUMP_V2_PEER_INDEX_TABLE_AS4+TABLE_DUMP_V2_PEER_INDEX_TABLE_IP);
+ stream_put_in_addr (obuf, &bgp->router_id);
+ stream_put_in_addr (obuf, &localhost);
+ stream_putl (obuf, bgp->as);
+
+ peerno++;
/* Walk down all peers */
for(ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))
{
@@ -360,7 +368,7 @@ bgp_dump_routes_func (int afi, int first_run, unsigned int seq)
/* Dump attribute. */
/* Skip prefix & AFI/SAFI for MP_NLRI */
- bgp_dump_routes_attr (obuf, info->attr, &rn->p);
+ bgp_dump_routes_attr (obuf, info->attr, &rn->p, info->flags);
}
/* Overwrite the entry count, now that we know the right number */
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index 487ebddb..e18fc8cd 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -704,7 +704,7 @@ bgp_start (struct peer *peer)
peer->fd);
return -1;
}
- BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
+
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
break;
}
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 9d14683c..f761f238 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -35,6 +35,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "routemap.h"
#include "filter.h"
#include "plist.h"
+#include "paths.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"
@@ -52,6 +53,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
static const struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
{ "config_file", required_argument, NULL, 'f'},
{ "pid_file", required_argument, NULL, 'i'},
{ "bgp_port", required_argument, NULL, 'p'},
@@ -96,7 +98,7 @@ static struct quagga_signal_t bgp_signals[] =
};
/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR BGP_DEFAULT_CONFIG;
+static char config_default[MAXPATHLEN];
/* Route retain mode flag. */
static int retain_mode = 0;
@@ -107,8 +109,11 @@ struct thread_master *master;
/* Manually specified configuration file name. */
char *config_file = NULL;
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
+
/* Process ID saved for use by init system */
-static const char *pid_file = PATH_BGPD_PID;
+static const char *pid_file = pid_file_default;
/* VTY port number and address. */
int vty_port = BGP_VTY_PORT;
@@ -147,6 +152,7 @@ usage (char *progname, int status)
Daemon which manages kernel routing table management and \
redistribution between different routing protocols.\n\n\
-d, --daemon Runs in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
-f, --config_file Set configuration file name\n\
-i, --pid_file Set process identifier file name\n\
-p, --bgp_port Set bgp protocol's port number\n\
@@ -182,7 +188,7 @@ sighup (void)
vty_read_config (config_file, config_default);
/* Create VTY's socket */
- vty_serv_sock (vty_addr, vty_port, BGP_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (BGP_VTY_NAME));
/* Try to return to normal operation. */
}
@@ -327,7 +333,7 @@ main (int argc, char **argv)
/* Command line argument treatment. */
while (1)
{
- opt = getopt_long (argc, argv, "df:i:hp:l:A:P:rnu:g:vC", longopts, 0);
+ opt = getopt_long (argc, argv, "dN:f:i:hp:l:A:P:rnu:g:vC", longopts, 0);
if (opt == EOF)
break;
@@ -339,6 +345,9 @@ main (int argc, char **argv)
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'f':
config_file = optarg;
break;
@@ -398,6 +407,9 @@ main (int argc, char **argv)
}
}
+ strcpy (config_default, path_config (BGP_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (BGP_PID_NAME));
+
/* Make thread master. */
master = bm->master;
@@ -434,7 +446,7 @@ main (int argc, char **argv)
pid_output (pid_file);
/* Make bgp vty socket. */
- vty_serv_sock (vty_addr, vty_port, BGP_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (BGP_VTY_NAME));
/* Print banner. */
zlog_notice ("BGPd %s starting: vty@%d, bgp@%s:%d", QUAGGA_VERSION,
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 9e3427d2..83b1142e 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -150,6 +150,7 @@ bgp_accept (struct thread *thread)
zlog_err ("[Error] BGP socket accept failed (%s)", safe_strerror (errno));
return -1;
}
+ set_nonblocking (bgp_sock);
if (BGP_DEBUG (events, EVENTS))
zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
@@ -233,46 +234,36 @@ bgp_bind (struct peer *peer)
}
static int
-bgp_bind_address (int sock, struct in_addr *addr)
+bgp_update_address (struct interface *ifp, const union sockunion *dst,
+ union sockunion *addr)
{
- int ret;
- struct sockaddr_in local;
-
- memset (&local, 0, sizeof (struct sockaddr_in));
- local.sin_family = AF_INET;
-#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
- local.sin_len = sizeof(struct sockaddr_in);
-#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
- memcpy (&local.sin_addr, addr, sizeof (struct in_addr));
-
- if ( bgpd_privs.change (ZPRIVS_RAISE) )
- zlog_err ("bgp_bind_address: could not raise privs");
-
- ret = bind (sock, (struct sockaddr *)&local, sizeof (struct sockaddr_in));
- if (ret < 0)
- ;
-
- if (bgpd_privs.change (ZPRIVS_LOWER) )
- zlog_err ("bgp_bind_address: could not lower privs");
-
- return 0;
-}
-
-static struct in_addr *
-bgp_update_address (struct interface *ifp)
-{
- struct prefix_ipv4 *p;
+ struct prefix *p, *sel, *d;
struct connected *connected;
struct listnode *node;
+ int common;
+
+ d = sockunion2hostprefix (dst);
+ sel = NULL;
+ common = -1;
for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
{
- p = (struct prefix_ipv4 *) connected->address;
-
- if (p->family == AF_INET)
- return &p->prefix;
+ p = connected->address;
+ if (p->family != d->family)
+ continue;
+ if (prefix_common_bits (p, d) > common)
+ {
+ sel = p;
+ common = prefix_common_bits (sel, d);
+ }
}
- return NULL;
+
+ prefix_free (d);
+ if (!sel)
+ return 1;
+
+ prefix2sockunion (sel, addr);
+ return 0;
}
/* Update source selection. */
@@ -280,7 +271,7 @@ static void
bgp_update_source (struct peer *peer)
{
struct interface *ifp;
- struct in_addr *addr;
+ union sockunion addr;
/* Source is specified with interface name. */
if (peer->update_if)
@@ -289,11 +280,10 @@ bgp_update_source (struct peer *peer)
if (! ifp)
return;
- addr = bgp_update_address (ifp);
- if (! addr)
+ if (bgp_update_address (ifp, &peer->su, &addr))
return;
- bgp_bind_address (peer->fd, addr);
+ sockunion_bind (peer->fd, &addr, 0, &addr);
}
/* Source is specified with IP address. */
@@ -383,14 +373,7 @@ bgp_listener (int sock, struct sockaddr *sa, socklen_t salen)
setsockopt_ipv4_tos (sock, IPTOS_PREC_INTERNETCONTROL);
#endif
-#ifdef IPV6_V6ONLY
- /* Want only IPV6 on ipv6 socket (not mapped addresses) */
- if (sa->sa_family == AF_INET6) {
- int on = 1;
- setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY,
- (void *) &on, sizeof (on));
- }
-#endif
+ sockopt_v6only (sa->sa_family, sock);
if (bgpd_privs.change (ZPRIVS_RAISE) )
zlog_err ("bgp_socket: could not raise privs");
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index 0cde665e..ba6f6ffa 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -28,6 +28,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "network.h"
#include "log.h"
#include "memory.h"
+#include "paths.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
@@ -1097,7 +1098,7 @@ zlookup_connect (struct thread *t)
#ifdef HAVE_TCP_ZEBRA
zlookup->sock = zclient_socket ();
#else
- zlookup->sock = zclient_socket_un (ZEBRA_SERV_PATH);
+ zlookup->sock = zclient_socket_un (path_state (ZEBRA_SERV_NAME));
#endif /* HAVE_TCP_ZEBRA */
if (zlookup->sock < 0)
return -1;
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index b29bc1f0..1e2f95e3 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -107,8 +107,7 @@ bgp_connect_check (struct peer *peer)
socklen_t slen;
int ret;
- /* Anyway I have to reset read and write thread. */
- BGP_READ_OFF (peer->t_read);
+ /* Anyway I have to reset write thread. */
BGP_WRITE_OFF (peer->t_write);
/* Check file descriptor. */
@@ -597,7 +596,6 @@ bgp_write (struct thread *thread)
struct stream *s;
int num;
unsigned int count = 0;
- int write_errno;
/* Yes first of all get peer pointer. */
peer = THREAD_ARG (thread);
@@ -610,46 +608,37 @@ bgp_write (struct thread *thread)
return 0;
}
- /* Nonblocking write until TCP output buffer is full. */
- while (1)
+ s = bgp_write_packet (peer);
+ if (!s)
+ return 0; /* nothing to send */
+
+ sockopt_cork (peer->fd, 1);
+
+ /* Nonblocking write until TCP output buffer is full. */
+ do
{
int writenum;
- int val;
-
- s = bgp_write_packet (peer);
- if (! s)
- return 0;
-
- /* XXX: FIXME, the socket should be NONBLOCK from the start
- * status shouldnt need to be toggled on each write
- */
- val = fcntl (peer->fd, F_GETFL, 0);
- fcntl (peer->fd, F_SETFL, val|O_NONBLOCK);
/* Number of bytes to be sent. */
writenum = stream_get_endp (s) - stream_get_getp (s);
/* Call write() system call. */
num = write (peer->fd, STREAM_PNT (s), writenum);
- write_errno = errno;
- fcntl (peer->fd, F_SETFL, val);
- if (num <= 0)
+ if (num < 0)
{
- /* Partial write. */
- if (write_errno == EWOULDBLOCK || write_errno == EAGAIN)
- break;
+ /* write failed either retry needed or error */
+ if (ERRNO_IO_RETRY(errno))
+ break;
BGP_EVENT_ADD (peer, TCP_fatal_error);
return 0;
}
+
if (num != writenum)
{
+ /* Partial write */
stream_forward_getp (s, num);
-
- if (write_errno == EAGAIN)
- break;
-
- continue;
+ break;
}
/* Retrieve BGP packet type. */
@@ -690,13 +679,14 @@ bgp_write (struct thread *thread)
/* OK we send packet so delete it. */
bgp_packet_delete (peer);
-
- if (++count >= BGP_WRITE_PACKET_MAX)
- break;
}
+ while (++count < BGP_WRITE_PACKET_MAX &&
+ (s = bgp_write_packet (peer)) != NULL);
if (bgp_write_proceed (peer))
BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
+ else
+ sockopt_cork (peer->fd, 0);
return 0;
}
@@ -705,7 +695,7 @@ bgp_write (struct thread *thread)
static int
bgp_write_notify (struct peer *peer)
{
- int ret;
+ int ret, val;
u_char type;
struct stream *s;
@@ -715,7 +705,10 @@ bgp_write_notify (struct peer *peer)
return 0;
assert (stream_get_endp (s) >= BGP_HEADER_SIZE);
- /* I'm not sure fd is writable. */
+ /* Put socket in blocking mode. */
+ val = fcntl (peer->fd, F_GETFL, 0);
+ fcntl (peer->fd, F_SETFL, val & ~O_NONBLOCK);
+
ret = writen (peer->fd, STREAM_DATA (s), stream_get_endp (s));
if (ret <= 0)
{
@@ -2237,12 +2230,13 @@ bgp_read_packet (struct peer *peer)
return 0;
/* Read packet from fd. */
- nbytes = stream_read_unblock (peer->ibuf, peer->fd, readsize);
+ nbytes = stream_read_try (peer->ibuf, peer->fd, readsize);
/* If read byte is smaller than zero then error occured. */
if (nbytes < 0)
{
- if (errno == EAGAIN)
+ /* Transient error should retry */
+ if (nbytes == -2)
return -1;
plog_err (peer->log, "%s [Error] bgp_read_packet error: %s",
@@ -2319,22 +2313,14 @@ bgp_read (struct thread *thread)
peer = THREAD_ARG (thread);
peer->t_read = NULL;
- /* For non-blocking IO check. */
- if (peer->status == Connect)
- {
- bgp_connect_check (peer);
- goto done;
- }
- else
+ if (peer->fd < 0)
{
- if (peer->fd < 0)
- {
- zlog_err ("bgp_read peer's fd is negative value %d", peer->fd);
- return -1;
- }
- BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
+ zlog_err ("bgp_read peer's fd is negative value %d", peer->fd);
+ return -1;
}
+ BGP_READ_ON (peer->t_read, bgp_read, peer->fd);
+
/* Read packet header to determine type of the packet */
if (peer->packet_size == 0)
peer->packet_size = BGP_HEADER_SIZE;
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index a92ca4e2..3d0417b1 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -1614,14 +1614,13 @@ bgp_process_queue_init (void)
}
bm->process_main_queue->spec.workfunc = &bgp_process_main;
- bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
- bm->process_rsclient_queue->spec.del_item_data
- = bm->process_main_queue->spec.del_item_data;
- bm->process_main_queue->spec.max_retries
- = bm->process_main_queue->spec.max_retries = 0;
- bm->process_rsclient_queue->spec.hold
- = bm->process_main_queue->spec.hold = 50;
+ bm->process_main_queue->spec.max_retries = 0;
+ bm->process_main_queue->spec.hold = 50;
+
+ memcpy (bm->process_rsclient_queue, bm->process_main_queue,
+ sizeof (struct work_queue *));
+ bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
}
void
@@ -5613,23 +5612,7 @@ route_vty_out_route (struct prefix *p, struct vty *vty)
u_int32_t destination;
char buf[BUFSIZ];
- if (p->family == AF_INET)
- {
- len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
- destination = ntohl (p->u.prefix4.s_addr);
-
- if ((IN_CLASSC (destination) && p->prefixlen == 24)
- || (IN_CLASSB (destination) && p->prefixlen == 16)
- || (IN_CLASSA (destination) && p->prefixlen == 8)
- || p->u.prefix4.s_addr == 0)
- {
- /* When mask is natural, mask is not displayed. */
- }
- else
- len += vty_out (vty, "/%d", p->prefixlen);
- }
- else
- len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
+ len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
p->prefixlen);
len = 17 - len;
@@ -6663,6 +6646,15 @@ DEFUN (show_ip_bgp_ipv4,
return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
}
+ALIAS (show_ip_bgp_ipv4,
+ show_bgp_ipv4_safi_cmd,
+ "show bgp ipv4 (unicast|multicast)",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n")
+
DEFUN (show_ip_bgp_route,
show_ip_bgp_route_cmd,
"show ip bgp A.B.C.D",
@@ -6691,6 +6683,16 @@ DEFUN (show_ip_bgp_ipv4_route,
return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
}
+ALIAS (show_ip_bgp_ipv4_route,
+ show_bgp_ipv4_safi_route_cmd,
+ "show bgp ipv4 (unicast|multicast) A.B.C.D",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Network in the BGP routing table to display\n")
+
DEFUN (show_ip_bgp_vpnv4_all_route,
show_ip_bgp_vpnv4_all_route_cmd,
"show ip bgp vpnv4 all A.B.C.D",
@@ -6755,6 +6757,16 @@ DEFUN (show_ip_bgp_ipv4_prefix,
return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
}
+ALIAS (show_ip_bgp_ipv4_prefix,
+ show_bgp_ipv4_safi_prefix_cmd,
+ "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
+
DEFUN (show_ip_bgp_vpnv4_all_prefix,
show_ip_bgp_vpnv4_all_prefix_cmd,
"show ip bgp vpnv4 all A.B.C.D/M",
@@ -6857,6 +6869,22 @@ ALIAS (show_bgp,
BGP_STR
"Address family\n")
+DEFUN (show_bgp_ipv6_safi,
+ show_bgp_ipv6_safi_cmd,
+ "show bgp ipv6 (unicast|multicast)",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n")
+{
+ if (strncmp (argv[0], "m", 1) == 0)
+ return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
+ NULL);
+
+ return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
+}
+
/* old command */
DEFUN (show_ipv6_bgp,
show_ipv6_bgp_cmd,
@@ -6887,6 +6915,22 @@ ALIAS (show_bgp_route,
"Address family\n"
"Network in the BGP routing table to display\n")
+DEFUN (show_bgp_ipv6_safi_route,
+ show_bgp_ipv6_safi_route_cmd,
+ "show bgp ipv6 (unicast|multicast) X:X::X:X",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Network in the BGP routing table to display\n")
+{
+ if (strncmp (argv[0], "m", 1) == 0)
+ return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
+
+ return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
+}
+
/* old command */
DEFUN (show_ipv6_bgp_route,
show_ipv6_bgp_route_cmd,
@@ -6917,6 +6961,22 @@ ALIAS (show_bgp_prefix,
"Address family\n"
"IPv6 prefix <network>/<length>\n")
+DEFUN (show_bgp_ipv6_safi_prefix,
+ show_bgp_ipv6_safi_prefix_cmd,
+ "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
+{
+ if (strncmp (argv[0], "m", 1) == 0)
+ return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
+
+ return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
+}
+
/* old command */
DEFUN (show_ipv6_bgp_prefix,
show_ipv6_bgp_prefix_cmd,
@@ -7621,15 +7681,36 @@ DEFUN (show_ipv6_mbgp_community_all,
#endif /* HAVE_IPV6 */
static int
-bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
- u_int16_t afi, u_char safi)
+bgp_show_community (struct vty *vty, const char *view_name, int argc,
+ const char **argv, int exact, afi_t afi, safi_t safi)
{
struct community *com;
struct buffer *b;
+ struct bgp *bgp;
int i;
char *str;
int first = 0;
+ /* BGP structure lookup */
+ if (view_name)
+ {
+ bgp = bgp_lookup_by_name (view_name);
+ if (bgp == NULL)
+ {
+ vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else
+ {
+ bgp = bgp_get_default ();
+ if (bgp == NULL)
+ {
+ vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
b = buffer_new (1024);
for (i = 0; i < argc; i++)
{
@@ -7657,7 +7738,7 @@ bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
return CMD_WARNING;
}
- return bgp_show (vty, NULL, afi, safi,
+ return bgp_show (vty, bgp, afi, safi,
(exact ? bgp_show_type_community_exact :
bgp_show_type_community), com);
}
@@ -7674,7 +7755,7 @@ DEFUN (show_ip_bgp_community,
"Do not advertise to any peer (well-known community)\n"
"Do not export to next AS (well-known community)\n")
{
- return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
}
ALIAS (show_ip_bgp_community,
@@ -7753,9 +7834,9 @@ DEFUN (show_ip_bgp_ipv4_community,
"Do not export to next AS (well-known community)\n")
{
if (strncmp (argv[0], "m", 1) == 0)
- return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
- return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
}
ALIAS (show_ip_bgp_ipv4_community,
@@ -7827,6 +7908,177 @@ ALIAS (show_ip_bgp_ipv4_community,
"Do not advertise to any peer (well-known community)\n"
"Do not export to next AS (well-known community)\n")
+DEFUN (show_bgp_view_afi_safi_community_all,
+ show_bgp_view_afi_safi_community_all_cmd,
+#ifdef HAVE_IPV6
+ "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
+#else
+ "show bgp view WORD ipv4 (unicast|multicast) community",
+#endif
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+#ifdef HAVE_IPV6
+ "Address family\n"
+#endif
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Display routes containing communities\n")
+{
+ int afi;
+ int safi;
+ struct bgp *bgp;
+
+ /* BGP structure lookup. */
+ bgp = bgp_lookup_by_name (argv[0]);
+ if (bgp == NULL)
+ {
+ vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+#ifdef HAVE_IPV6
+ afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
+ safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+#else
+ afi = AFI_IP;
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+#endif
+ return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
+}
+
+DEFUN (show_bgp_view_afi_safi_community,
+ show_bgp_view_afi_safi_community_cmd,
+#ifdef HAVE_IPV6
+ "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
+#else
+ "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
+#endif
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+#ifdef HAVE_IPV6
+ "Address family\n"
+#endif
+ "Address family modifier\n"
+ "Address family modifier\n"
+ "Display routes matching the communities\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n")
+{
+ int afi;
+ int safi;
+
+#ifdef HAVE_IPV6
+ afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
+ safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
+#else
+ afi = AFI_IP;
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
+#endif
+}
+
+ALIAS (show_bgp_view_afi_safi_community,
+ show_bgp_view_afi_safi_community2_cmd,
+#ifdef HAVE_IPV6
+ "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+#else
+ "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+#endif
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+#ifdef HAVE_IPV6
+ "Address family\n"
+#endif
+ "Address family modifier\n"
+ "Address family modifier\n"
+ "Display routes matching the communities\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n")
+
+ALIAS (show_bgp_view_afi_safi_community,
+ show_bgp_view_afi_safi_community3_cmd,
+#ifdef HAVE_IPV6
+ "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+#else
+ "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+#endif
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+#ifdef HAVE_IPV6
+ "Address family\n"
+#endif
+ "Address family modifier\n"
+ "Address family modifier\n"
+ "Display routes matching the communities\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n")
+
+ALIAS (show_bgp_view_afi_safi_community,
+ show_bgp_view_afi_safi_community4_cmd,
+#ifdef HAVE_IPV6
+ "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+#else
+ "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
+#endif
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+#ifdef HAVE_IPV6
+ "Address family\n"
+#endif
+ "Address family modifier\n"
+ "Address family modifier\n"
+ "Display routes matching the communities\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n"
+ "community number\n"
+ "Do not send outside local AS (well-known community)\n"
+ "Do not advertise to any peer (well-known community)\n"
+ "Do not export to next AS (well-known community)\n")
+
DEFUN (show_ip_bgp_community_exact,
show_ip_bgp_community_exact_cmd,
"show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
@@ -7840,7 +8092,7 @@ DEFUN (show_ip_bgp_community_exact,
"Do not export to next AS (well-known community)\n"
"Exact match of the communities")
{
- return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
}
ALIAS (show_ip_bgp_community_exact,
@@ -7923,9 +8175,9 @@ DEFUN (show_ip_bgp_ipv4_community_exact,
"Exact match of the communities")
{
if (strncmp (argv[0], "m", 1) == 0)
- return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
- return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
}
ALIAS (show_ip_bgp_ipv4_community_exact,
@@ -8012,7 +8264,7 @@ DEFUN (show_bgp_community,
"Do not advertise to any peer (well-known community)\n"
"Do not export to next AS (well-known community)\n")
{
- return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
}
ALIAS (show_bgp_community,
@@ -8157,7 +8409,7 @@ DEFUN (show_ipv6_bgp_community,
"Do not advertise to any peer (well-known community)\n"
"Do not export to next AS (well-known community)\n")
{
- return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
}
/* old command */
@@ -8235,7 +8487,7 @@ DEFUN (show_bgp_community_exact,
"Do not export to next AS (well-known community)\n"
"Exact match of the communities")
{
- return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
}
ALIAS (show_bgp_community_exact,
@@ -8388,7 +8640,7 @@ DEFUN (show_ipv6_bgp_community_exact,
"Do not export to next AS (well-known community)\n"
"Exact match of the communities")
{
- return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
}
/* old command */
@@ -8470,7 +8722,7 @@ DEFUN (show_ipv6_mbgp_community,
"Do not advertise to any peer (well-known community)\n"
"Do not export to next AS (well-known community)\n")
{
- return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
}
/* old command */
@@ -8550,7 +8802,7 @@ DEFUN (show_ipv6_mbgp_community_exact,
"Do not export to next AS (well-known community)\n"
"Exact match of the communities")
{
- return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
+ return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
}
/* old command */
@@ -9959,6 +10211,56 @@ DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
}
+DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
+ show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
+#ifdef HAVE_IPV6
+ "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
+#else
+ "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
+#endif
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+#ifdef HAVE_IPV6
+ "Address family\n"
+#endif
+ "Address family modifier\n"
+ "Address family modifier\n"
+ "Detailed information on TCP and BGP neighbor connections\n"
+ "Neighbor to display information about\n"
+ "Neighbor to display information about\n"
+ "Display the advertised routes to neighbor\n"
+ "Display the received routes from neighbor\n")
+{
+ int afi;
+ int safi;
+ int in;
+ struct peer *peer;
+
+#ifdef HAVE_IPV6
+ peer = peer_lookup_in_view (vty, argv[0], argv[3]);
+#else
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+#endif
+
+ if (! peer)
+ return CMD_WARNING;
+
+#ifdef HAVE_IPV6
+ afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
+ safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
+#else
+ afi = AFI_IP;
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
+#endif
+
+ return peer_adj_routes (vty, peer, afi, safi, in);
+}
+
DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
show_ip_bgp_neighbor_received_prefix_filter_cmd,
"show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
@@ -10366,6 +10668,65 @@ ALIAS (show_ip_bgp_view_rsclient,
"Information about Route Server Client\n"
NEIGHBOR_ADDR_STR)
+DEFUN (show_bgp_view_ipv4_safi_rsclient,
+ show_bgp_view_ipv4_safi_rsclient_cmd,
+ "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR)
+{
+ struct bgp_table *table;
+ struct peer *peer;
+ safi_t safi;
+
+ if (argc == 3) {
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ } else {
+ peer = peer_lookup_in_view (vty, NULL, argv[1]);
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ }
+
+ if (! peer)
+ return CMD_WARNING;
+
+ if (! peer->afc[AFI_IP][safi])
+ {
+ vty_out (vty, "%% Activate the neighbor for the address family first%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
+ PEER_FLAG_RSERVER_CLIENT))
+ {
+ vty_out (vty, "%% Neighbor is not a Route-Server client%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ table = peer->rib[AFI_IP][safi];
+
+ return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
+}
+
+ALIAS (show_bgp_view_ipv4_safi_rsclient,
+ show_bgp_ipv4_safi_rsclient_cmd,
+ "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR)
+
DEFUN (show_ip_bgp_view_rsclient_route,
show_ip_bgp_view_rsclient_route_cmd,
"show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
@@ -10439,6 +10800,87 @@ ALIAS (show_ip_bgp_view_rsclient_route,
NEIGHBOR_ADDR_STR
"Network in the BGP routing table to display\n")
+DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
+ show_bgp_view_ipv4_safi_rsclient_route_cmd,
+ "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "Network in the BGP routing table to display\n")
+{
+ struct bgp *bgp;
+ struct peer *peer;
+ safi_t safi;
+
+ /* BGP structure lookup. */
+ if (argc == 4)
+ {
+ bgp = bgp_lookup_by_name (argv[0]);
+ if (bgp == NULL)
+ {
+ vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else
+ {
+ bgp = bgp_get_default ();
+ if (bgp == NULL)
+ {
+ vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ if (argc == 4) {
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ } else {
+ peer = peer_lookup_in_view (vty, NULL, argv[1]);
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ }
+
+ if (! peer)
+ return CMD_WARNING;
+
+ if (! peer->afc[AFI_IP][safi])
+ {
+ vty_out (vty, "%% Activate the neighbor for the address family first%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+}
+
+ if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
+ PEER_FLAG_RSERVER_CLIENT))
+ {
+ vty_out (vty, "%% Neighbor is not a Route-Server client%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
+ (argc == 4) ? argv[3] : argv[2],
+ AFI_IP, safi, NULL, 0);
+}
+
+ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
+ show_bgp_ipv4_safi_rsclient_route_cmd,
+ "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "Network in the BGP routing table to display\n")
+
DEFUN (show_ip_bgp_view_rsclient_prefix,
show_ip_bgp_view_rsclient_prefix_cmd,
"show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
@@ -10512,6 +10954,86 @@ ALIAS (show_ip_bgp_view_rsclient_prefix,
NEIGHBOR_ADDR_STR
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
+DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
+ show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
+ "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
+{
+ struct bgp *bgp;
+ struct peer *peer;
+ safi_t safi;
+
+ /* BGP structure lookup. */
+ if (argc == 4)
+ {
+ bgp = bgp_lookup_by_name (argv[0]);
+ if (bgp == NULL)
+ {
+ vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else
+ {
+ bgp = bgp_get_default ();
+ if (bgp == NULL)
+ {
+ vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ if (argc == 4) {
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ } else {
+ peer = peer_lookup_in_view (vty, NULL, argv[1]);
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ }
+
+ if (! peer)
+ return CMD_WARNING;
+
+ if (! peer->afc[AFI_IP][safi])
+ {
+ vty_out (vty, "%% Activate the neighbor for the address family first%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+}
+
+ if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
+ PEER_FLAG_RSERVER_CLIENT))
+{
+ vty_out (vty, "%% Neighbor is not a Route-Server client%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
+ (argc == 4) ? argv[3] : argv[2],
+ AFI_IP, safi, NULL, 1);
+}
+
+ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
+ show_bgp_ipv4_safi_rsclient_prefix_cmd,
+ "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
#ifdef HAVE_IPV6
DEFUN (show_bgp_view_neighbor_routes,
@@ -10778,6 +11300,65 @@ ALIAS (show_bgp_view_rsclient,
"Information about Route Server Client\n"
NEIGHBOR_ADDR_STR)
+DEFUN (show_bgp_view_ipv6_safi_rsclient,
+ show_bgp_view_ipv6_safi_rsclient_cmd,
+ "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR)
+{
+ struct bgp_table *table;
+ struct peer *peer;
+ safi_t safi;
+
+ if (argc == 3) {
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ } else {
+ peer = peer_lookup_in_view (vty, NULL, argv[1]);
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ }
+
+ if (! peer)
+ return CMD_WARNING;
+
+ if (! peer->afc[AFI_IP6][safi])
+ {
+ vty_out (vty, "%% Activate the neighbor for the address family first%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
+ PEER_FLAG_RSERVER_CLIENT))
+ {
+ vty_out (vty, "%% Neighbor is not a Route-Server client%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ table = peer->rib[AFI_IP6][safi];
+
+ return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
+}
+
+ALIAS (show_bgp_view_ipv6_safi_rsclient,
+ show_bgp_ipv6_safi_rsclient_cmd,
+ "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR)
+
DEFUN (show_bgp_view_rsclient_route,
show_bgp_view_rsclient_route_cmd,
"show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
@@ -10849,6 +11430,87 @@ ALIAS (show_bgp_view_rsclient_route,
NEIGHBOR_ADDR_STR
"Network in the BGP routing table to display\n")
+DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
+ show_bgp_view_ipv6_safi_rsclient_route_cmd,
+ "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "Network in the BGP routing table to display\n")
+{
+ struct bgp *bgp;
+ struct peer *peer;
+ safi_t safi;
+
+ /* BGP structure lookup. */
+ if (argc == 4)
+ {
+ bgp = bgp_lookup_by_name (argv[0]);
+ if (bgp == NULL)
+ {
+ vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else
+ {
+ bgp = bgp_get_default ();
+ if (bgp == NULL)
+ {
+ vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ if (argc == 4) {
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ } else {
+ peer = peer_lookup_in_view (vty, NULL, argv[1]);
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ }
+
+ if (! peer)
+ return CMD_WARNING;
+
+ if (! peer->afc[AFI_IP6][safi])
+ {
+ vty_out (vty, "%% Activate the neighbor for the address family first%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+}
+
+ if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
+ PEER_FLAG_RSERVER_CLIENT))
+ {
+ vty_out (vty, "%% Neighbor is not a Route-Server client%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
+ (argc == 4) ? argv[3] : argv[2],
+ AFI_IP6, safi, NULL, 0);
+}
+
+ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
+ show_bgp_ipv6_safi_rsclient_route_cmd,
+ "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "Network in the BGP routing table to display\n")
+
DEFUN (show_bgp_view_rsclient_prefix,
show_bgp_view_rsclient_prefix_cmd,
"show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
@@ -10920,6 +11582,87 @@ ALIAS (show_bgp_view_rsclient_prefix,
NEIGHBOR_ADDR_STR
"IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
+DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
+ show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
+ "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "BGP view name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
+{
+ struct bgp *bgp;
+ struct peer *peer;
+ safi_t safi;
+
+ /* BGP structure lookup. */
+ if (argc == 4)
+ {
+ bgp = bgp_lookup_by_name (argv[0]);
+ if (bgp == NULL)
+ {
+ vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else
+ {
+ bgp = bgp_get_default ();
+ if (bgp == NULL)
+ {
+ vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ if (argc == 4) {
+ peer = peer_lookup_in_view (vty, argv[0], argv[2]);
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ } else {
+ peer = peer_lookup_in_view (vty, NULL, argv[1]);
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ }
+
+ if (! peer)
+ return CMD_WARNING;
+
+ if (! peer->afc[AFI_IP6][safi])
+ {
+ vty_out (vty, "%% Activate the neighbor for the address family first%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+}
+
+ if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
+ PEER_FLAG_RSERVER_CLIENT))
+{
+ vty_out (vty, "%% Neighbor is not a Route-Server client%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
+ (argc == 4) ? argv[3] : argv[2],
+ AFI_IP6, safi, NULL, 1);
+}
+
+ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
+ show_bgp_ipv6_safi_rsclient_prefix_cmd,
+ "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Client\n"
+ NEIGHBOR_ADDR_STR
+ "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
+
#endif /* HAVE_IPV6 */
struct bgp_table *bgp_distance_table;
@@ -11521,18 +12264,9 @@ bgp_config_write_network (struct vty *vty, struct bgp *bgp,
destination = ntohl (p->u.prefix4.s_addr);
masklen2ip (p->prefixlen, &netmask);
- vty_out (vty, " network %s",
- inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
-
- if ((IN_CLASSC (destination) && p->prefixlen == 24)
- || (IN_CLASSB (destination) && p->prefixlen == 16)
- || (IN_CLASSA (destination) && p->prefixlen == 8)
- || p->u.prefix4.s_addr == 0)
- {
- /* Natural mask is not display. */
- }
- else
- vty_out (vty, " mask %s", inet_ntoa (netmask));
+ vty_out (vty, " network %s mask %s",
+ inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
+ inet_ntoa (netmask));
}
else
{
@@ -11773,12 +12507,15 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_ip_bgp_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
@@ -11804,6 +12541,11 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
@@ -11822,6 +12564,7 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
@@ -11839,20 +12582,28 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
/* Restricted node: VIEW_NODE - (set of dangerous commands) */
install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
@@ -11865,6 +12616,11 @@ bgp_route_init (void)
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
@@ -11874,18 +12630,25 @@ bgp_route_init (void)
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
@@ -11911,6 +12674,11 @@ bgp_route_init (void)
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
@@ -11929,6 +12697,7 @@ bgp_route_init (void)
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
@@ -11946,13 +12715,19 @@ bgp_route_init (void)
install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
/* BGP dampening clear commands */
install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
@@ -11991,10 +12766,13 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_bgp_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
install_element (VIEW_NODE, &show_bgp_route_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
install_element (VIEW_NODE, &show_bgp_prefix_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
install_element (VIEW_NODE, &show_bgp_regexp_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
@@ -12040,8 +12818,11 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
install_element (VIEW_NODE, &show_bgp_view_cmd);
install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
install_element (VIEW_NODE, &show_bgp_view_route_cmd);
@@ -12061,16 +12842,21 @@ bgp_route_init (void)
install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
+ install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
/* Restricted:
* VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
*/
install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
@@ -12088,7 +12874,9 @@ bgp_route_init (void)
install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
@@ -12096,14 +12884,19 @@ bgp_route_init (void)
install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
install_element (ENABLE_NODE, &show_bgp_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
install_element (ENABLE_NODE, &show_bgp_route_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
@@ -12149,8 +12942,11 @@ bgp_route_init (void)
install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
install_element (ENABLE_NODE, &show_bgp_view_cmd);
install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
@@ -12170,8 +12966,11 @@ bgp_route_init (void)
install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
+ install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
/* Statistics */
install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 88be52e2..959f45c6 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -6864,6 +6864,16 @@ DEFUN (show_ip_bgp_ipv4_summary,
return bgp_show_summary_vty (vty, NULL, AFI_IP, SAFI_UNICAST);
}
+ALIAS (show_ip_bgp_ipv4_summary,
+ show_bgp_ipv4_safi_summary_cmd,
+ "show bgp ipv4 (unicast|multicast) summary",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Summary of BGP neighbor status\n")
+
DEFUN (show_ip_bgp_instance_ipv4_summary,
show_ip_bgp_instance_ipv4_summary_cmd,
"show ip bgp view WORD ipv4 (unicast|multicast) summary",
@@ -6883,6 +6893,18 @@ DEFUN (show_ip_bgp_instance_ipv4_summary,
return bgp_show_summary_vty (vty, argv[0], AFI_IP, SAFI_UNICAST);
}
+ALIAS (show_ip_bgp_instance_ipv4_summary,
+ show_bgp_instance_ipv4_safi_summary_cmd,
+ "show bgp view WORD ipv4 (unicast|multicast) summary",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "View name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Summary of BGP neighbor status\n")
+
DEFUN (show_ip_bgp_vpnv4_all_summary,
show_ip_bgp_vpnv4_all_summary_cmd,
"show ip bgp vpnv4 all summary",
@@ -6961,6 +6983,40 @@ ALIAS (show_bgp_instance_summary,
"Address family\n"
"Summary of BGP neighbor status\n")
+DEFUN (show_bgp_ipv6_safi_summary,
+ show_bgp_ipv6_safi_summary_cmd,
+ "show bgp ipv6 (unicast|multicast) summary",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Summary of BGP neighbor status\n")
+{
+ if (strncmp (argv[0], "m", 1) == 0)
+ return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_MULTICAST);
+
+ return bgp_show_summary_vty (vty, NULL, AFI_IP6, SAFI_UNICAST);
+}
+
+DEFUN (show_bgp_instance_ipv6_safi_summary,
+ show_bgp_instance_ipv6_safi_summary_cmd,
+ "show bgp view WORD ipv6 (unicast|multicast) summary",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "View name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Summary of BGP neighbor status\n")
+{
+ if (strncmp (argv[1], "m", 1) == 0)
+ return bgp_show_summary_vty (vty, argv[0], AFI_IP6, SAFI_MULTICAST);
+
+ return bgp_show_summary_vty (vty, argv[0], AFI_IP6, SAFI_UNICAST);
+}
+
/* old command */
DEFUN (show_ipv6_bgp_summary,
show_ipv6_bgp_summary_cmd,
@@ -8162,6 +8218,41 @@ DEFUN (show_ip_bgp_instance_ipv4_rsclient_summary,
return bgp_show_rsclient_summary_vty (vty, argv[0], AFI_IP, SAFI_UNICAST);
}
+DEFUN (show_bgp_instance_ipv4_safi_rsclient_summary,
+ show_bgp_instance_ipv4_safi_rsclient_summary_cmd,
+ "show bgp view WORD ipv4 (unicast|multicast) rsclient summary",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "View name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Clients\n"
+ "Summary of all Route Server Clients\n")
+{
+ safi_t safi;
+
+ if (argc == 2) {
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ return bgp_show_rsclient_summary_vty (vty, argv[0], AFI_IP, safi);
+ } else {
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ return bgp_show_rsclient_summary_vty (vty, NULL, AFI_IP, safi);
+ }
+}
+
+ALIAS (show_bgp_instance_ipv4_safi_rsclient_summary,
+ show_bgp_ipv4_safi_rsclient_summary_cmd,
+ "show bgp ipv4 (unicast|multicast) rsclient summary",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Clients\n"
+ "Summary of all Route Server Clients\n")
+
#ifdef HAVE_IPV6
DEFUN (show_bgp_rsclient_summary,
show_bgp_rsclient_summary_cmd,
@@ -8206,61 +8297,56 @@ ALIAS (show_bgp_instance_rsclient_summary,
"Address family\n"
"Information about Route Server Clients\n"
"Summary of all Route Server Clients\n")
-#endif /* HAVE IPV6 */
-
-/* Redistribute VTY commands. */
-/* Utility function to convert user input route type string to route
- type. */
-static int
-bgp_str2route_type (int afi, const char *str)
+DEFUN (show_bgp_instance_ipv6_safi_rsclient_summary,
+ show_bgp_instance_ipv6_safi_rsclient_summary_cmd,
+ "show bgp view WORD ipv6 (unicast|multicast) rsclient summary",
+ SHOW_STR
+ BGP_STR
+ "BGP view\n"
+ "View name\n"
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Clients\n"
+ "Summary of all Route Server Clients\n")
{
- if (! str)
- return 0;
+ safi_t safi;
- if (afi == AFI_IP)
- {
- if (strncmp (str, "k", 1) == 0)
- return ZEBRA_ROUTE_KERNEL;
- else if (strncmp (str, "c", 1) == 0)
- return ZEBRA_ROUTE_CONNECT;
- else if (strncmp (str, "s", 1) == 0)
- return ZEBRA_ROUTE_STATIC;
- else if (strncmp (str, "r", 1) == 0)
- return ZEBRA_ROUTE_RIP;
- else if (strncmp (str, "o", 1) == 0)
- return ZEBRA_ROUTE_OSPF;
- }
- if (afi == AFI_IP6)
- {
- if (strncmp (str, "k", 1) == 0)
- return ZEBRA_ROUTE_KERNEL;
- else if (strncmp (str, "c", 1) == 0)
- return ZEBRA_ROUTE_CONNECT;
- else if (strncmp (str, "s", 1) == 0)
- return ZEBRA_ROUTE_STATIC;
- else if (strncmp (str, "r", 1) == 0)
- return ZEBRA_ROUTE_RIPNG;
- else if (strncmp (str, "o", 1) == 0)
- return ZEBRA_ROUTE_OSPF6;
- }
- return 0;
+ if (argc == 2) {
+ safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ return bgp_show_rsclient_summary_vty (vty, argv[0], AFI_IP6, safi);
+ } else {
+ safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
+ return bgp_show_rsclient_summary_vty (vty, NULL, AFI_IP6, safi);
+ }
}
+ALIAS (show_bgp_instance_ipv6_safi_rsclient_summary,
+ show_bgp_ipv6_safi_rsclient_summary_cmd,
+ "show bgp ipv6 (unicast|multicast) rsclient summary",
+ SHOW_STR
+ BGP_STR
+ "Address family\n"
+ "Address Family modifier\n"
+ "Address Family modifier\n"
+ "Information about Route Server Clients\n"
+ "Summary of all Route Server Clients\n")
+
+#endif /* HAVE IPV6 */
+
+/* Redistribute VTY commands. */
+
DEFUN (bgp_redistribute_ipv4,
bgp_redistribute_ipv4_cmd,
- "redistribute (connected|kernel|ospf|rip|static)",
+ "redistribute " QUAGGA_IP_REDIST_STR_BGPD,
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n")
+ QUAGGA_IP_REDIST_HELP_STR_BGPD)
{
int type;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8270,20 +8356,16 @@ DEFUN (bgp_redistribute_ipv4,
DEFUN (bgp_redistribute_ipv4_rmap,
bgp_redistribute_ipv4_rmap_cmd,
- "redistribute (connected|kernel|ospf|rip|static) route-map WORD",
+ "redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n")
{
int type;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8295,21 +8377,17 @@ DEFUN (bgp_redistribute_ipv4_rmap,
DEFUN (bgp_redistribute_ipv4_metric,
bgp_redistribute_ipv4_metric_cmd,
- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
+ "redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295>",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n")
{
int type;
u_int32_t metric;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8322,13 +8400,9 @@ DEFUN (bgp_redistribute_ipv4_metric,
DEFUN (bgp_redistribute_ipv4_rmap_metric,
bgp_redistribute_ipv4_rmap_metric_cmd,
- "redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
+ "redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n"
"Metric for redistributed routes\n"
@@ -8337,8 +8411,8 @@ DEFUN (bgp_redistribute_ipv4_rmap_metric,
int type;
u_int32_t metric;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8352,13 +8426,9 @@ DEFUN (bgp_redistribute_ipv4_rmap_metric,
DEFUN (bgp_redistribute_ipv4_metric_rmap,
bgp_redistribute_ipv4_metric_rmap_cmd,
- "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
+ "redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n"
"Route map reference\n"
@@ -8367,8 +8437,8 @@ DEFUN (bgp_redistribute_ipv4_metric_rmap,
int type;
u_int32_t metric;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8382,19 +8452,15 @@ DEFUN (bgp_redistribute_ipv4_metric_rmap,
DEFUN (no_bgp_redistribute_ipv4,
no_bgp_redistribute_ipv4_cmd,
- "no redistribute (connected|kernel|ospf|rip|static)",
+ "no redistribute " QUAGGA_IP_REDIST_STR_BGPD,
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n")
+ QUAGGA_IP_REDIST_HELP_STR_BGPD)
{
int type;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8405,21 +8471,17 @@ DEFUN (no_bgp_redistribute_ipv4,
DEFUN (no_bgp_redistribute_ipv4_rmap,
no_bgp_redistribute_ipv4_rmap_cmd,
- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD",
+ "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n")
{
int type;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8431,21 +8493,17 @@ DEFUN (no_bgp_redistribute_ipv4_rmap,
DEFUN (no_bgp_redistribute_ipv4_metric,
no_bgp_redistribute_ipv4_metric_cmd,
- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>",
+ "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295>",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n")
{
int type;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8457,14 +8515,10 @@ DEFUN (no_bgp_redistribute_ipv4_metric,
DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
no_bgp_redistribute_ipv4_rmap_metric_cmd,
- "no redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>",
+ "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n"
"Metric for redistributed routes\n"
@@ -8472,8 +8526,8 @@ DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
{
int type;
- type = bgp_str2route_type (AFI_IP, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8486,14 +8540,10 @@ DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
no_bgp_redistribute_ipv4_metric_rmap_cmd,
- "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD",
+ "no redistribute " QUAGGA_IP_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n"
+ QUAGGA_IP_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n"
"Route map reference\n"
@@ -8502,18 +8552,14 @@ ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
#ifdef HAVE_IPV6
DEFUN (bgp_redistribute_ipv6,
bgp_redistribute_ipv6_cmd,
- "redistribute (connected|kernel|ospf6|ripng|static)",
+ "redistribute " QUAGGA_IP6_REDIST_STR_BGPD,
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n")
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD)
{
int type;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8524,20 +8570,16 @@ DEFUN (bgp_redistribute_ipv6,
DEFUN (bgp_redistribute_ipv6_rmap,
bgp_redistribute_ipv6_rmap_cmd,
- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
+ "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n")
{
int type;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8549,21 +8591,17 @@ DEFUN (bgp_redistribute_ipv6_rmap,
DEFUN (bgp_redistribute_ipv6_metric,
bgp_redistribute_ipv6_metric_cmd,
- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
+ "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295>",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n")
{
int type;
u_int32_t metric;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8576,13 +8614,9 @@ DEFUN (bgp_redistribute_ipv6_metric,
DEFUN (bgp_redistribute_ipv6_rmap_metric,
bgp_redistribute_ipv6_rmap_metric_cmd,
- "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
+ "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n"
"Metric for redistributed routes\n"
@@ -8591,8 +8625,8 @@ DEFUN (bgp_redistribute_ipv6_rmap_metric,
int type;
u_int32_t metric;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8606,13 +8640,9 @@ DEFUN (bgp_redistribute_ipv6_rmap_metric,
DEFUN (bgp_redistribute_ipv6_metric_rmap,
bgp_redistribute_ipv6_metric_rmap_cmd,
- "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
+ "redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n"
"Route map reference\n"
@@ -8621,8 +8651,8 @@ DEFUN (bgp_redistribute_ipv6_metric_rmap,
int type;
u_int32_t metric;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8636,19 +8666,15 @@ DEFUN (bgp_redistribute_ipv6_metric_rmap,
DEFUN (no_bgp_redistribute_ipv6,
no_bgp_redistribute_ipv6_cmd,
- "no redistribute (connected|kernel|ospf6|ripng|static)",
+ "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD,
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n")
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD)
{
int type;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8659,21 +8685,17 @@ DEFUN (no_bgp_redistribute_ipv6,
DEFUN (no_bgp_redistribute_ipv6_rmap,
no_bgp_redistribute_ipv6_rmap_cmd,
- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD",
+ "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n")
{
int type;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8685,21 +8707,17 @@ DEFUN (no_bgp_redistribute_ipv6_rmap,
DEFUN (no_bgp_redistribute_ipv6_metric,
no_bgp_redistribute_ipv6_metric_cmd,
- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>",
+ "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295>",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n")
{
int type;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8711,14 +8729,10 @@ DEFUN (no_bgp_redistribute_ipv6_metric,
DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
no_bgp_redistribute_ipv6_rmap_metric_cmd,
- "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
+ "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " route-map WORD metric <0-4294967295>",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Route map reference\n"
"Pointer to route-map entries\n"
"Metric for redistributed routes\n"
@@ -8726,8 +8740,8 @@ DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
{
int type;
- type = bgp_str2route_type (AFI_IP6, argv[0]);
- if (! type)
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_BGP)
{
vty_out (vty, "%% Invalid route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -8740,14 +8754,10 @@ DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
ALIAS (no_bgp_redistribute_ipv6_rmap_metric,
no_bgp_redistribute_ipv6_metric_rmap_cmd,
- "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD",
+ "no redistribute " QUAGGA_IP6_REDIST_STR_BGPD " metric <0-4294967295> route-map WORD",
NO_STR
"Redistribute information from another routing protocol\n"
- "Connected\n"
- "Kernel routes\n"
- "Open Shurtest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n"
+ QUAGGA_IP6_REDIST_HELP_STR_BGPD
"Metric for redistributed routes\n"
"Default metric\n"
"Route map reference\n"
@@ -9752,38 +9762,50 @@ bgp_vty_init (void)
install_element (VIEW_NODE, &show_ip_bgp_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_instance_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_instance_ipv4_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_instance_ipv4_safi_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd);
#ifdef HAVE_IPV6
install_element (VIEW_NODE, &show_bgp_summary_cmd);
install_element (VIEW_NODE, &show_bgp_instance_summary_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_summary_cmd);
install_element (VIEW_NODE, &show_bgp_instance_ipv6_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_instance_ipv6_safi_summary_cmd);
#endif /* HAVE_IPV6 */
install_element (RESTRICTED_NODE, &show_ip_bgp_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_instance_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_instance_ipv4_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_instance_ipv4_safi_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd);
#ifdef HAVE_IPV6
install_element (RESTRICTED_NODE, &show_bgp_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_instance_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_ipv6_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_safi_summary_cmd);
#endif /* HAVE_IPV6 */
install_element (ENABLE_NODE, &show_ip_bgp_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_instance_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_instance_ipv4_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_instance_ipv4_safi_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_summary_cmd);
#ifdef HAVE_IPV6
install_element (ENABLE_NODE, &show_bgp_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_instance_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_instance_ipv6_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_instance_ipv6_safi_summary_cmd);
#endif /* HAVE_IPV6 */
/* "show ip bgp neighbors" commands. */
@@ -9847,28 +9869,40 @@ bgp_vty_init (void)
install_element (VIEW_NODE, &show_ip_bgp_instance_rsclient_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_ipv4_rsclient_summary_cmd);
install_element (VIEW_NODE, &show_ip_bgp_instance_ipv4_rsclient_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_instance_ipv4_safi_rsclient_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_instance_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_ip_bgp_instance_ipv4_rsclient_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_instance_ipv4_safi_rsclient_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_instance_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_ipv4_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_instance_ipv4_rsclient_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_instance_ipv4_safi_rsclient_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_summary_cmd);
#ifdef HAVE_IPV6
install_element (VIEW_NODE, &show_bgp_rsclient_summary_cmd);
install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_summary_cmd);
install_element (VIEW_NODE, &show_bgp_instance_rsclient_summary_cmd);
install_element (VIEW_NODE, &show_bgp_instance_ipv6_rsclient_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_instance_ipv6_safi_rsclient_summary_cmd);
+ install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_instance_rsclient_summary_cmd);
install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_rsclient_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_instance_ipv6_safi_rsclient_summary_cmd);
+ install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_ipv6_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_instance_rsclient_summary_cmd);
install_element (ENABLE_NODE, &show_bgp_instance_ipv6_rsclient_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_instance_ipv6_safi_rsclient_summary_cmd);
+ install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_summary_cmd);
#endif /* HAVE_IPV6 */
/* "show ip bgp paths" commands. */
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index f3baeee0..d4f95745 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -432,6 +432,28 @@ if_lookup_by_ipv4_exact (struct in_addr *addr)
return NULL;
}
+static int
+if_get_ipv4 (struct interface *ifp, struct in_addr *addr)
+{
+ struct listnode *cnode;
+ struct connected *connected;
+ struct prefix *cp;
+ int hit = 0;
+
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
+ {
+ cp = connected->address;
+
+ if (cp->family == AF_INET)
+ if (!hit || ntohl(cp->u.prefix4.s_addr) < ntohl(addr->s_addr))
+ {
+ memcpy (addr, &cp->u.prefix4, IPV4_MAX_BYTELEN);
+ hit = 1;
+ }
+ }
+ return hit;
+}
+
#ifdef HAVE_IPV6
struct interface *
if_lookup_by_ipv6 (struct in6_addr *addr)
@@ -586,7 +608,8 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
struct interface *direct = NULL;
/* IPv4 nexthop. I don't care about it. */
- if (peer->local_id.s_addr)
+ ret = if_get_ipv4 (ifp, &nexthop->v4);
+ if (!ret && peer->local_id.s_addr)
nexthop->v4 = peer->local_id;
/* Global address*/
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 882fe37c..a03025f6 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -2257,6 +2257,9 @@ peer_change_action (struct peer *peer, afi_t afi, safi_t safi,
if (CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP))
return;
+ if (peer->status != Established)
+ return;
+
if (type == peer_change_reset)
bgp_notify_send (peer, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_CONFIG_CHANGE);
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index a5afaedc..77c26646 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -616,6 +616,9 @@ struct bgp_nlri
#define BGP_ATTR_AS4_AGGREGATOR 18
#define BGP_ATTR_AS_PATHLIMIT 21
+/* BGP attribute 255, "development". Used in dumps for extended information. */
+#define BGP_ATTR_QUAGGA_DUMPEXT 255
+
/* BGP update origin. */
#define BGP_ORIGIN_IGP 0
#define BGP_ORIGIN_EGP 1
@@ -736,7 +739,9 @@ struct bgp_nlri
/* Default configuration settings for bgpd. */
#define BGP_VTY_PORT 2605
-#define BGP_DEFAULT_CONFIG "bgpd.conf"
+#define BGP_CONFIG_NAME "bgpd.conf"
+#define BGP_PID_NAME "bgpd.pid"
+#define BGP_VTY_NAME "bgpd.vty"
/* Check AS path loop when we send NLRI. */
/* #define BGP_SEND_ASPATH_CHECK */
diff --git a/configure.ac b/configure.ac
index 9c47b5b4..d53c4c56 100755
--- a/configure.ac
+++ b/configure.ac
@@ -8,7 +8,7 @@
## $Id$
AC_PREREQ(2.53)
-AC_INIT(Quagga, 0.99.15, [http://bugzilla.quagga.net])
+AC_INIT(Quagga, [1.1.0-dn42.11], [http://bugzilla.quagga.net])
AC_CONFIG_SRCDIR(lib/zebra.h)
AC_CONFIG_MACRO_DIR([m4])
@@ -202,6 +202,8 @@ AC_ARG_ENABLE(watchquagga,
[ --disable-watchquagga do not build watchquagga])
AC_ARG_ENABLE(isisd,
[ --enable-isisd build isisd])
+AC_ARG_ENABLE(pimd,
+[ --enable-pimd build pimd])
AC_ARG_ENABLE(solaris,
[ --enable-solaris build solaris])
AC_ARG_ENABLE(bgp-announce,
@@ -666,11 +668,9 @@ dnl ----------------------------
AC_FUNC_CHOWN
AC_FUNC_FNMATCH
AC_FUNC_FORK
-AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_STRFTIME
-AC_FUNC_REALLOC
AC_FUNC_STAT
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRFTIME
@@ -782,15 +782,18 @@ AC_SUBST(OTHER_METHOD)
dnl --------------------------
dnl Determine IS-IS I/O method
dnl --------------------------
+AC_DEFINE(ISIS_METHOD_PFPACKET, 1, [ constant value for isis method pfpacket ])
+AC_DEFINE(ISIS_METHOD_DLPI, 2, [ constant value for isis method dlpi ])
+AC_DEFINE(ISIS_METHOD_BPF, 3, [ constant value for isis method bpf ])
AC_CHECK_HEADER(net/bpf.h)
AC_CHECK_HEADER(sys/dlpi.h)
AC_MSG_CHECKING(zebra IS-IS I/O method)
if test x"$opsys" = x"gnu-linux"; then
AC_MSG_RESULT(pfpacket)
- ISIS_METHOD=isis_pfpacket.o
+ ISIS_METHOD_MACRO="ISIS_METHOD_PFPACKET"
elif test x"$opsys" = x"sol2-6" -o x"$opsys" = x"sol8"; then
AC_MSG_RESULT(DLPI)
- ISIS_METHOD="isis_dlpi.o"
+ ISIS_METHOD_MACRO="ISIS_METHOD_DLPI"
else
if test $ac_cv_header_net_bpf_h = no; then
if test $ac_cv_header_sys_dlpi_h = no; then
@@ -800,13 +803,13 @@ else
else
AC_MSG_RESULT(DLPI)
fi
- ISIS_METHOD="isis_dlpi.o"
+ ISIS_METHOD_MACRO="ISIS_METHOD_DLPI"
else
AC_MSG_RESULT(BPF)
- ISIS_METHOD="isis_bpf.o"
+ ISIS_METHOD_MACRO="ISIS_METHOD_BPF"
fi
fi
-AC_SUBST(ISIS_METHOD)
+AC_DEFINE_UNQUOTED(ISIS_METHOD, $ISIS_METHOD_MACRO, [ selected method for isis, == one of the constants ])
dnl ------------------------------------
dnl check for broken CMSG_FIRSTHDR macro
@@ -970,10 +973,18 @@ dnl -----------------------------
dnl check ipforward detect method
dnl -----------------------------
AC_CACHE_CHECK([ipforward method], [quagga_cv_ipforward_method],
-[for quagga_cv_ipforward_method in /proc/net/snmp /dev/ip /dev/null;
-do
- test x`ls $quagga_cv_ipforward_method 2>/dev/null` = x"$quagga_cv_ipforward_method" && break
-done
+[if test x$cross_compiling = xyes; then
+ if test x"$opsys" = x"gnu-linux"; then
+ quagga_cv_ipforward_method=/proc/net/snmp
+ else
+ quagga_cv_ipforward_method=/dev/ip
+ fi
+else
+ for quagga_cv_ipforward_method in /proc/net/snmp /dev/ip /dev/null;
+ do
+ test x`ls $quagga_cv_ipforward_method 2>/dev/null` = x"$quagga_cv_ipforward_method" && break
+ done
+fi
case $quagga_cv_ipforward_method in
"/proc/net/snmp") quagga_cv_ipforward_method="proc";;
"/dev/ip")
@@ -1227,6 +1238,12 @@ case "${enable_isisd}" in
* ) ;;
esac
+case "${enable_pimd}" in
+ "yes") PIMD="pimd";;
+ "no" ) PIMD="";;
+ * ) ;;
+esac
+
# XXX Perhaps auto-enable on Solaris, but that's messy for cross builds.
case "${enable_solaris}" in
"yes") SOLARIS="solaris";;
@@ -1249,6 +1266,7 @@ AC_SUBST(OSPFD)
AC_SUBST(OSPF6D)
AC_SUBST(WATCHQUAGGA)
AC_SUBST(ISISD)
+AC_SUBST(PIMD)
AC_SUBST(SOLARIS)
AC_SUBST(VTYSH)
AC_SUBST(INCLUDES)
@@ -1313,10 +1331,12 @@ dnl sockaddr and netinet checks
dnl ---------------------------
AC_CHECK_TYPES([struct sockaddr, struct sockaddr_in,
struct sockaddr_in6, struct sockaddr_un, struct sockaddr_dl,
- socklen_t,
+ socklen_t, struct vifctl, struct mfcctl, struct sioc_sg_req,
+ vifi_t, struct sioc_vif_req, struct igmpmsg,
struct ifaliasreq, struct if6_aliasreq, struct in6_aliasreq,
struct nd_opt_adv_interval, struct rt_addrinfo,
- struct nd_opt_homeagent_info, struct nd_opt_adv_interval],
+ struct nd_opt_homeagent_info, struct nd_opt_adv_interval,
+ struct nd_opt_rdnss],
[], [], QUAGGA_INCLUDES)
AC_CHECK_MEMBERS([struct sockaddr.sa_len,
@@ -1341,6 +1361,45 @@ AC_CHECK_TYPES([struct in_pktinfo],
AC_MSG_ERROR(['IRDP requires in_pktinfo at the moment!'])
fi], [QUAGGA_INCLUDES])
+dnl -----------------------
+dnl checking for IP_PKTINFO
+dnl -----------------------
+AC_MSG_CHECKING(for IP_PKTINFO)
+AC_TRY_COMPILE([#include <netdb.h>], [
+ int opt = IP_PKTINFO;
+], [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_IP_PKTINFO, 1, [Have IP_PKTINFO])
+], [
+ AC_MSG_RESULT(no)
+])
+
+dnl ---------------------------
+dnl checking for IP_RECVDSTADDR
+dnl ---------------------------
+AC_MSG_CHECKING(for IP_RECVDSTADDR)
+AC_TRY_COMPILE([#include <netinet/in.h>], [
+ int opt = IP_RECVDSTADDR;
+], [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_IP_RECVDSTADDR, 1, [Have IP_RECVDSTADDR])
+], [
+ AC_MSG_RESULT(no)
+])
+
+dnl ----------------------
+dnl checking for IP_RECVIF
+dnl ----------------------
+AC_MSG_CHECKING(for IP_RECVIF)
+AC_TRY_COMPILE([#include <netinet/in.h>], [
+ int opt = IP_RECVIF;
+], [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_IP_RECVIF, 1, [Have IP_RECVIF])
+], [
+ AC_MSG_RESULT(no)
+])
+
dnl --------------------------------------
dnl checking for getrusage struct and call
dnl --------------------------------------
@@ -1486,22 +1545,8 @@ fi
AC_MSG_RESULT(${quagga_statedir})
AC_SUBST(quagga_statedir)
-AC_DEFINE_UNQUOTED(PATH_ZEBRA_PID, "$quagga_statedir/zebra.pid",zebra PID)
-AC_DEFINE_UNQUOTED(PATH_RIPD_PID, "$quagga_statedir/ripd.pid",ripd PID)
-AC_DEFINE_UNQUOTED(PATH_RIPNGD_PID, "$quagga_statedir/ripngd.pid",ripngd PID)
-AC_DEFINE_UNQUOTED(PATH_BGPD_PID, "$quagga_statedir/bgpd.pid",bgpd PID)
-AC_DEFINE_UNQUOTED(PATH_OSPFD_PID, "$quagga_statedir/ospfd.pid",ospfd PID)
-AC_DEFINE_UNQUOTED(PATH_OSPF6D_PID, "$quagga_statedir/ospf6d.pid",ospf6d PID)
-AC_DEFINE_UNQUOTED(PATH_ISISD_PID, "$quagga_statedir/isisd.pid",isisd PID)
+AC_DEFINE_UNQUOTED(PATH_STATE, "$quagga_statedir",zebra state path)
AC_DEFINE_UNQUOTED(PATH_WATCHQUAGGA_PID, "$quagga_statedir/watchquagga.pid",watchquagga PID)
-AC_DEFINE_UNQUOTED(ZEBRA_SERV_PATH, "$quagga_statedir/zserv.api",zebra api socket)
-AC_DEFINE_UNQUOTED(ZEBRA_VTYSH_PATH, "$quagga_statedir/zebra.vty",zebra vty socket)
-AC_DEFINE_UNQUOTED(RIP_VTYSH_PATH, "$quagga_statedir/ripd.vty",rip vty socket)
-AC_DEFINE_UNQUOTED(RIPNG_VTYSH_PATH, "$quagga_statedir/ripngd.vty",ripng vty socket)
-AC_DEFINE_UNQUOTED(BGP_VTYSH_PATH, "$quagga_statedir/bgpd.vty",bgpd vty socket)
-AC_DEFINE_UNQUOTED(OSPF_VTYSH_PATH, "$quagga_statedir/ospfd.vty",ospfd vty socket)
-AC_DEFINE_UNQUOTED(OSPF6_VTYSH_PATH, "$quagga_statedir/ospf6d.vty",ospf6d vty socket)
-AC_DEFINE_UNQUOTED(ISIS_VTYSH_PATH, "$quagga_statedir/isisd.vty",isisd vty socket)
AC_DEFINE_UNQUOTED(DAEMON_VTY_DIR, "$quagga_statedir",daemon vty directory)
dnl -------------------------------
@@ -1527,6 +1572,7 @@ AC_CONFIG_FILES([Makefile lib/Makefile zebra/Makefile ripd/Makefile
ripngd/Makefile bgpd/Makefile ospfd/Makefile watchquagga/Makefile
ospf6d/Makefile isisd/Makefile vtysh/Makefile doc/Makefile
ospfclient/Makefile tests/Makefile m4/Makefile redhat/Makefile
+ pimd/Makefile
pkgsrc/Makefile
redhat/quagga.spec
lib/version.h
diff --git a/doc/.gitignore b/doc/.gitignore
index ed527fcb..5071f987 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -6,6 +6,7 @@ quagga.info-*
zebra.html
defines.texi
version.texi
+texinfo.tex
quagga.html
quagga.info
*.pdf
diff --git a/doc/Makefile.am b/doc/Makefile.am
index c3016b2b..5c041572 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -61,7 +61,7 @@ quagga_TEXINFOS = appendix.texi basic.texi bgpd.texi filter.texi install.texi \
.dia.png:
$(DIATOPNG) "$@" $<
-man_MANS = vtysh.1 bgpd.8 ospf6d.8 ospfd.8 ripd.8 ripngd.8 zebra.8 isisd.8
+man_MANS = vtysh.1 bgpd.8 ospf6d.8 ospfd.8 ripd.8 ripngd.8 zebra.8 isisd.8 pimd.8
EXTRA_DIST = BGP-TypeCode draft-zebra-00.ms draft-zebra-00.txt $(man_MANS) \
mpls/ChangeLog.opaque.txt mpls/cli_summary.txt \
diff --git a/doc/install.texi b/doc/install.texi
index 16e29c99..fbc2401d 100644
--- a/doc/install.texi
+++ b/doc/install.texi
@@ -267,6 +267,7 @@ bgpd 2605/tcp # BGPd vty
ospf6d 2606/tcp # OSPF6d vty
ospfapi 2607/tcp # ospfapi
isisd 2608/tcp # ISISd vty
+pimd 2611/tcp # PIMd vty
@end example
If you use a FreeBSD newer than 2.2.8, the above entries are already
diff --git a/doc/ipv6.texi b/doc/ipv6.texi
index a78a92fe..519b7798 100644
--- a/doc/ipv6.texi
+++ b/doc/ipv6.texi
@@ -157,15 +157,25 @@ Set default router preference in IPv6 router advertisements per RFC4191.
Default: medium
@end deffn
+@deffn {Interface Command} {ipv6 nd rdnss ipv6prefix [lifetime]} {} Include
+RDNSS options to advertise recursive DNS server addresses. Additionally a
+maximum lifetime (in seconds) can be specified to limit the lifetime of this
+option. The valid range is between @code{<0-4294967295>} where 0 means that the
+RDNSS address must no longer be used. The default lifetime - without explicitly
+specify a lifetime - is unlimited.
+@end deffn
+
@example
@group
interface eth0
no ipv6 nd suppress-ra
ipv6 nd prefix 2001:0DB8:5009::/64
+ ipv6 nd rdnss 2001:0DB8:5009::1
@end group
@end example
For more information see @cite{RFC2462 (IPv6 Stateless Address Autoconfiguration)}
, @cite{RFC2461 (Neighbor Discovery for IP Version 6 (IPv6))}
, @cite{RFC3775 (Mobility Support in IPv6 (Mobile IPv6))}
+, @cite{RFC5006 (IPv6 Router Advertisement Option for DNS Configuration)}
and @cite{RFC4191 (Default Router Preferences and More-Specific Routes)}.
diff --git a/doc/pimd.8 b/doc/pimd.8
new file mode 100644
index 00000000..b26b1128
--- /dev/null
+++ b/doc/pimd.8
@@ -0,0 +1,108 @@
+.TH PIM 8 "10 December 2008" "Quagga PIM daemon" "Version 0.99.11"
+.SH NAME
+pimd \- a PIM routing for use with Quagga Routing Suite.
+.SH SYNOPSIS
+.B pimd
+[
+.B \-dhvZ
+] [
+.B \-f
+.I config-file
+] [
+.B \-i
+.I pid-file
+] [
+.B \-P
+.I port-number
+] [
+.B \-A
+.I vty-address
+] [
+.B \-u
+.I user
+] [
+.B \-g
+.I group
+]
+.SH DESCRIPTION
+.B pimd
+is a protocol-independent multicast component that works with the
+.B Quagga
+Routing Suite.
+.SH OPTIONS
+Options available for the
+.B pimd
+command:
+.TP
+\fB\-d\fR, \fB\-\-daemon\fR
+Runs in daemon mode, forking and exiting from tty.
+.TP
+\fB\-f\fR, \fB\-\-config-file \fR\fIconfig-file\fR
+Specifies the config file to use for startup. If not specified this
+option will likely default to \fB\fI/usr/local/etc/pimd.conf\fR.
+.TP
+\fB\-g\fR, \fB\-\-group \fR\fIgroup\fR
+Specify the group to run as. Default is \fIquagga\fR.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+A brief message.
+.TP
+\fB\-i\fR, \fB\-\-pid_file \fR\fIpid-file\fR
+When pimd starts its process identifier is written to
+\fB\fIpid-file\fR. The init system uses the recorded PID to stop or
+restart pimd. The likely default is \fB\fI/var/run/pimd.pid\fR.
+.TP
+\fB\-P\fR, \fB\-\-vty_port \fR\fIport-number\fR
+Specify the port that the pimd VTY will listen on. This defaults to
+2611, as specified in \fB\fI/etc/services\fR.
+.TP
+\fB\-A\fR, \fB\-\-vty_addr \fR\fIvty-address\fR
+Specify the address that the pimd VTY will listen on. Default is all
+interfaces.
+.TP
+\fB\-u\fR, \fB\-\-user \fR\fIuser\fR
+Specify the user to run as. Default is \fIquagga\fR.
+.TP
+\fB\-v\fR, \fB\-\-version\fR
+Print the version and exit.
+.TP
+\fB\-Z\fR, \fB\-\-debug_zclient\fR
+Enable logging information for zclient debugging.
+.SH FILES
+.TP
+.BI /usr/local/sbin/pimd
+The default location of the
+.B pimd
+binary.
+.TP
+.BI /usr/local/etc/pimd.conf
+The default location of the
+.B pimd
+config file.
+.TP
+.BI $(PWD)/pimd.log
+If the
+.B pimd
+process is config'd to output logs to a file, then you will find this
+file in the directory where you started \fBpimd\fR.
+.SH WARNING
+This man page is intended to be a quick reference for command line
+options.
+.SH DIAGNOSTICS
+The pimd process may log to standard output, to a VTY, to a log
+file, or through syslog to the system logs.
+.SH "SEE ALSO"
+.BR zebra (8),
+.BR vtysh (1)
+.SH BUGS
+\fBpimd\fR is in early development at the moment and is not ready for
+production use.
+
+.B pimd
+eats bugs for breakfast. If you have food for the maintainers try
+.BI http://savannah.nongnu.org/projects/qpimd
+.SH AUTHORS
+See
+.BI http://savannah.nongnu.org/projects/qpimd
+for an accurate list of authors.
+
diff --git a/doc/texinfo.tex b/doc/texinfo.tex
deleted file mode 100644
index 58bea4dd..00000000
--- a/doc/texinfo.tex
+++ /dev/null
@@ -1,7086 +0,0 @@
-% texinfo.tex -- TeX macros to handle Texinfo files.
-%
-% Load plain if necessary, i.e., if running under initex.
-\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
-%
-\def\texinfoversion{2005-01-30.17}
-%
-% Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
-% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software
-% Foundation, Inc.
-%
-% This texinfo.tex file is free software; you can redistribute it and/or
-% modify it under the terms of the GNU General Public License as
-% published by the Free Software Foundation; either version 2, or (at
-% your option) any later version.
-%
-% This texinfo.tex file is distributed in the hope that it will be
-% useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-% General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with this texinfo.tex file; see the file COPYING. If not, write
-% to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-% Boston, MA 02111-1307, USA.
-%
-% As a special exception, when this file is read by TeX when processing
-% a Texinfo source document, you may use the result without
-% restriction. (This has been our intent since Texinfo was invented.)
-%
-% Please try the latest version of texinfo.tex before submitting bug
-% reports; you can get the latest version from:
-% http://www.gnu.org/software/texinfo/ (the Texinfo home page), or
-% ftp://tug.org/tex/texinfo.tex
-% (and all CTAN mirrors, see http://www.ctan.org).
-% The texinfo.tex in any given distribution could well be out
-% of date, so if that's what you're using, please check.
-%
-% Send bug reports to bug-texinfo@gnu.org. Please include including a
-% complete document in each bug report with which we can reproduce the
-% problem. Patches are, of course, greatly appreciated.
-%
-% To process a Texinfo manual with TeX, it's most reliable to use the
-% texi2dvi shell script that comes with the distribution. For a simple
-% manual foo.texi, however, you can get away with this:
-% tex foo.texi
-% texindex foo.??
-% tex foo.texi
-% tex foo.texi
-% dvips foo.dvi -o # or whatever; this makes foo.ps.
-% The extra TeX runs get the cross-reference information correct.
-% Sometimes one run after texindex suffices, and sometimes you need more
-% than two; texi2dvi does it as many times as necessary.
-%
-% It is possible to adapt texinfo.tex for other languages, to some
-% extent. You can get the existing language-specific files from the
-% full Texinfo distribution.
-%
-% The GNU Texinfo home page is http://www.gnu.org/software/texinfo.
-
-
-\message{Loading texinfo [version \texinfoversion]:}
-
-% If in a .fmt file, print the version number
-% and turn on active characters that we couldn't do earlier because
-% they might have appeared in the input file name.
-\everyjob{\message{[Texinfo version \texinfoversion]}%
- \catcode`+=\active \catcode`\_=\active}
-
-\message{Basics,}
-\chardef\other=12
-
-% We never want plain's \outer definition of \+ in Texinfo.
-% For @tex, we can use \tabalign.
-\let\+ = \relax
-
-% Save some plain tex macros whose names we will redefine.
-\let\ptexb=\b
-\let\ptexbullet=\bullet
-\let\ptexc=\c
-\let\ptexcomma=\,
-\let\ptexdot=\.
-\let\ptexdots=\dots
-\let\ptexend=\end
-\let\ptexequiv=\equiv
-\let\ptexexclam=\!
-\let\ptexfootnote=\footnote
-\let\ptexgtr=>
-\let\ptexhat=^
-\let\ptexi=\i
-\let\ptexindent=\indent
-\let\ptexinsert=\insert
-\let\ptexlbrace=\{
-\let\ptexless=<
-\let\ptexnewwrite\newwrite
-\let\ptexnoindent=\noindent
-\let\ptexplus=+
-\let\ptexrbrace=\}
-\let\ptexslash=\/
-\let\ptexstar=\*
-\let\ptext=\t
-
-% If this character appears in an error message or help string, it
-% starts a new line in the output.
-\newlinechar = `^^J
-
-% Use TeX 3.0's \inputlineno to get the line number, for better error
-% messages, but if we're using an old version of TeX, don't do anything.
-%
-\ifx\inputlineno\thisisundefined
- \let\linenumber = \empty % Pre-3.0.
-\else
- \def\linenumber{l.\the\inputlineno:\space}
-\fi
-
-% Set up fixed words for English if not already set.
-\ifx\putwordAppendix\undefined \gdef\putwordAppendix{Appendix}\fi
-\ifx\putwordChapter\undefined \gdef\putwordChapter{Chapter}\fi
-\ifx\putwordfile\undefined \gdef\putwordfile{file}\fi
-\ifx\putwordin\undefined \gdef\putwordin{in}\fi
-\ifx\putwordIndexIsEmpty\undefined \gdef\putwordIndexIsEmpty{(Index is empty)}\fi
-\ifx\putwordIndexNonexistent\undefined \gdef\putwordIndexNonexistent{(Index is nonexistent)}\fi
-\ifx\putwordInfo\undefined \gdef\putwordInfo{Info}\fi
-\ifx\putwordInstanceVariableof\undefined \gdef\putwordInstanceVariableof{Instance Variable of}\fi
-\ifx\putwordMethodon\undefined \gdef\putwordMethodon{Method on}\fi
-\ifx\putwordNoTitle\undefined \gdef\putwordNoTitle{No Title}\fi
-\ifx\putwordof\undefined \gdef\putwordof{of}\fi
-\ifx\putwordon\undefined \gdef\putwordon{on}\fi
-\ifx\putwordpage\undefined \gdef\putwordpage{page}\fi
-\ifx\putwordsection\undefined \gdef\putwordsection{section}\fi
-\ifx\putwordSection\undefined \gdef\putwordSection{Section}\fi
-\ifx\putwordsee\undefined \gdef\putwordsee{see}\fi
-\ifx\putwordSee\undefined \gdef\putwordSee{See}\fi
-\ifx\putwordShortTOC\undefined \gdef\putwordShortTOC{Short Contents}\fi
-\ifx\putwordTOC\undefined \gdef\putwordTOC{Table of Contents}\fi
-%
-\ifx\putwordMJan\undefined \gdef\putwordMJan{January}\fi
-\ifx\putwordMFeb\undefined \gdef\putwordMFeb{February}\fi
-\ifx\putwordMMar\undefined \gdef\putwordMMar{March}\fi
-\ifx\putwordMApr\undefined \gdef\putwordMApr{April}\fi
-\ifx\putwordMMay\undefined \gdef\putwordMMay{May}\fi
-\ifx\putwordMJun\undefined \gdef\putwordMJun{June}\fi
-\ifx\putwordMJul\undefined \gdef\putwordMJul{July}\fi
-\ifx\putwordMAug\undefined \gdef\putwordMAug{August}\fi
-\ifx\putwordMSep\undefined \gdef\putwordMSep{September}\fi
-\ifx\putwordMOct\undefined \gdef\putwordMOct{October}\fi
-\ifx\putwordMNov\undefined \gdef\putwordMNov{November}\fi
-\ifx\putwordMDec\undefined \gdef\putwordMDec{December}\fi
-%
-\ifx\putwordDefmac\undefined \gdef\putwordDefmac{Macro}\fi
-\ifx\putwordDefspec\undefined \gdef\putwordDefspec{Special Form}\fi
-\ifx\putwordDefvar\undefined \gdef\putwordDefvar{Variable}\fi
-\ifx\putwordDefopt\undefined \gdef\putwordDefopt{User Option}\fi
-\ifx\putwordDeffunc\undefined \gdef\putwordDeffunc{Function}\fi
-
-% In some macros, we cannot use the `\? notation---the left quote is
-% in some cases the escape char.
-\chardef\colonChar = `\:
-\chardef\commaChar = `\,
-\chardef\dotChar = `\.
-\chardef\exclamChar= `\!
-\chardef\questChar = `\?
-\chardef\semiChar = `\;
-\chardef\underChar = `\_
-
-\chardef\spaceChar = `\ %
-\chardef\spacecat = 10
-\def\spaceisspace{\catcode\spaceChar=\spacecat}
-
-% Ignore a token.
-%
-\def\gobble#1{}
-
-% The following is used inside several \edef's.
-\def\makecsname#1{\expandafter\noexpand\csname#1\endcsname}
-
-% Hyphenation fixes.
-\hyphenation{
- Flor-i-da Ghost-script Ghost-view Mac-OS Post-Script
- ap-pen-dix bit-map bit-maps
- data-base data-bases eshell fall-ing half-way long-est man-u-script
- man-u-scripts mini-buf-fer mini-buf-fers over-view par-a-digm
- par-a-digms rath-er rec-tan-gu-lar ro-bot-ics se-vere-ly set-up spa-ces
- spell-ing spell-ings
- stand-alone strong-est time-stamp time-stamps which-ever white-space
- wide-spread wrap-around
-}
-
-% Margin to add to right of even pages, to left of odd pages.
-\newdimen\bindingoffset
-\newdimen\normaloffset
-\newdimen\pagewidth \newdimen\pageheight
-
-% For a final copy, take out the rectangles
-% that mark overfull boxes (in case you have decided
-% that the text looks ok even though it passes the margin).
-%
-\def\finalout{\overfullrule=0pt}
-
-% @| inserts a changebar to the left of the current line. It should
-% surround any changed text. This approach does *not* work if the
-% change spans more than two lines of output. To handle that, we would
-% have adopt a much more difficult approach (putting marks into the main
-% vertical list for the beginning and end of each change).
-%
-\def\|{%
- % \vadjust can only be used in horizontal mode.
- \leavevmode
- %
- % Append this vertical mode material after the current line in the output.
- \vadjust{%
- % We want to insert a rule with the height and depth of the current
- % leading; that is exactly what \strutbox is supposed to record.
- \vskip-\baselineskip
- %
- % \vadjust-items are inserted at the left edge of the type. So
- % the \llap here moves out into the left-hand margin.
- \llap{%
- %
- % For a thicker or thinner bar, change the `1pt'.
- \vrule height\baselineskip width1pt
- %
- % This is the space between the bar and the text.
- \hskip 12pt
- }%
- }%
-}
-
-% Sometimes it is convenient to have everything in the transcript file
-% and nothing on the terminal. We don't just call \tracingall here,
-% since that produces some useless output on the terminal. We also make
-% some effort to order the tracing commands to reduce output in the log
-% file; cf. trace.sty in LaTeX.
-%
-\def\gloggingall{\begingroup \globaldefs = 1 \loggingall \endgroup}%
-\def\loggingall{%
- \tracingstats2
- \tracingpages1
- \tracinglostchars2 % 2 gives us more in etex
- \tracingparagraphs1
- \tracingoutput1
- \tracingmacros2
- \tracingrestores1
- \showboxbreadth\maxdimen \showboxdepth\maxdimen
- \ifx\eTeXversion\undefined\else % etex gives us more logging
- \tracingscantokens1
- \tracingifs1
- \tracinggroups1
- \tracingnesting2
- \tracingassigns1
- \fi
- \tracingcommands3 % 3 gives us more in etex
- \errorcontextlines16
-}%
-
-% add check for \lastpenalty to plain's definitions. If the last thing
-% we did was a \nobreak, we don't want to insert more space.
-%
-\def\smallbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\smallskipamount
- \removelastskip\penalty-50\smallskip\fi\fi}
-\def\medbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\medskipamount
- \removelastskip\penalty-100\medskip\fi\fi}
-\def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount
- \removelastskip\penalty-200\bigskip\fi\fi}
-
-% For @cropmarks command.
-% Do @cropmarks to get crop marks.
-%
-\newif\ifcropmarks
-\let\cropmarks = \cropmarkstrue
-%
-% Dimensions to add cropmarks at corners.
-% Added by P. A. MacKay, 12 Nov. 1986
-%
-\newdimen\outerhsize \newdimen\outervsize % set by the paper size routines
-\newdimen\cornerlong \cornerlong=1pc
-\newdimen\cornerthick \cornerthick=.3pt
-\newdimen\topandbottommargin \topandbottommargin=.75in
-
-% Main output routine.
-\chardef\PAGE = 255
-\output = {\onepageout{\pagecontents\PAGE}}
-
-\newbox\headlinebox
-\newbox\footlinebox
-
-% \onepageout takes a vbox as an argument. Note that \pagecontents
-% does insertions, but you have to call it yourself.
-\def\onepageout#1{%
- \ifcropmarks \hoffset=0pt \else \hoffset=\normaloffset \fi
- %
- \ifodd\pageno \advance\hoffset by \bindingoffset
- \else \advance\hoffset by -\bindingoffset\fi
- %
- % Do this outside of the \shipout so @code etc. will be expanded in
- % the headline as they should be, not taken literally (outputting ''code).
- \setbox\headlinebox = \vbox{\let\hsize=\pagewidth \makeheadline}%
- \setbox\footlinebox = \vbox{\let\hsize=\pagewidth \makefootline}%
- %
- {%
- % Have to do this stuff outside the \shipout because we want it to
- % take effect in \write's, yet the group defined by the \vbox ends
- % before the \shipout runs.
- %
- \escapechar = `\\ % use backslash in output files.
- \indexdummies % don't expand commands in the output.
- \normalturnoffactive % \ in index entries must not stay \, e.g., if
- % the page break happens to be in the middle of an example.
- \shipout\vbox{%
- % Do this early so pdf references go to the beginning of the page.
- \ifpdfmakepagedest \pdfdest name{\the\pageno} xyz\fi
- %
- \ifcropmarks \vbox to \outervsize\bgroup
- \hsize = \outerhsize
- \vskip-\topandbottommargin
- \vtop to0pt{%
- \line{\ewtop\hfil\ewtop}%
- \nointerlineskip
- \line{%
- \vbox{\moveleft\cornerthick\nstop}%
- \hfill
- \vbox{\moveright\cornerthick\nstop}%
- }%
- \vss}%
- \vskip\topandbottommargin
- \line\bgroup
- \hfil % center the page within the outer (page) hsize.
- \ifodd\pageno\hskip\bindingoffset\fi
- \vbox\bgroup
- \fi
- %
- \unvbox\headlinebox
- \pagebody{#1}%
- \ifdim\ht\footlinebox > 0pt
- % Only leave this space if the footline is nonempty.
- % (We lessened \vsize for it in \oddfootingxxx.)
- % The \baselineskip=24pt in plain's \makefootline has no effect.
- \vskip 2\baselineskip
- \unvbox\footlinebox
- \fi
- %
- \ifcropmarks
- \egroup % end of \vbox\bgroup
- \hfil\egroup % end of (centering) \line\bgroup
- \vskip\topandbottommargin plus1fill minus1fill
- \boxmaxdepth = \cornerthick
- \vbox to0pt{\vss
- \line{%
- \vbox{\moveleft\cornerthick\nsbot}%
- \hfill
- \vbox{\moveright\cornerthick\nsbot}%
- }%
- \nointerlineskip
- \line{\ewbot\hfil\ewbot}%
- }%
- \egroup % \vbox from first cropmarks clause
- \fi
- }% end of \shipout\vbox
- }% end of group with \normalturnoffactive
- \advancepageno
- \ifnum\outputpenalty>-20000 \else\dosupereject\fi
-}
-
-\newinsert\margin \dimen\margin=\maxdimen
-
-\def\pagebody#1{\vbox to\pageheight{\boxmaxdepth=\maxdepth #1}}
-{\catcode`\@ =11
-\gdef\pagecontents#1{\ifvoid\topins\else\unvbox\topins\fi
-% marginal hacks, juha@viisa.uucp (Juha Takala)
-\ifvoid\margin\else % marginal info is present
- \rlap{\kern\hsize\vbox to\z@{\kern1pt\box\margin \vss}}\fi
-\dimen@=\dp#1 \unvbox#1
-\ifvoid\footins\else\vskip\skip\footins\footnoterule \unvbox\footins\fi
-\ifr@ggedbottom \kern-\dimen@ \vfil \fi}
-}
-
-% Here are the rules for the cropmarks. Note that they are
-% offset so that the space between them is truly \outerhsize or \outervsize
-% (P. A. MacKay, 12 November, 1986)
-%
-\def\ewtop{\vrule height\cornerthick depth0pt width\cornerlong}
-\def\nstop{\vbox
- {\hrule height\cornerthick depth\cornerlong width\cornerthick}}
-\def\ewbot{\vrule height0pt depth\cornerthick width\cornerlong}
-\def\nsbot{\vbox
- {\hrule height\cornerlong depth\cornerthick width\cornerthick}}
-
-% Parse an argument, then pass it to #1. The argument is the rest of
-% the input line (except we remove a trailing comment). #1 should be a
-% macro which expects an ordinary undelimited TeX argument.
-%
-\def\parsearg{\parseargusing{}}
-\def\parseargusing#1#2{%
- \def\next{#2}%
- \begingroup
- \obeylines
- \spaceisspace
- #1%
- \parseargline\empty% Insert the \empty token, see \finishparsearg below.
-}
-
-{\obeylines %
- \gdef\parseargline#1^^M{%
- \endgroup % End of the group started in \parsearg.
- \argremovecomment #1\comment\ArgTerm%
- }%
-}
-
-% First remove any @comment, then any @c comment.
-\def\argremovecomment#1\comment#2\ArgTerm{\argremovec #1\c\ArgTerm}
-\def\argremovec#1\c#2\ArgTerm{\argcheckspaces#1\^^M\ArgTerm}
-
-% Each occurence of `\^^M' or `<space>\^^M' is replaced by a single space.
-%
-% \argremovec might leave us with trailing space, e.g.,
-% @end itemize @c foo
-% This space token undergoes the same procedure and is eventually removed
-% by \finishparsearg.
-%
-\def\argcheckspaces#1\^^M{\argcheckspacesX#1\^^M \^^M}
-\def\argcheckspacesX#1 \^^M{\argcheckspacesY#1\^^M}
-\def\argcheckspacesY#1\^^M#2\^^M#3\ArgTerm{%
- \def\temp{#3}%
- \ifx\temp\empty
- % We cannot use \next here, as it holds the macro to run;
- % thus we reuse \temp.
- \let\temp\finishparsearg
- \else
- \let\temp\argcheckspaces
- \fi
- % Put the space token in:
- \temp#1 #3\ArgTerm
-}
-
-% If a _delimited_ argument is enclosed in braces, they get stripped; so
-% to get _exactly_ the rest of the line, we had to prevent such situation.
-% We prepended an \empty token at the very beginning and we expand it now,
-% just before passing the control to \next.
-% (Similarily, we have to think about #3 of \argcheckspacesY above: it is
-% either the null string, or it ends with \^^M---thus there is no danger
-% that a pair of braces would be stripped.
-%
-% But first, we have to remove the trailing space token.
-%
-\def\finishparsearg#1 \ArgTerm{\expandafter\next\expandafter{#1}}
-
-% \parseargdef\foo{...}
-% is roughly equivalent to
-% \def\foo{\parsearg\Xfoo}
-% \def\Xfoo#1{...}
-%
-% Actually, I use \csname\string\foo\endcsname, ie. \\foo, as it is my
-% favourite TeX trick. --kasal, 16nov03
-
-\def\parseargdef#1{%
- \expandafter \doparseargdef \csname\string#1\endcsname #1%
-}
-\def\doparseargdef#1#2{%
- \def#2{\parsearg#1}%
- \def#1##1%
-}
-
-% Several utility definitions with active space:
-{
- \obeyspaces
- \gdef\obeyedspace{ }
-
- % Make each space character in the input produce a normal interword
- % space in the output. Don't allow a line break at this space, as this
- % is used only in environments like @example, where each line of input
- % should produce a line of output anyway.
- %
- \gdef\sepspaces{\obeyspaces\let =\tie}
-
- % If an index command is used in an @example environment, any spaces
- % therein should become regular spaces in the raw index file, not the
- % expansion of \tie (\leavevmode \penalty \@M \ ).
- \gdef\unsepspaces{\let =\space}
-}
-
-
-\def\flushcr{\ifx\par\lisppar \def\next##1{}\else \let\next=\relax \fi \next}
-
-% Define the framework for environments in texinfo.tex. It's used like this:
-%
-% \envdef\foo{...}
-% \def\Efoo{...}
-%
-% It's the responsibility of \envdef to insert \begingroup before the
-% actual body; @end closes the group after calling \Efoo. \envdef also
-% defines \thisenv, so the current environment is known; @end checks
-% whether the environment name matches. The \checkenv macro can also be
-% used to check whether the current environment is the one expected.
-%
-% Non-false conditionals (@iftex, @ifset) don't fit into this, so they
-% are not treated as enviroments; they don't open a group. (The
-% implementation of @end takes care not to call \endgroup in this
-% special case.)
-
-
-% At runtime, environments start with this:
-\def\startenvironment#1{\begingroup\def\thisenv{#1}}
-% initialize
-\let\thisenv\empty
-
-% ... but they get defined via ``\envdef\foo{...}'':
-\long\def\envdef#1#2{\def#1{\startenvironment#1#2}}
-\def\envparseargdef#1#2{\parseargdef#1{\startenvironment#1#2}}
-
-% Check whether we're in the right environment:
-\def\checkenv#1{%
- \def\temp{#1}%
- \ifx\thisenv\temp
- \else
- \badenverr
- \fi
-}
-
-% Evironment mismatch, #1 expected:
-\def\badenverr{%
- \errhelp = \EMsimple
- \errmessage{This command can appear only \inenvironment\temp,
- not \inenvironment\thisenv}%
-}
-\def\inenvironment#1{%
- \ifx#1\empty
- out of any environment%
- \else
- in environment \expandafter\string#1%
- \fi
-}
-
-% @end foo executes the definition of \Efoo.
-% But first, it executes a specialized version of \checkenv
-%
-\parseargdef\end{%
- \if 1\csname iscond.#1\endcsname
- \else
- % The general wording of \badenverr may not be ideal, but... --kasal, 06nov03
- \expandafter\checkenv\csname#1\endcsname
- \csname E#1\endcsname
- \endgroup
- \fi
-}
-
-\newhelp\EMsimple{Press RETURN to continue.}
-
-
-%% Simple single-character @ commands
-
-% @@ prints an @
-% Kludge this until the fonts are right (grr).
-\def\@{{\tt\char64}}
-
-% This is turned off because it was never documented
-% and you can use @w{...} around a quote to suppress ligatures.
-%% Define @` and @' to be the same as ` and '
-%% but suppressing ligatures.
-%\def\`{{`}}
-%\def\'{{'}}
-
-% Used to generate quoted braces.
-\def\mylbrace {{\tt\char123}}
-\def\myrbrace {{\tt\char125}}
-\let\{=\mylbrace
-\let\}=\myrbrace
-\begingroup
- % Definitions to produce \{ and \} commands for indices,
- % and @{ and @} for the aux file.
- \catcode`\{ = \other \catcode`\} = \other
- \catcode`\[ = 1 \catcode`\] = 2
- \catcode`\! = 0 \catcode`\\ = \other
- !gdef!lbracecmd[\{]%
- !gdef!rbracecmd[\}]%
- !gdef!lbraceatcmd[@{]%
- !gdef!rbraceatcmd[@}]%
-!endgroup
-
-% @comma{} to avoid , parsing problems.
-\let\comma = ,
-
-% Accents: @, @dotaccent @ringaccent @ubaraccent @udotaccent
-% Others are defined by plain TeX: @` @' @" @^ @~ @= @u @v @H.
-\let\, = \c
-\let\dotaccent = \.
-\def\ringaccent#1{{\accent23 #1}}
-\let\tieaccent = \t
-\let\ubaraccent = \b
-\let\udotaccent = \d
-
-% Other special characters: @questiondown @exclamdown @ordf @ordm
-% Plain TeX defines: @AA @AE @O @OE @L (plus lowercase versions) @ss.
-\def\questiondown{?`}
-\def\exclamdown{!`}
-\def\ordf{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{a}}}
-\def\ordm{\leavevmode\raise1ex\hbox{\selectfonts\lllsize \underbar{o}}}
-
-% Dotless i and dotless j, used for accents.
-\def\imacro{i}
-\def\jmacro{j}
-\def\dotless#1{%
- \def\temp{#1}%
- \ifx\temp\imacro \ptexi
- \else\ifx\temp\jmacro \j
- \else \errmessage{@dotless can be used only with i or j}%
- \fi\fi
-}
-
-% The \TeX{} logo, as in plain, but resetting the spacing so that a
-% period following counts as ending a sentence. (Idea found in latex.)
-%
-\edef\TeX{\TeX \spacefactor=1000 }
-
-% @LaTeX{} logo. Not quite the same results as the definition in
-% latex.ltx, since we use a different font for the raised A; it's most
-% convenient for us to use an explicitly smaller font, rather than using
-% the \scriptstyle font (since we don't reset \scriptstyle and
-% \scriptscriptstyle).
-%
-\def\LaTeX{%
- L\kern-.36em
- {\setbox0=\hbox{T}%
- \vbox to \ht0{\hbox{\selectfonts\lllsize A}\vss}}%
- \kern-.15em
- \TeX
-}
-
-% Be sure we're in horizontal mode when doing a tie, since we make space
-% equivalent to this in @example-like environments. Otherwise, a space
-% at the beginning of a line will start with \penalty -- and
-% since \penalty is valid in vertical mode, we'd end up putting the
-% penalty on the vertical list instead of in the new paragraph.
-{\catcode`@ = 11
- % Avoid using \@M directly, because that causes trouble
- % if the definition is written into an index file.
- \global\let\tiepenalty = \@M
- \gdef\tie{\leavevmode\penalty\tiepenalty\ }
-}
-
-% @: forces normal size whitespace following.
-\def\:{\spacefactor=1000 }
-
-% @* forces a line break.
-\def\*{\hfil\break\hbox{}\ignorespaces}
-
-% @/ allows a line break.
-\let\/=\allowbreak
-
-% @. is an end-of-sentence period.
-\def\.{.\spacefactor=3000 }
-
-% @! is an end-of-sentence bang.
-\def\!{!\spacefactor=3000 }
-
-% @? is an end-of-sentence query.
-\def\?{?\spacefactor=3000 }
-
-% @w prevents a word break. Without the \leavevmode, @w at the
-% beginning of a paragraph, when TeX is still in vertical mode, would
-% produce a whole line of output instead of starting the paragraph.
-\def\w#1{\leavevmode\hbox{#1}}
-
-% @group ... @end group forces ... to be all on one page, by enclosing
-% it in a TeX vbox. We use \vtop instead of \vbox to construct the box
-% to keep its height that of a normal line. According to the rules for
-% \topskip (p.114 of the TeXbook), the glue inserted is
-% max (\topskip - \ht (first item), 0). If that height is large,
-% therefore, no glue is inserted, and the space between the headline and
-% the text is small, which looks bad.
-%
-% Another complication is that the group might be very large. This can
-% cause the glue on the previous page to be unduly stretched, because it
-% does not have much material. In this case, it's better to add an
-% explicit \vfill so that the extra space is at the bottom. The
-% threshold for doing this is if the group is more than \vfilllimit
-% percent of a page (\vfilllimit can be changed inside of @tex).
-%
-\newbox\groupbox
-\def\vfilllimit{0.7}
-%
-\envdef\group{%
- \ifnum\catcode`\^^M=\active \else
- \errhelp = \groupinvalidhelp
- \errmessage{@group invalid in context where filling is enabled}%
- \fi
- \startsavinginserts
- %
- \setbox\groupbox = \vtop\bgroup
- % Do @comment since we are called inside an environment such as
- % @example, where each end-of-line in the input causes an
- % end-of-line in the output. We don't want the end-of-line after
- % the `@group' to put extra space in the output. Since @group
- % should appear on a line by itself (according to the Texinfo
- % manual), we don't worry about eating any user text.
- \comment
-}
-%
-% The \vtop produces a box with normal height and large depth; thus, TeX puts
-% \baselineskip glue before it, and (when the next line of text is done)
-% \lineskip glue after it. Thus, space below is not quite equal to space
-% above. But it's pretty close.
-\def\Egroup{%
- % To get correct interline space between the last line of the group
- % and the first line afterwards, we have to propagate \prevdepth.
- \endgraf % Not \par, as it may have been set to \lisppar.
- \global\dimen1 = \prevdepth
- \egroup % End the \vtop.
- % \dimen0 is the vertical size of the group's box.
- \dimen0 = \ht\groupbox \advance\dimen0 by \dp\groupbox
- % \dimen2 is how much space is left on the page (more or less).
- \dimen2 = \pageheight \advance\dimen2 by -\pagetotal
- % if the group doesn't fit on the current page, and it's a big big
- % group, force a page break.
- \ifdim \dimen0 > \dimen2
- \ifdim \pagetotal < \vfilllimit\pageheight
- \page
- \fi
- \fi
- \box\groupbox
- \prevdepth = \dimen1
- \checkinserts
-}
-%
-% TeX puts in an \escapechar (i.e., `@') at the beginning of the help
-% message, so this ends up printing `@group can only ...'.
-%
-\newhelp\groupinvalidhelp{%
-group can only be used in environments such as @example,^^J%
-where each line of input produces a line of output.}
-
-% @need space-in-mils
-% forces a page break if there is not space-in-mils remaining.
-
-\newdimen\mil \mil=0.001in
-
-% Old definition--didn't work.
-%\parseargdef\need{\par %
-%% This method tries to make TeX break the page naturally
-%% if the depth of the box does not fit.
-%{\baselineskip=0pt%
-%\vtop to #1\mil{\vfil}\kern -#1\mil\nobreak
-%\prevdepth=-1000pt
-%}}
-
-\parseargdef\need{%
- % Ensure vertical mode, so we don't make a big box in the middle of a
- % paragraph.
- \par
- %
- % If the @need value is less than one line space, it's useless.
- \dimen0 = #1\mil
- \dimen2 = \ht\strutbox
- \advance\dimen2 by \dp\strutbox
- \ifdim\dimen0 > \dimen2
- %
- % Do a \strut just to make the height of this box be normal, so the
- % normal leading is inserted relative to the preceding line.
- % And a page break here is fine.
- \vtop to #1\mil{\strut\vfil}%
- %
- % TeX does not even consider page breaks if a penalty added to the
- % main vertical list is 10000 or more. But in order to see if the
- % empty box we just added fits on the page, we must make it consider
- % page breaks. On the other hand, we don't want to actually break the
- % page after the empty box. So we use a penalty of 9999.
- %
- % There is an extremely small chance that TeX will actually break the
- % page at this \penalty, if there are no other feasible breakpoints in
- % sight. (If the user is using lots of big @group commands, which
- % almost-but-not-quite fill up a page, TeX will have a hard time doing
- % good page breaking, for example.) However, I could not construct an
- % example where a page broke at this \penalty; if it happens in a real
- % document, then we can reconsider our strategy.
- \penalty9999
- %
- % Back up by the size of the box, whether we did a page break or not.
- \kern -#1\mil
- %
- % Do not allow a page break right after this kern.
- \nobreak
- \fi
-}
-
-% @br forces paragraph break (and is undocumented).
-
-\let\br = \par
-
-% @page forces the start of a new page.
-%
-\def\page{\par\vfill\supereject}
-
-% @exdent text....
-% outputs text on separate line in roman font, starting at standard page margin
-
-% This records the amount of indent in the innermost environment.
-% That's how much \exdent should take out.
-\newskip\exdentamount
-
-% This defn is used inside fill environments such as @defun.
-\parseargdef\exdent{\hfil\break\hbox{\kern -\exdentamount{\rm#1}}\hfil\break}
-
-% This defn is used inside nofill environments such as @example.
-\parseargdef\nofillexdent{{\advance \leftskip by -\exdentamount
- \leftline{\hskip\leftskip{\rm#1}}}}
-
-% @inmargin{WHICH}{TEXT} puts TEXT in the WHICH margin next to the current
-% paragraph. For more general purposes, use the \margin insertion
-% class. WHICH is `l' or `r'.
-%
-\newskip\inmarginspacing \inmarginspacing=1cm
-\def\strutdepth{\dp\strutbox}
-%
-\def\doinmargin#1#2{\strut\vadjust{%
- \nobreak
- \kern-\strutdepth
- \vtop to \strutdepth{%
- \baselineskip=\strutdepth
- \vss
- % if you have multiple lines of stuff to put here, you'll need to
- % make the vbox yourself of the appropriate size.
- \ifx#1l%
- \llap{\ignorespaces #2\hskip\inmarginspacing}%
- \else
- \rlap{\hskip\hsize \hskip\inmarginspacing \ignorespaces #2}%
- \fi
- \null
- }%
-}}
-\def\inleftmargin{\doinmargin l}
-\def\inrightmargin{\doinmargin r}
-%
-% @inmargin{TEXT [, RIGHT-TEXT]}
-% (if RIGHT-TEXT is given, use TEXT for left page, RIGHT-TEXT for right;
-% else use TEXT for both).
-%
-\def\inmargin#1{\parseinmargin #1,,\finish}
-\def\parseinmargin#1,#2,#3\finish{% not perfect, but better than nothing.
- \setbox0 = \hbox{\ignorespaces #2}%
- \ifdim\wd0 > 0pt
- \def\lefttext{#1}% have both texts
- \def\righttext{#2}%
- \else
- \def\lefttext{#1}% have only one text
- \def\righttext{#1}%
- \fi
- %
- \ifodd\pageno
- \def\temp{\inrightmargin\righttext}% odd page -> outside is right margin
- \else
- \def\temp{\inleftmargin\lefttext}%
- \fi
- \temp
-}
-
-% @include file insert text of that file as input.
-%
-\def\include{\parseargusing\filenamecatcodes\includezzz}
-\def\includezzz#1{%
- \pushthisfilestack
- \def\thisfile{#1}%
- {%
- \makevalueexpandable
- \def\temp{\input #1 }%
- \expandafter
- }\temp
- \popthisfilestack
-}
-\def\filenamecatcodes{%
- \catcode`\\=\other
- \catcode`~=\other
- \catcode`^=\other
- \catcode`_=\other
- \catcode`|=\other
- \catcode`<=\other
- \catcode`>=\other
- \catcode`+=\other
- \catcode`-=\other
-}
-
-\def\pushthisfilestack{%
- \expandafter\pushthisfilestackX\popthisfilestack\StackTerm
-}
-\def\pushthisfilestackX{%
- \expandafter\pushthisfilestackY\thisfile\StackTerm
-}
-\def\pushthisfilestackY #1\StackTerm #2\StackTerm {%
- \gdef\popthisfilestack{\gdef\thisfile{#1}\gdef\popthisfilestack{#2}}%
-}
-
-\def\popthisfilestack{\errthisfilestackempty}
-\def\errthisfilestackempty{\errmessage{Internal error:
- the stack of filenames is empty.}}
-
-\def\thisfile{}
-
-% @center line
-% outputs that line, centered.
-%
-\parseargdef\center{%
- \ifhmode
- \let\next\centerH
- \else
- \let\next\centerV
- \fi
- \next{\hfil \ignorespaces#1\unskip \hfil}%
-}
-\def\centerH#1{%
- {%
- \hfil\break
- \advance\hsize by -\leftskip
- \advance\hsize by -\rightskip
- \line{#1}%
- \break
- }%
-}
-\def\centerV#1{\line{\kern\leftskip #1\kern\rightskip}}
-
-% @sp n outputs n lines of vertical space
-
-\parseargdef\sp{\vskip #1\baselineskip}
-
-% @comment ...line which is ignored...
-% @c is the same as @comment
-% @ignore ... @end ignore is another way to write a comment
-
-\def\comment{\begingroup \catcode`\^^M=\other%
-\catcode`\@=\other \catcode`\{=\other \catcode`\}=\other%
-\commentxxx}
-{\catcode`\^^M=\other \gdef\commentxxx#1^^M{\endgroup}}
-
-\let\c=\comment
-
-% @paragraphindent NCHARS
-% We'll use ems for NCHARS, close enough.
-% NCHARS can also be the word `asis' or `none'.
-% We cannot feasibly implement @paragraphindent asis, though.
-%
-\def\asisword{asis} % no translation, these are keywords
-\def\noneword{none}
-%
-\parseargdef\paragraphindent{%
- \def\temp{#1}%
- \ifx\temp\asisword
- \else
- \ifx\temp\noneword
- \defaultparindent = 0pt
- \else
- \defaultparindent = #1em
- \fi
- \fi
- \parindent = \defaultparindent
-}
-
-% @exampleindent NCHARS
-% We'll use ems for NCHARS like @paragraphindent.
-% It seems @exampleindent asis isn't necessary, but
-% I preserve it to make it similar to @paragraphindent.
-\parseargdef\exampleindent{%
- \def\temp{#1}%
- \ifx\temp\asisword
- \else
- \ifx\temp\noneword
- \lispnarrowing = 0pt
- \else
- \lispnarrowing = #1em
- \fi
- \fi
-}
-
-% @firstparagraphindent WORD
-% If WORD is `none', then suppress indentation of the first paragraph
-% after a section heading. If WORD is `insert', then do indent at such
-% paragraphs.
-%
-% The paragraph indentation is suppressed or not by calling
-% \suppressfirstparagraphindent, which the sectioning commands do.
-% We switch the definition of this back and forth according to WORD.
-% By default, we suppress indentation.
-%
-\def\suppressfirstparagraphindent{\dosuppressfirstparagraphindent}
-\def\insertword{insert}
-%
-\parseargdef\firstparagraphindent{%
- \def\temp{#1}%
- \ifx\temp\noneword
- \let\suppressfirstparagraphindent = \dosuppressfirstparagraphindent
- \else\ifx\temp\insertword
- \let\suppressfirstparagraphindent = \relax
- \else
- \errhelp = \EMsimple
- \errmessage{Unknown @firstparagraphindent option `\temp'}%
- \fi\fi
-}
-
-% Here is how we actually suppress indentation. Redefine \everypar to
-% \kern backwards by \parindent, and then reset itself to empty.
-%
-% We also make \indent itself not actually do anything until the next
-% paragraph.
-%
-\gdef\dosuppressfirstparagraphindent{%
- \gdef\indent{%
- \restorefirstparagraphindent
- \indent
- }%
- \gdef\noindent{%
- \restorefirstparagraphindent
- \noindent
- }%
- \global\everypar = {%
- \kern -\parindent
- \restorefirstparagraphindent
- }%
-}
-
-\gdef\restorefirstparagraphindent{%
- \global \let \indent = \ptexindent
- \global \let \noindent = \ptexnoindent
- \global \everypar = {}%
-}
-
-
-% @asis just yields its argument. Used with @table, for example.
-%
-\def\asis#1{#1}
-
-% @math outputs its argument in math mode.
-%
-% One complication: _ usually means subscripts, but it could also mean
-% an actual _ character, as in @math{@var{some_variable} + 1}. So make
-% _ active, and distinguish by seeing if the current family is \slfam,
-% which is what @var uses.
-{
- \catcode\underChar = \active
- \gdef\mathunderscore{%
- \catcode\underChar=\active
- \def_{\ifnum\fam=\slfam \_\else\sb\fi}%
- }
-}
-% Another complication: we want \\ (and @\) to output a \ character.
-% FYI, plain.tex uses \\ as a temporary control sequence (why?), but
-% this is not advertised and we don't care. Texinfo does not
-% otherwise define @\.
-%
-% The \mathchar is class=0=ordinary, family=7=ttfam, position=5C=\.
-\def\mathbackslash{\ifnum\fam=\ttfam \mathchar"075C \else\backslash \fi}
-%
-\def\math{%
- \tex
- \mathunderscore
- \let\\ = \mathbackslash
- \mathactive
- $\finishmath
-}
-\def\finishmath#1{#1$\endgroup} % Close the group opened by \tex.
-
-% Some active characters (such as <) are spaced differently in math.
-% We have to reset their definitions in case the @math was an argument
-% to a command which sets the catcodes (such as @item or @section).
-%
-{
- \catcode`^ = \active
- \catcode`< = \active
- \catcode`> = \active
- \catcode`+ = \active
- \gdef\mathactive{%
- \let^ = \ptexhat
- \let< = \ptexless
- \let> = \ptexgtr
- \let+ = \ptexplus
- }
-}
-
-% @bullet and @minus need the same treatment as @math, just above.
-\def\bullet{$\ptexbullet$}
-\def\minus{$-$}
-
-% @dots{} outputs an ellipsis using the current font.
-% We do .5em per period so that it has the same spacing in a typewriter
-% font as three actual period characters.
-%
-\def\dots{%
- \leavevmode
- \hbox to 1.5em{%
- \hskip 0pt plus 0.25fil
- .\hfil.\hfil.%
- \hskip 0pt plus 0.5fil
- }%
-}
-
-% @enddots{} is an end-of-sentence ellipsis.
-%
-\def\enddots{%
- \dots
- \spacefactor=3000
-}
-
-% @comma{} is so commas can be inserted into text without messing up
-% Texinfo's parsing.
-%
-\let\comma = ,
-
-% @refill is a no-op.
-\let\refill=\relax
-
-% If working on a large document in chapters, it is convenient to
-% be able to disable indexing, cross-referencing, and contents, for test runs.
-% This is done with @novalidate (before @setfilename).
-%
-\newif\iflinks \linkstrue % by default we want the aux files.
-\let\novalidate = \linksfalse
-
-% @setfilename is done at the beginning of every texinfo file.
-% So open here the files we need to have open while reading the input.
-% This makes it possible to make a .fmt file for texinfo.
-\def\setfilename{%
- \fixbackslash % Turn off hack to swallow `\input texinfo'.
- \iflinks
- \tryauxfile
- % Open the new aux file. TeX will close it automatically at exit.
- \immediate\openout\auxfile=\jobname.aux
- \fi % \openindices needs to do some work in any case.
- \openindices
- \let\setfilename=\comment % Ignore extra @setfilename cmds.
- %
- % If texinfo.cnf is present on the system, read it.
- % Useful for site-wide @afourpaper, etc.
- \openin 1 texinfo.cnf
- \ifeof 1 \else \input texinfo.cnf \fi
- \closein 1
- %
- \comment % Ignore the actual filename.
-}
-
-% Called from \setfilename.
-%
-\def\openindices{%
- \newindex{cp}%
- \newcodeindex{fn}%
- \newcodeindex{vr}%
- \newcodeindex{tp}%
- \newcodeindex{ky}%
- \newcodeindex{pg}%
-}
-
-% @bye.
-\outer\def\bye{\pagealignmacro\tracingstats=1\ptexend}
-
-
-\message{pdf,}
-% adobe `portable' document format
-\newcount\tempnum
-\newcount\lnkcount
-\newtoks\filename
-\newcount\filenamelength
-\newcount\pgn
-\newtoks\toksA
-\newtoks\toksB
-\newtoks\toksC
-\newtoks\toksD
-\newbox\boxA
-\newcount\countA
-\newif\ifpdf
-\newif\ifpdfmakepagedest
-
-% when pdftex is run in dvi mode, \pdfoutput is defined (so \pdfoutput=1
-% can be set). So we test for \relax and 0 as well as \undefined,
-% borrowed from ifpdf.sty.
-\ifx\pdfoutput\undefined
-\else
- \ifx\pdfoutput\relax
- \else
- \ifcase\pdfoutput
- \else
- \pdftrue
- \fi
- \fi
-\fi
-%
-\ifpdf
- \input pdfcolor
- \pdfcatalog{/PageMode /UseOutlines}%
- \def\dopdfimage#1#2#3{%
- \def\imagewidth{#2}%
- \def\imageheight{#3}%
- % without \immediate, pdftex seg faults when the same image is
- % included twice. (Version 3.14159-pre-1.0-unofficial-20010704.)
- \ifnum\pdftexversion < 14
- \immediate\pdfimage
- \else
- \immediate\pdfximage
- \fi
- \ifx\empty\imagewidth\else width \imagewidth \fi
- \ifx\empty\imageheight\else height \imageheight \fi
- \ifnum\pdftexversion<13
- #1.pdf%
- \else
- {#1.pdf}%
- \fi
- \ifnum\pdftexversion < 14 \else
- \pdfrefximage \pdflastximage
- \fi}
- \def\pdfmkdest#1{{%
- % We have to set dummies so commands such as @code in a section title
- % aren't expanded.
- \atdummies
- \normalturnoffactive
- \pdfdest name{#1} xyz%
- }}
- \def\pdfmkpgn#1{#1}
- \let\linkcolor = \Blue % was Cyan, but that seems light?
- \def\endlink{\Black\pdfendlink}
- % Adding outlines to PDF; macros for calculating structure of outlines
- % come from Petr Olsak
- \def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
- \else \csname#1\endcsname \fi}
- \def\advancenumber#1{\tempnum=\expnumber{#1}\relax
- \advance\tempnum by 1
- \expandafter\xdef\csname#1\endcsname{\the\tempnum}}
- %
- % #1 is the section text. #2 is the pdf expression for the number
- % of subentries (or empty, for subsubsections). #3 is the node
- % text, which might be empty if this toc entry had no
- % corresponding node. #4 is the page number.
- %
- \def\dopdfoutline#1#2#3#4{%
- % Generate a link to the node text if that exists; else, use the
- % page number. We could generate a destination for the section
- % text in the case where a section has no node, but it doesn't
- % seem worthwhile, since most documents are normally structured.
- \def\pdfoutlinedest{#3}%
- \ifx\pdfoutlinedest\empty \def\pdfoutlinedest{#4}\fi
- %
- \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{#1}%
- }
- %
- \def\pdfmakeoutlines{%
- \begingroup
- % Thanh's hack / proper braces in bookmarks
- \edef\mylbrace{\iftrue \string{\else}\fi}\let\{=\mylbrace
- \edef\myrbrace{\iffalse{\else\string}\fi}\let\}=\myrbrace
- %
- % Read toc silently, to get counts of subentries for \pdfoutline.
- \def\numchapentry##1##2##3##4{%
- \def\thischapnum{##2}%
- \def\thissecnum{0}%
- \def\thissubsecnum{0}%
- }%
- \def\numsecentry##1##2##3##4{%
- \advancenumber{chap\thischapnum}%
- \def\thissecnum{##2}%
- \def\thissubsecnum{0}%
- }%
- \def\numsubsecentry##1##2##3##4{%
- \advancenumber{sec\thissecnum}%
- \def\thissubsecnum{##2}%
- }%
- \def\numsubsubsecentry##1##2##3##4{%
- \advancenumber{subsec\thissubsecnum}%
- }%
- \def\thischapnum{0}%
- \def\thissecnum{0}%
- \def\thissubsecnum{0}%
- %
- % use \def rather than \let here because we redefine \chapentry et
- % al. a second time, below.
- \def\appentry{\numchapentry}%
- \def\appsecentry{\numsecentry}%
- \def\appsubsecentry{\numsubsecentry}%
- \def\appsubsubsecentry{\numsubsubsecentry}%
- \def\unnchapentry{\numchapentry}%
- \def\unnsecentry{\numsecentry}%
- \def\unnsubsecentry{\numsubsecentry}%
- \def\unnsubsubsecentry{\numsubsubsecentry}%
- \input \jobname.toc
- %
- % Read toc second time, this time actually producing the outlines.
- % The `-' means take the \expnumber as the absolute number of
- % subentries, which we calculated on our first read of the .toc above.
- %
- % We use the node names as the destinations.
- \def\numchapentry##1##2##3##4{%
- \dopdfoutline{##1}{count-\expnumber{chap##2}}{##3}{##4}}%
- \def\numsecentry##1##2##3##4{%
- \dopdfoutline{##1}{count-\expnumber{sec##2}}{##3}{##4}}%
- \def\numsubsecentry##1##2##3##4{%
- \dopdfoutline{##1}{count-\expnumber{subsec##2}}{##3}{##4}}%
- \def\numsubsubsecentry##1##2##3##4{% count is always zero
- \dopdfoutline{##1}{}{##3}{##4}}%
- %
- % PDF outlines are displayed using system fonts, instead of
- % document fonts. Therefore we cannot use special characters,
- % since the encoding is unknown. For example, the eogonek from
- % Latin 2 (0xea) gets translated to a | character. Info from
- % Staszek Wawrykiewicz, 19 Jan 2004 04:09:24 +0100.
- %
- % xx to do this right, we have to translate 8-bit characters to
- % their "best" equivalent, based on the @documentencoding. Right
- % now, I guess we'll just let the pdf reader have its way.
- \indexnofonts
- \turnoffactive
- \input \jobname.toc
- \endgroup
- }
- %
- \def\makelinks #1,{%
- \def\params{#1}\def\E{END}%
- \ifx\params\E
- \let\nextmakelinks=\relax
- \else
- \let\nextmakelinks=\makelinks
- \ifnum\lnkcount>0,\fi
- \picknum{#1}%
- \startlink attr{/Border [0 0 0]}
- goto name{\pdfmkpgn{\the\pgn}}%
- \linkcolor #1%
- \advance\lnkcount by 1%
- \endlink
- \fi
- \nextmakelinks
- }
- \def\picknum#1{\expandafter\pn#1}
- \def\pn#1{%
- \def\p{#1}%
- \ifx\p\lbrace
- \let\nextpn=\ppn
- \else
- \let\nextpn=\ppnn
- \def\first{#1}
- \fi
- \nextpn
- }
- \def\ppn#1{\pgn=#1\gobble}
- \def\ppnn{\pgn=\first}
- \def\pdfmklnk#1{\lnkcount=0\makelinks #1,END,}
- \def\skipspaces#1{\def\PP{#1}\def\D{|}%
- \ifx\PP\D\let\nextsp\relax
- \else\let\nextsp\skipspaces
- \ifx\p\space\else\addtokens{\filename}{\PP}%
- \advance\filenamelength by 1
- \fi
- \fi
- \nextsp}
- \def\getfilename#1{\filenamelength=0\expandafter\skipspaces#1|\relax}
- \ifnum\pdftexversion < 14
- \let \startlink \pdfannotlink
- \else
- \let \startlink \pdfstartlink
- \fi
- \def\pdfurl#1{%
- \begingroup
- \normalturnoffactive\def\@{@}%
- \makevalueexpandable
- \leavevmode\Red
- \startlink attr{/Border [0 0 0]}%
- user{/Subtype /Link /A << /S /URI /URI (#1) >>}%
- \endgroup}
- \def\pdfgettoks#1.{\setbox\boxA=\hbox{\toksA={#1.}\toksB={}\maketoks}}
- \def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
- \def\adn#1{\addtokens{\toksC}{#1}\global\countA=1\let\next=\maketoks}
- \def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}\toksA={#2}}
- \def\maketoks{%
- \expandafter\poptoks\the\toksA|ENDTOKS|\relax
- \ifx\first0\adn0
- \else\ifx\first1\adn1 \else\ifx\first2\adn2 \else\ifx\first3\adn3
- \else\ifx\first4\adn4 \else\ifx\first5\adn5 \else\ifx\first6\adn6
- \else\ifx\first7\adn7 \else\ifx\first8\adn8 \else\ifx\first9\adn9
- \else
- \ifnum0=\countA\else\makelink\fi
- \ifx\first.\let\next=\done\else
- \let\next=\maketoks
- \addtokens{\toksB}{\the\toksD}
- \ifx\first,\addtokens{\toksB}{\space}\fi
- \fi
- \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
- \next}
- \def\makelink{\addtokens{\toksB}%
- {\noexpand\pdflink{\the\toksC}}\toksC={}\global\countA=0}
- \def\pdflink#1{%
- \startlink attr{/Border [0 0 0]} goto name{\pdfmkpgn{#1}}
- \linkcolor #1\endlink}
- \def\done{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
-\else
- \let\pdfmkdest = \gobble
- \let\pdfurl = \gobble
- \let\endlink = \relax
- \let\linkcolor = \relax
- \let\pdfmakeoutlines = \relax
-\fi % \ifx\pdfoutput
-
-
-\message{fonts,}
-
-% Change the current font style to #1, remembering it in \curfontstyle.
-% For now, we do not accumulate font styles: @b{@i{foo}} prints foo in
-% italics, not bold italics.
-%
-\def\setfontstyle#1{%
- \def\curfontstyle{#1}% not as a control sequence, because we are \edef'd.
- \csname ten#1\endcsname % change the current font
-}
-
-% Select #1 fonts with the current style.
-%
-\def\selectfonts#1{\csname #1fonts\endcsname \csname\curfontstyle\endcsname}
-
-\def\rm{\fam=0 \setfontstyle{rm}}
-\def\it{\fam=\itfam \setfontstyle{it}}
-\def\sl{\fam=\slfam \setfontstyle{sl}}
-\def\bf{\fam=\bffam \setfontstyle{bf}}\def\bfstylename{bf}
-\def\tt{\fam=\ttfam \setfontstyle{tt}}
-
-% Texinfo sort of supports the sans serif font style, which plain TeX does not.
-% So we set up a \sf.
-\newfam\sffam
-\def\sf{\fam=\sffam \setfontstyle{sf}}
-\let\li = \sf % Sometimes we call it \li, not \sf.
-
-% We don't need math for this font style.
-\def\ttsl{\setfontstyle{ttsl}}
-
-% Default leading.
-\newdimen\textleading \textleading = 13.2pt
-
-% Set the baselineskip to #1, and the lineskip and strut size
-% correspondingly. There is no deep meaning behind these magic numbers
-% used as factors; they just match (closely enough) what Knuth defined.
-%
-\def\lineskipfactor{.08333}
-\def\strutheightpercent{.70833}
-\def\strutdepthpercent {.29167}
-%
-\def\setleading#1{%
- \normalbaselineskip = #1\relax
- \normallineskip = \lineskipfactor\normalbaselineskip
- \normalbaselines
- \setbox\strutbox =\hbox{%
- \vrule width0pt height\strutheightpercent\baselineskip
- depth \strutdepthpercent \baselineskip
- }%
-}
-
-% Set the font macro #1 to the font named #2, adding on the
-% specified font prefix (normally `cm').
-% #3 is the font's design size, #4 is a scale factor
-\def\setfont#1#2#3#4{\font#1=\fontprefix#2#3 scaled #4}
-
-% Use cm as the default font prefix.
-% To specify the font prefix, you must define \fontprefix
-% before you read in texinfo.tex.
-\ifx\fontprefix\undefined
-\def\fontprefix{cm}
-\fi
-% Support font families that don't use the same naming scheme as CM.
-\def\rmshape{r}
-\def\rmbshape{bx} %where the normal face is bold
-\def\bfshape{b}
-\def\bxshape{bx}
-\def\ttshape{tt}
-\def\ttbshape{tt}
-\def\ttslshape{sltt}
-\def\itshape{ti}
-\def\itbshape{bxti}
-\def\slshape{sl}
-\def\slbshape{bxsl}
-\def\sfshape{ss}
-\def\sfbshape{ss}
-\def\scshape{csc}
-\def\scbshape{csc}
-
-% Text fonts (11.2pt, magstep1).
-\def\textnominalsize{11pt}
-\edef\mainmagstep{\magstephalf}
-\setfont\textrm\rmshape{10}{\mainmagstep}
-\setfont\texttt\ttshape{10}{\mainmagstep}
-\setfont\textbf\bfshape{10}{\mainmagstep}
-\setfont\textit\itshape{10}{\mainmagstep}
-\setfont\textsl\slshape{10}{\mainmagstep}
-\setfont\textsf\sfshape{10}{\mainmagstep}
-\setfont\textsc\scshape{10}{\mainmagstep}
-\setfont\textttsl\ttslshape{10}{\mainmagstep}
-\font\texti=cmmi10 scaled \mainmagstep
-\font\textsy=cmsy10 scaled \mainmagstep
-
-% A few fonts for @defun names and args.
-\setfont\defbf\bfshape{10}{\magstep1}
-\setfont\deftt\ttshape{10}{\magstep1}
-\setfont\defttsl\ttslshape{10}{\magstep1}
-\def\df{\let\tentt=\deftt \let\tenbf = \defbf \let\tenttsl=\defttsl \bf}
-
-% Fonts for indices, footnotes, small examples (9pt).
-\def\smallnominalsize{9pt}
-\setfont\smallrm\rmshape{9}{1000}
-\setfont\smalltt\ttshape{9}{1000}
-\setfont\smallbf\bfshape{10}{900}
-\setfont\smallit\itshape{9}{1000}
-\setfont\smallsl\slshape{9}{1000}
-\setfont\smallsf\sfshape{9}{1000}
-\setfont\smallsc\scshape{10}{900}
-\setfont\smallttsl\ttslshape{10}{900}
-\font\smalli=cmmi9
-\font\smallsy=cmsy9
-
-% Fonts for small examples (8pt).
-\def\smallernominalsize{8pt}
-\setfont\smallerrm\rmshape{8}{1000}
-\setfont\smallertt\ttshape{8}{1000}
-\setfont\smallerbf\bfshape{10}{800}
-\setfont\smallerit\itshape{8}{1000}
-\setfont\smallersl\slshape{8}{1000}
-\setfont\smallersf\sfshape{8}{1000}
-\setfont\smallersc\scshape{10}{800}
-\setfont\smallerttsl\ttslshape{10}{800}
-\font\smalleri=cmmi8
-\font\smallersy=cmsy8
-
-% Fonts for title page (20.4pt):
-\def\titlenominalsize{20pt}
-\setfont\titlerm\rmbshape{12}{\magstep3}
-\setfont\titleit\itbshape{10}{\magstep4}
-\setfont\titlesl\slbshape{10}{\magstep4}
-\setfont\titlett\ttbshape{12}{\magstep3}
-\setfont\titlettsl\ttslshape{10}{\magstep4}
-\setfont\titlesf\sfbshape{17}{\magstep1}
-\let\titlebf=\titlerm
-\setfont\titlesc\scbshape{10}{\magstep4}
-\font\titlei=cmmi12 scaled \magstep3
-\font\titlesy=cmsy10 scaled \magstep4
-\def\authorrm{\secrm}
-\def\authortt{\sectt}
-
-% Chapter (and unnumbered) fonts (17.28pt).
-\def\chapnominalsize{17pt}
-\setfont\chaprm\rmbshape{12}{\magstep2}
-\setfont\chapit\itbshape{10}{\magstep3}
-\setfont\chapsl\slbshape{10}{\magstep3}
-\setfont\chaptt\ttbshape{12}{\magstep2}
-\setfont\chapttsl\ttslshape{10}{\magstep3}
-\setfont\chapsf\sfbshape{17}{1000}
-\let\chapbf=\chaprm
-\setfont\chapsc\scbshape{10}{\magstep3}
-\font\chapi=cmmi12 scaled \magstep2
-\font\chapsy=cmsy10 scaled \magstep3
-
-% Section fonts (14.4pt).
-\def\secnominalsize{14pt}
-\setfont\secrm\rmbshape{12}{\magstep1}
-\setfont\secit\itbshape{10}{\magstep2}
-\setfont\secsl\slbshape{10}{\magstep2}
-\setfont\sectt\ttbshape{12}{\magstep1}
-\setfont\secttsl\ttslshape{10}{\magstep2}
-\setfont\secsf\sfbshape{12}{\magstep1}
-\let\secbf\secrm
-\setfont\secsc\scbshape{10}{\magstep2}
-\font\seci=cmmi12 scaled \magstep1
-\font\secsy=cmsy10 scaled \magstep2
-
-% Subsection fonts (13.15pt).
-\def\ssecnominalsize{13pt}
-\setfont\ssecrm\rmbshape{12}{\magstephalf}
-\setfont\ssecit\itbshape{10}{1315}
-\setfont\ssecsl\slbshape{10}{1315}
-\setfont\ssectt\ttbshape{12}{\magstephalf}
-\setfont\ssecttsl\ttslshape{10}{1315}
-\setfont\ssecsf\sfbshape{12}{\magstephalf}
-\let\ssecbf\ssecrm
-\setfont\ssecsc\scbshape{10}{1315}
-\font\sseci=cmmi12 scaled \magstephalf
-\font\ssecsy=cmsy10 scaled 1315
-
-% Reduced fonts for @acro in text (10pt).
-\def\reducednominalsize{10pt}
-\setfont\reducedrm\rmshape{10}{1000}
-\setfont\reducedtt\ttshape{10}{1000}
-\setfont\reducedbf\bfshape{10}{1000}
-\setfont\reducedit\itshape{10}{1000}
-\setfont\reducedsl\slshape{10}{1000}
-\setfont\reducedsf\sfshape{10}{1000}
-\setfont\reducedsc\scshape{10}{1000}
-\setfont\reducedttsl\ttslshape{10}{1000}
-\font\reducedi=cmmi10
-\font\reducedsy=cmsy10
-
-% In order for the font changes to affect most math symbols and letters,
-% we have to define the \textfont of the standard families. Since
-% texinfo doesn't allow for producing subscripts and superscripts except
-% in the main text, we don't bother to reset \scriptfont and
-% \scriptscriptfont (which would also require loading a lot more fonts).
-%
-\def\resetmathfonts{%
- \textfont0=\tenrm \textfont1=\teni \textfont2=\tensy
- \textfont\itfam=\tenit \textfont\slfam=\tensl \textfont\bffam=\tenbf
- \textfont\ttfam=\tentt \textfont\sffam=\tensf
-}
-
-% The font-changing commands redefine the meanings of \tenSTYLE, instead
-% of just \STYLE. We do this because \STYLE needs to also set the
-% current \fam for math mode. Our \STYLE (e.g., \rm) commands hardwire
-% \tenSTYLE to set the current font.
-%
-% Each font-changing command also sets the names \lsize (one size lower)
-% and \lllsize (three sizes lower). These relative commands are used in
-% the LaTeX logo and acronyms.
-%
-% This all needs generalizing, badly.
-%
-\def\textfonts{%
- \let\tenrm=\textrm \let\tenit=\textit \let\tensl=\textsl
- \let\tenbf=\textbf \let\tentt=\texttt \let\smallcaps=\textsc
- \let\tensf=\textsf \let\teni=\texti \let\tensy=\textsy
- \let\tenttsl=\textttsl
- \def\curfontsize{text}%
- \def\lsize{reduced}\def\lllsize{smaller}%
- \resetmathfonts \setleading{\textleading}}
-\def\titlefonts{%
- \let\tenrm=\titlerm \let\tenit=\titleit \let\tensl=\titlesl
- \let\tenbf=\titlebf \let\tentt=\titlett \let\smallcaps=\titlesc
- \let\tensf=\titlesf \let\teni=\titlei \let\tensy=\titlesy
- \let\tenttsl=\titlettsl
- \def\curfontsize{title}%
- \def\lsize{chap}\def\lllsize{subsec}%
- \resetmathfonts \setleading{25pt}}
-\def\titlefont#1{{\titlefonts\rm #1}}
-\def\chapfonts{%
- \let\tenrm=\chaprm \let\tenit=\chapit \let\tensl=\chapsl
- \let\tenbf=\chapbf \let\tentt=\chaptt \let\smallcaps=\chapsc
- \let\tensf=\chapsf \let\teni=\chapi \let\tensy=\chapsy
- \let\tenttsl=\chapttsl
- \def\curfontsize{chap}%
- \def\lsize{sec}\def\lllsize{text}%
- \resetmathfonts \setleading{19pt}}
-\def\secfonts{%
- \let\tenrm=\secrm \let\tenit=\secit \let\tensl=\secsl
- \let\tenbf=\secbf \let\tentt=\sectt \let\smallcaps=\secsc
- \let\tensf=\secsf \let\teni=\seci \let\tensy=\secsy
- \let\tenttsl=\secttsl
- \def\curfontsize{sec}%
- \def\lsize{subsec}\def\lllsize{reduced}%
- \resetmathfonts \setleading{16pt}}
-\def\subsecfonts{%
- \let\tenrm=\ssecrm \let\tenit=\ssecit \let\tensl=\ssecsl
- \let\tenbf=\ssecbf \let\tentt=\ssectt \let\smallcaps=\ssecsc
- \let\tensf=\ssecsf \let\teni=\sseci \let\tensy=\ssecsy
- \let\tenttsl=\ssecttsl
- \def\curfontsize{ssec}%
- \def\lsize{text}\def\lllsize{small}%
- \resetmathfonts \setleading{15pt}}
-\let\subsubsecfonts = \subsecfonts
-\def\reducedfonts{%
- \let\tenrm=\reducedrm \let\tenit=\reducedit \let\tensl=\reducedsl
- \let\tenbf=\reducedbf \let\tentt=\reducedtt \let\reducedcaps=\reducedsc
- \let\tensf=\reducedsf \let\teni=\reducedi \let\tensy=\reducedsy
- \let\tenttsl=\reducedttsl
- \def\curfontsize{reduced}%
- \def\lsize{small}\def\lllsize{smaller}%
- \resetmathfonts \setleading{10.5pt}}
-\def\smallfonts{%
- \let\tenrm=\smallrm \let\tenit=\smallit \let\tensl=\smallsl
- \let\tenbf=\smallbf \let\tentt=\smalltt \let\smallcaps=\smallsc
- \let\tensf=\smallsf \let\teni=\smalli \let\tensy=\smallsy
- \let\tenttsl=\smallttsl
- \def\curfontsize{small}%
- \def\lsize{smaller}\def\lllsize{smaller}%
- \resetmathfonts \setleading{10.5pt}}
-\def\smallerfonts{%
- \let\tenrm=\smallerrm \let\tenit=\smallerit \let\tensl=\smallersl
- \let\tenbf=\smallerbf \let\tentt=\smallertt \let\smallcaps=\smallersc
- \let\tensf=\smallersf \let\teni=\smalleri \let\tensy=\smallersy
- \let\tenttsl=\smallerttsl
- \def\curfontsize{smaller}%
- \def\lsize{smaller}\def\lllsize{smaller}%
- \resetmathfonts \setleading{9.5pt}}
-
-% Set the fonts to use with the @small... environments.
-\let\smallexamplefonts = \smallfonts
-
-% About \smallexamplefonts. If we use \smallfonts (9pt), @smallexample
-% can fit this many characters:
-% 8.5x11=86 smallbook=72 a4=90 a5=69
-% If we use \scriptfonts (8pt), then we can fit this many characters:
-% 8.5x11=90+ smallbook=80 a4=90+ a5=77
-% For me, subjectively, the few extra characters that fit aren't worth
-% the additional smallness of 8pt. So I'm making the default 9pt.
-%
-% By the way, for comparison, here's what fits with @example (10pt):
-% 8.5x11=71 smallbook=60 a4=75 a5=58
-%
-% I wish the USA used A4 paper.
-% --karl, 24jan03.
-
-
-% Set up the default fonts, so we can use them for creating boxes.
-%
-\textfonts \rm
-
-% Define these so they can be easily changed for other fonts.
-\def\angleleft{$\langle$}
-\def\angleright{$\rangle$}
-
-% Count depth in font-changes, for error checks
-\newcount\fontdepth \fontdepth=0
-
-% Fonts for short table of contents.
-\setfont\shortcontrm\rmshape{12}{1000}
-\setfont\shortcontbf\bfshape{10}{\magstep1} % no cmb12
-\setfont\shortcontsl\slshape{12}{1000}
-\setfont\shortconttt\ttshape{12}{1000}
-
-%% Add scribe-like font environments, plus @l for inline lisp (usually sans
-%% serif) and @ii for TeX italic
-
-% \smartitalic{ARG} outputs arg in italics, followed by an italic correction
-% unless the following character is such as not to need one.
-\def\smartitalicx{\ifx\next,\else\ifx\next-\else\ifx\next.\else
- \ptexslash\fi\fi\fi}
-\def\smartslanted#1{{\ifusingtt\ttsl\sl #1}\futurelet\next\smartitalicx}
-\def\smartitalic#1{{\ifusingtt\ttsl\it #1}\futurelet\next\smartitalicx}
-
-% like \smartslanted except unconditionally uses \ttsl.
-% @var is set to this for defun arguments.
-\def\ttslanted#1{{\ttsl #1}\futurelet\next\smartitalicx}
-
-% like \smartslanted except unconditionally use \sl. We never want
-% ttsl for book titles, do we?
-\def\cite#1{{\sl #1}\futurelet\next\smartitalicx}
-
-\let\i=\smartitalic
-\let\slanted=\smartslanted
-\let\var=\smartslanted
-\let\dfn=\smartslanted
-\let\emph=\smartitalic
-
-% @b, explicit bold.
-\def\b#1{{\bf #1}}
-\let\strong=\b
-
-% @sansserif, explicit sans.
-\def\sansserif#1{{\sf #1}}
-
-% We can't just use \exhyphenpenalty, because that only has effect at
-% the end of a paragraph. Restore normal hyphenation at the end of the
-% group within which \nohyphenation is presumably called.
-%
-\def\nohyphenation{\hyphenchar\font = -1 \aftergroup\restorehyphenation}
-\def\restorehyphenation{\hyphenchar\font = `- }
-
-% Set sfcode to normal for the chars that usually have another value.
-% Can't use plain's \frenchspacing because it uses the `\x notation, and
-% sometimes \x has an active definition that messes things up.
-%
-\catcode`@=11
- \def\frenchspacing{%
- \sfcode\dotChar =\@m \sfcode\questChar=\@m \sfcode\exclamChar=\@m
- \sfcode\colonChar=\@m \sfcode\semiChar =\@m \sfcode\commaChar =\@m
- }
-\catcode`@=\other
-
-\def\t#1{%
- {\tt \rawbackslash \frenchspacing #1}%
- \null
-}
-\def\samp#1{`\tclose{#1}'\null}
-\setfont\keyrm\rmshape{8}{1000}
-\font\keysy=cmsy9
-\def\key#1{{\keyrm\textfont2=\keysy \leavevmode\hbox{%
- \raise0.4pt\hbox{\angleleft}\kern-.08em\vtop{%
- \vbox{\hrule\kern-0.4pt
- \hbox{\raise0.4pt\hbox{\vphantom{\angleleft}}#1}}%
- \kern-0.4pt\hrule}%
- \kern-.06em\raise0.4pt\hbox{\angleright}}}}
-% The old definition, with no lozenge:
-%\def\key #1{{\ttsl \nohyphenation \uppercase{#1}}\null}
-\def\ctrl #1{{\tt \rawbackslash \hat}#1}
-
-% @file, @option are the same as @samp.
-\let\file=\samp
-\let\option=\samp
-
-% @code is a modification of @t,
-% which makes spaces the same size as normal in the surrounding text.
-\def\tclose#1{%
- {%
- % Change normal interword space to be same as for the current font.
- \spaceskip = \fontdimen2\font
- %
- % Switch to typewriter.
- \tt
- %
- % But `\ ' produces the large typewriter interword space.
- \def\ {{\spaceskip = 0pt{} }}%
- %
- % Turn off hyphenation.
- \nohyphenation
- %
- \rawbackslash
- \frenchspacing
- #1%
- }%
- \null
-}
-
-% We *must* turn on hyphenation at `-' and `_' in @code.
-% Otherwise, it is too hard to avoid overfull hboxes
-% in the Emacs manual, the Library manual, etc.
-
-% Unfortunately, TeX uses one parameter (\hyphenchar) to control
-% both hyphenation at - and hyphenation within words.
-% We must therefore turn them both off (\tclose does that)
-% and arrange explicitly to hyphenate at a dash.
-% -- rms.
-{
- \catcode`\-=\active
- \catcode`\_=\active
- %
- \global\def\code{\begingroup
- \catcode`\-=\active \let-\codedash
- \catcode`\_=\active \let_\codeunder
- \codex
- }
-}
-
-\def\realdash{-}
-\def\codedash{-\discretionary{}{}{}}
-\def\codeunder{%
- % this is all so @math{@code{var_name}+1} can work. In math mode, _
- % is "active" (mathcode"8000) and \normalunderscore (or \char95, etc.)
- % will therefore expand the active definition of _, which is us
- % (inside @code that is), therefore an endless loop.
- \ifusingtt{\ifmmode
- \mathchar"075F % class 0=ordinary, family 7=ttfam, pos 0x5F=_.
- \else\normalunderscore \fi
- \discretionary{}{}{}}%
- {\_}%
-}
-\def\codex #1{\tclose{#1}\endgroup}
-
-% @kbd is like @code, except that if the argument is just one @key command,
-% then @kbd has no effect.
-
-% @kbdinputstyle -- arg is `distinct' (@kbd uses slanted tty font always),
-% `example' (@kbd uses ttsl only inside of @example and friends),
-% or `code' (@kbd uses normal tty font always).
-\parseargdef\kbdinputstyle{%
- \def\arg{#1}%
- \ifx\arg\worddistinct
- \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\ttsl}%
- \else\ifx\arg\wordexample
- \gdef\kbdexamplefont{\ttsl}\gdef\kbdfont{\tt}%
- \else\ifx\arg\wordcode
- \gdef\kbdexamplefont{\tt}\gdef\kbdfont{\tt}%
- \else
- \errhelp = \EMsimple
- \errmessage{Unknown @kbdinputstyle option `\arg'}%
- \fi\fi\fi
-}
-\def\worddistinct{distinct}
-\def\wordexample{example}
-\def\wordcode{code}
-
-% Default is `distinct.'
-\kbdinputstyle distinct
-
-\def\xkey{\key}
-\def\kbdfoo#1#2#3\par{\def\one{#1}\def\three{#3}\def\threex{??}%
-\ifx\one\xkey\ifx\threex\three \key{#2}%
-\else{\tclose{\kbdfont\look}}\fi
-\else{\tclose{\kbdfont\look}}\fi}
-
-% For @indicateurl, @env, @command quotes seem unnecessary, so use \code.
-\let\indicateurl=\code
-\let\env=\code
-\let\command=\code
-
-% @uref (abbreviation for `urlref') takes an optional (comma-separated)
-% second argument specifying the text to display and an optional third
-% arg as text to display instead of (rather than in addition to) the url
-% itself. First (mandatory) arg is the url. Perhaps eventually put in
-% a hypertex \special here.
-%
-\def\uref#1{\douref #1,,,\finish}
-\def\douref#1,#2,#3,#4\finish{\begingroup
- \unsepspaces
- \pdfurl{#1}%
- \setbox0 = \hbox{\ignorespaces #3}%
- \ifdim\wd0 > 0pt
- \unhbox0 % third arg given, show only that
- \else
- \setbox0 = \hbox{\ignorespaces #2}%
- \ifdim\wd0 > 0pt
- \ifpdf
- \unhbox0 % PDF: 2nd arg given, show only it
- \else
- \unhbox0\ (\code{#1})% DVI: 2nd arg given, show both it and url
- \fi
- \else
- \code{#1}% only url given, so show it
- \fi
- \fi
- \endlink
-\endgroup}
-
-% @url synonym for @uref, since that's how everyone uses it.
-%
-\let\url=\uref
-
-% rms does not like angle brackets --karl, 17may97.
-% So now @email is just like @uref, unless we are pdf.
-%
-%\def\email#1{\angleleft{\tt #1}\angleright}
-\ifpdf
- \def\email#1{\doemail#1,,\finish}
- \def\doemail#1,#2,#3\finish{\begingroup
- \unsepspaces
- \pdfurl{mailto:#1}%
- \setbox0 = \hbox{\ignorespaces #2}%
- \ifdim\wd0>0pt\unhbox0\else\code{#1}\fi
- \endlink
- \endgroup}
-\else
- \let\email=\uref
-\fi
-
-% Check if we are currently using a typewriter font. Since all the
-% Computer Modern typewriter fonts have zero interword stretch (and
-% shrink), and it is reasonable to expect all typewriter fonts to have
-% this property, we can check that font parameter.
-%
-\def\ifmonospace{\ifdim\fontdimen3\font=0pt }
-
-% Typeset a dimension, e.g., `in' or `pt'. The only reason for the
-% argument is to make the input look right: @dmn{pt} instead of @dmn{}pt.
-%
-\def\dmn#1{\thinspace #1}
-
-\def\kbd#1{\def\look{#1}\expandafter\kbdfoo\look??\par}
-
-% @l was never documented to mean ``switch to the Lisp font'',
-% and it is not used as such in any manual I can find. We need it for
-% Polish suppressed-l. --karl, 22sep96.
-%\def\l#1{{\li #1}\null}
-
-% Explicit font changes: @r, @sc, undocumented @ii.
-\def\r#1{{\rm #1}} % roman font
-\def\sc#1{{\smallcaps#1}} % smallcaps font
-\def\ii#1{{\it #1}} % italic font
-
-% @acronym for "FBI", "NATO", and the like.
-% We print this one point size smaller, since it's intended for
-% all-uppercase.
-%
-\def\acronym#1{\doacronym #1,,\finish}
-\def\doacronym#1,#2,#3\finish{%
- {\selectfonts\lsize #1}%
- \def\temp{#2}%
- \ifx\temp\empty \else
- \space ({\unsepspaces \ignorespaces \temp \unskip})%
- \fi
-}
-
-% @abbr for "Comput. J." and the like.
-% No font change, but don't do end-of-sentence spacing.
-%
-\def\abbr#1{\doabbr #1,,\finish}
-\def\doabbr#1,#2,#3\finish{%
- {\frenchspacing #1}%
- \def\temp{#2}%
- \ifx\temp\empty \else
- \space ({\unsepspaces \ignorespaces \temp \unskip})%
- \fi
-}
-
-% @pounds{} is a sterling sign, which Knuth put in the CM italic font.
-%
-\def\pounds{{\it\$}}
-
-% @euro{} comes from a separate font, depending on the current style.
-% We use the free feym* fonts from the eurosym package by Henrik
-% Theiling, which support regular, slanted, bold and bold slanted (and
-% "outlined" (blackboard board, sort of) versions, which we don't need).
-% It is available from http://www.ctan.org/tex-archive/fonts/eurosym.
-%
-% Although only regular is the truly official Euro symbol, we ignore
-% that. The Euro is designed to be slightly taller than the regular
-% font height.
-%
-% feymr - regular
-% feymo - slanted
-% feybr - bold
-% feybo - bold slanted
-%
-% There is no good (free) typewriter version, to my knowledge.
-% A feymr10 euro is ~7.3pt wide, while a normal cmtt10 char is ~5.25pt wide.
-% Hmm.
-%
-% Also doesn't work in math. Do we need to do math with euro symbols?
-% Hope not.
-%
-%
-\def\euro{{\eurofont e}}
-\def\eurofont{%
- % We set the font at each command, rather than predefining it in
- % \textfonts and the other font-switching commands, so that
- % installations which never need the symbol don't have to have the
- % font installed.
- %
- % There is only one designed size (nominal 10pt), so we always scale
- % that to the current nominal size.
- %
- % By the way, simply using "at 1em" works for cmr10 and the like, but
- % does not work for cmbx10 and other extended/shrunken fonts.
- %
- \def\eurosize{\csname\curfontsize nominalsize\endcsname}%
- %
- \ifx\curfontstyle\bfstylename
- % bold:
- \font\thiseurofont = \ifusingit{feybo10}{feybr10} at \eurosize
- \else
- % regular:
- \font\thiseurofont = \ifusingit{feymo10}{feymr10} at \eurosize
- \fi
- \thiseurofont
-}
-
-% @registeredsymbol - R in a circle. The font for the R should really
-% be smaller yet, but lllsize is the best we can do for now.
-% Adapted from the plain.tex definition of \copyright.
-%
-\def\registeredsymbol{%
- $^{{\ooalign{\hfil\raise.07ex\hbox{\selectfonts\lllsize R}%
- \hfil\crcr\Orb}}%
- }$%
-}
-
-% Laurent Siebenmann reports \Orb undefined with:
-% Textures 1.7.7 (preloaded format=plain 93.10.14) (68K) 16 APR 2004 02:38
-% so we'll define it if necessary.
-%
-\ifx\Orb\undefined
-\def\Orb{\mathhexbox20D}
-\fi
-
-
-\message{page headings,}
-
-\newskip\titlepagetopglue \titlepagetopglue = 1.5in
-\newskip\titlepagebottomglue \titlepagebottomglue = 2pc
-
-% First the title page. Must do @settitle before @titlepage.
-\newif\ifseenauthor
-\newif\iffinishedtitlepage
-
-% Do an implicit @contents or @shortcontents after @end titlepage if the
-% user says @setcontentsaftertitlepage or @setshortcontentsaftertitlepage.
-%
-\newif\ifsetcontentsaftertitlepage
- \let\setcontentsaftertitlepage = \setcontentsaftertitlepagetrue
-\newif\ifsetshortcontentsaftertitlepage
- \let\setshortcontentsaftertitlepage = \setshortcontentsaftertitlepagetrue
-
-\parseargdef\shorttitlepage{\begingroup\hbox{}\vskip 1.5in \chaprm \centerline{#1}%
- \endgroup\page\hbox{}\page}
-
-\envdef\titlepage{%
- % Open one extra group, as we want to close it in the middle of \Etitlepage.
- \begingroup
- \parindent=0pt \textfonts
- % Leave some space at the very top of the page.
- \vglue\titlepagetopglue
- % No rule at page bottom unless we print one at the top with @title.
- \finishedtitlepagetrue
- %
- % Most title ``pages'' are actually two pages long, with space
- % at the top of the second. We don't want the ragged left on the second.
- \let\oldpage = \page
- \def\page{%
- \iffinishedtitlepage\else
- \finishtitlepage
- \fi
- \let\page = \oldpage
- \page
- \null
- }%
-}
-
-\def\Etitlepage{%
- \iffinishedtitlepage\else
- \finishtitlepage
- \fi
- % It is important to do the page break before ending the group,
- % because the headline and footline are only empty inside the group.
- % If we use the new definition of \page, we always get a blank page
- % after the title page, which we certainly don't want.
- \oldpage
- \endgroup
- %
- % Need this before the \...aftertitlepage checks so that if they are
- % in effect the toc pages will come out with page numbers.
- \HEADINGSon
- %
- % If they want short, they certainly want long too.
- \ifsetshortcontentsaftertitlepage
- \shortcontents
- \contents
- \global\let\shortcontents = \relax
- \global\let\contents = \relax
- \fi
- %
- \ifsetcontentsaftertitlepage
- \contents
- \global\let\contents = \relax
- \global\let\shortcontents = \relax
- \fi
-}
-
-\def\finishtitlepage{%
- \vskip4pt \hrule height 2pt width \hsize
- \vskip\titlepagebottomglue
- \finishedtitlepagetrue
-}
-
-%%% Macros to be used within @titlepage:
-
-\let\subtitlerm=\tenrm
-\def\subtitlefont{\subtitlerm \normalbaselineskip = 13pt \normalbaselines}
-
-\def\authorfont{\authorrm \normalbaselineskip = 16pt \normalbaselines
- \let\tt=\authortt}
-
-\parseargdef\title{%
- \checkenv\titlepage
- \leftline{\titlefonts\rm #1}
- % print a rule at the page bottom also.
- \finishedtitlepagefalse
- \vskip4pt \hrule height 4pt width \hsize \vskip4pt
-}
-
-\parseargdef\subtitle{%
- \checkenv\titlepage
- {\subtitlefont \rightline{#1}}%
-}
-
-% @author should come last, but may come many times.
-% It can also be used inside @quotation.
-%
-\parseargdef\author{%
- \def\temp{\quotation}%
- \ifx\thisenv\temp
- \def\quotationauthor{#1}% printed in \Equotation.
- \else
- \checkenv\titlepage
- \ifseenauthor\else \vskip 0pt plus 1filll \seenauthortrue \fi
- {\authorfont \leftline{#1}}%
- \fi
-}
-
-
-%%% Set up page headings and footings.
-
-\let\thispage=\folio
-
-\newtoks\evenheadline % headline on even pages
-\newtoks\oddheadline % headline on odd pages
-\newtoks\evenfootline % footline on even pages
-\newtoks\oddfootline % footline on odd pages
-
-% Now make TeX use those variables
-\headline={{\textfonts\rm \ifodd\pageno \the\oddheadline
- \else \the\evenheadline \fi}}
-\footline={{\textfonts\rm \ifodd\pageno \the\oddfootline
- \else \the\evenfootline \fi}\HEADINGShook}
-\let\HEADINGShook=\relax
-
-% Commands to set those variables.
-% For example, this is what @headings on does
-% @evenheading @thistitle|@thispage|@thischapter
-% @oddheading @thischapter|@thispage|@thistitle
-% @evenfooting @thisfile||
-% @oddfooting ||@thisfile
-
-
-\def\evenheading{\parsearg\evenheadingxxx}
-\def\evenheadingxxx #1{\evenheadingyyy #1\|\|\|\|\finish}
-\def\evenheadingyyy #1\|#2\|#3\|#4\finish{%
-\global\evenheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
-
-\def\oddheading{\parsearg\oddheadingxxx}
-\def\oddheadingxxx #1{\oddheadingyyy #1\|\|\|\|\finish}
-\def\oddheadingyyy #1\|#2\|#3\|#4\finish{%
-\global\oddheadline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
-
-\parseargdef\everyheading{\oddheadingxxx{#1}\evenheadingxxx{#1}}%
-
-\def\evenfooting{\parsearg\evenfootingxxx}
-\def\evenfootingxxx #1{\evenfootingyyy #1\|\|\|\|\finish}
-\def\evenfootingyyy #1\|#2\|#3\|#4\finish{%
-\global\evenfootline={\rlap{\centerline{#2}}\line{#1\hfil#3}}}
-
-\def\oddfooting{\parsearg\oddfootingxxx}
-\def\oddfootingxxx #1{\oddfootingyyy #1\|\|\|\|\finish}
-\def\oddfootingyyy #1\|#2\|#3\|#4\finish{%
- \global\oddfootline = {\rlap{\centerline{#2}}\line{#1\hfil#3}}%
- %
- % Leave some space for the footline. Hopefully ok to assume
- % @evenfooting will not be used by itself.
- \global\advance\pageheight by -\baselineskip
- \global\advance\vsize by -\baselineskip
-}
-
-\parseargdef\everyfooting{\oddfootingxxx{#1}\evenfootingxxx{#1}}
-
-
-% @headings double turns headings on for double-sided printing.
-% @headings single turns headings on for single-sided printing.
-% @headings off turns them off.
-% @headings on same as @headings double, retained for compatibility.
-% @headings after turns on double-sided headings after this page.
-% @headings doubleafter turns on double-sided headings after this page.
-% @headings singleafter turns on single-sided headings after this page.
-% By default, they are off at the start of a document,
-% and turned `on' after @end titlepage.
-
-\def\headings #1 {\csname HEADINGS#1\endcsname}
-
-\def\HEADINGSoff{%
-\global\evenheadline={\hfil} \global\evenfootline={\hfil}
-\global\oddheadline={\hfil} \global\oddfootline={\hfil}}
-\HEADINGSoff
-% When we turn headings on, set the page number to 1.
-% For double-sided printing, put current file name in lower left corner,
-% chapter name on inside top of right hand pages, document
-% title on inside top of left hand pages, and page numbers on outside top
-% edge of all pages.
-\def\HEADINGSdouble{%
-\global\pageno=1
-\global\evenfootline={\hfil}
-\global\oddfootline={\hfil}
-\global\evenheadline={\line{\folio\hfil\thistitle}}
-\global\oddheadline={\line{\thischapter\hfil\folio}}
-\global\let\contentsalignmacro = \chapoddpage
-}
-\let\contentsalignmacro = \chappager
-
-% For single-sided printing, chapter title goes across top left of page,
-% page number on top right.
-\def\HEADINGSsingle{%
-\global\pageno=1
-\global\evenfootline={\hfil}
-\global\oddfootline={\hfil}
-\global\evenheadline={\line{\thischapter\hfil\folio}}
-\global\oddheadline={\line{\thischapter\hfil\folio}}
-\global\let\contentsalignmacro = \chappager
-}
-\def\HEADINGSon{\HEADINGSdouble}
-
-\def\HEADINGSafter{\let\HEADINGShook=\HEADINGSdoublex}
-\let\HEADINGSdoubleafter=\HEADINGSafter
-\def\HEADINGSdoublex{%
-\global\evenfootline={\hfil}
-\global\oddfootline={\hfil}
-\global\evenheadline={\line{\folio\hfil\thistitle}}
-\global\oddheadline={\line{\thischapter\hfil\folio}}
-\global\let\contentsalignmacro = \chapoddpage
-}
-
-\def\HEADINGSsingleafter{\let\HEADINGShook=\HEADINGSsinglex}
-\def\HEADINGSsinglex{%
-\global\evenfootline={\hfil}
-\global\oddfootline={\hfil}
-\global\evenheadline={\line{\thischapter\hfil\folio}}
-\global\oddheadline={\line{\thischapter\hfil\folio}}
-\global\let\contentsalignmacro = \chappager
-}
-
-% Subroutines used in generating headings
-% This produces Day Month Year style of output.
-% Only define if not already defined, in case a txi-??.tex file has set
-% up a different format (e.g., txi-cs.tex does this).
-\ifx\today\undefined
-\def\today{%
- \number\day\space
- \ifcase\month
- \or\putwordMJan\or\putwordMFeb\or\putwordMMar\or\putwordMApr
- \or\putwordMMay\or\putwordMJun\or\putwordMJul\or\putwordMAug
- \or\putwordMSep\or\putwordMOct\or\putwordMNov\or\putwordMDec
- \fi
- \space\number\year}
-\fi
-
-% @settitle line... specifies the title of the document, for headings.
-% It generates no output of its own.
-\def\thistitle{\putwordNoTitle}
-\def\settitle{\parsearg{\gdef\thistitle}}
-
-
-\message{tables,}
-% Tables -- @table, @ftable, @vtable, @item(x).
-
-% default indentation of table text
-\newdimen\tableindent \tableindent=.8in
-% default indentation of @itemize and @enumerate text
-\newdimen\itemindent \itemindent=.3in
-% margin between end of table item and start of table text.
-\newdimen\itemmargin \itemmargin=.1in
-
-% used internally for \itemindent minus \itemmargin
-\newdimen\itemmax
-
-% Note @table, @ftable, and @vtable define @item, @itemx, etc., with
-% these defs.
-% They also define \itemindex
-% to index the item name in whatever manner is desired (perhaps none).
-
-\newif\ifitemxneedsnegativevskip
-
-\def\itemxpar{\par\ifitemxneedsnegativevskip\nobreak\vskip-\parskip\nobreak\fi}
-
-\def\internalBitem{\smallbreak \parsearg\itemzzz}
-\def\internalBitemx{\itemxpar \parsearg\itemzzz}
-
-\def\itemzzz #1{\begingroup %
- \advance\hsize by -\rightskip
- \advance\hsize by -\tableindent
- \setbox0=\hbox{\itemindicate{#1}}%
- \itemindex{#1}%
- \nobreak % This prevents a break before @itemx.
- %
- % If the item text does not fit in the space we have, put it on a line
- % by itself, and do not allow a page break either before or after that
- % line. We do not start a paragraph here because then if the next
- % command is, e.g., @kindex, the whatsit would get put into the
- % horizontal list on a line by itself, resulting in extra blank space.
- \ifdim \wd0>\itemmax
- %
- % Make this a paragraph so we get the \parskip glue and wrapping,
- % but leave it ragged-right.
- \begingroup
- \advance\leftskip by-\tableindent
- \advance\hsize by\tableindent
- \advance\rightskip by0pt plus1fil
- \leavevmode\unhbox0\par
- \endgroup
- %
- % We're going to be starting a paragraph, but we don't want the
- % \parskip glue -- logically it's part of the @item we just started.
- \nobreak \vskip-\parskip
- %
- % Stop a page break at the \parskip glue coming up. However, if
- % what follows is an environment such as @example, there will be no
- % \parskip glue; then the negative vskip we just inserted would
- % cause the example and the item to crash together. So we use this
- % bizarre value of 10001 as a signal to \aboveenvbreak to insert
- % \parskip glue after all. Section titles are handled this way also.
- %
- \penalty 10001
- \endgroup
- \itemxneedsnegativevskipfalse
- \else
- % The item text fits into the space. Start a paragraph, so that the
- % following text (if any) will end up on the same line.
- \noindent
- % Do this with kerns and \unhbox so that if there is a footnote in
- % the item text, it can migrate to the main vertical list and
- % eventually be printed.
- \nobreak\kern-\tableindent
- \dimen0 = \itemmax \advance\dimen0 by \itemmargin \advance\dimen0 by -\wd0
- \unhbox0
- \nobreak\kern\dimen0
- \endgroup
- \itemxneedsnegativevskiptrue
- \fi
-}
-
-\def\item{\errmessage{@item while not in a list environment}}
-\def\itemx{\errmessage{@itemx while not in a list environment}}
-
-% @table, @ftable, @vtable.
-\envdef\table{%
- \let\itemindex\gobble
- \tablecheck{table}%
-}
-\envdef\ftable{%
- \def\itemindex ##1{\doind {fn}{\code{##1}}}%
- \tablecheck{ftable}%
-}
-\envdef\vtable{%
- \def\itemindex ##1{\doind {vr}{\code{##1}}}%
- \tablecheck{vtable}%
-}
-\def\tablecheck#1{%
- \ifnum \the\catcode`\^^M=\active
- \endgroup
- \errmessage{This command won't work in this context; perhaps the problem is
- that we are \inenvironment\thisenv}%
- \def\next{\doignore{#1}}%
- \else
- \let\next\tablex
- \fi
- \next
-}
-\def\tablex#1{%
- \def\itemindicate{#1}%
- \parsearg\tabley
-}
-\def\tabley#1{%
- {%
- \makevalueexpandable
- \edef\temp{\noexpand\tablez #1\space\space\space}%
- \expandafter
- }\temp \endtablez
-}
-\def\tablez #1 #2 #3 #4\endtablez{%
- \aboveenvbreak
- \ifnum 0#1>0 \advance \leftskip by #1\mil \fi
- \ifnum 0#2>0 \tableindent=#2\mil \fi
- \ifnum 0#3>0 \advance \rightskip by #3\mil \fi
- \itemmax=\tableindent
- \advance \itemmax by -\itemmargin
- \advance \leftskip by \tableindent
- \exdentamount=\tableindent
- \parindent = 0pt
- \parskip = \smallskipamount
- \ifdim \parskip=0pt \parskip=2pt \fi
- \let\item = \internalBitem
- \let\itemx = \internalBitemx
-}
-\def\Etable{\endgraf\afterenvbreak}
-\let\Eftable\Etable
-\let\Evtable\Etable
-\let\Eitemize\Etable
-\let\Eenumerate\Etable
-
-% This is the counter used by @enumerate, which is really @itemize
-
-\newcount \itemno
-
-\envdef\itemize{\parsearg\doitemize}
-
-\def\doitemize#1{%
- \aboveenvbreak
- \itemmax=\itemindent
- \advance\itemmax by -\itemmargin
- \advance\leftskip by \itemindent
- \exdentamount=\itemindent
- \parindent=0pt
- \parskip=\smallskipamount
- \ifdim\parskip=0pt \parskip=2pt \fi
- \def\itemcontents{#1}%
- % @itemize with no arg is equivalent to @itemize @bullet.
- \ifx\itemcontents\empty\def\itemcontents{\bullet}\fi
- \let\item=\itemizeitem
-}
-
-% Definition of @item while inside @itemize and @enumerate.
-%
-\def\itemizeitem{%
- \advance\itemno by 1 % for enumerations
- {\let\par=\endgraf \smallbreak}% reasonable place to break
- {%
- % If the document has an @itemize directly after a section title, a
- % \nobreak will be last on the list, and \sectionheading will have
- % done a \vskip-\parskip. In that case, we don't want to zero
- % parskip, or the item text will crash with the heading. On the
- % other hand, when there is normal text preceding the item (as there
- % usually is), we do want to zero parskip, or there would be too much
- % space. In that case, we won't have a \nobreak before. At least
- % that's the theory.
- \ifnum\lastpenalty<10000 \parskip=0in \fi
- \noindent
- \hbox to 0pt{\hss \itemcontents \kern\itemmargin}%
- \vadjust{\penalty 1200}}% not good to break after first line of item.
- \flushcr
-}
-
-% \splitoff TOKENS\endmark defines \first to be the first token in
-% TOKENS, and \rest to be the remainder.
-%
-\def\splitoff#1#2\endmark{\def\first{#1}\def\rest{#2}}%
-
-% Allow an optional argument of an uppercase letter, lowercase letter,
-% or number, to specify the first label in the enumerated list. No
-% argument is the same as `1'.
-%
-\envparseargdef\enumerate{\enumeratey #1 \endenumeratey}
-\def\enumeratey #1 #2\endenumeratey{%
- % If we were given no argument, pretend we were given `1'.
- \def\thearg{#1}%
- \ifx\thearg\empty \def\thearg{1}\fi
- %
- % Detect if the argument is a single token. If so, it might be a
- % letter. Otherwise, the only valid thing it can be is a number.
- % (We will always have one token, because of the test we just made.
- % This is a good thing, since \splitoff doesn't work given nothing at
- % all -- the first parameter is undelimited.)
- \expandafter\splitoff\thearg\endmark
- \ifx\rest\empty
- % Only one token in the argument. It could still be anything.
- % A ``lowercase letter'' is one whose \lccode is nonzero.
- % An ``uppercase letter'' is one whose \lccode is both nonzero, and
- % not equal to itself.
- % Otherwise, we assume it's a number.
- %
- % We need the \relax at the end of the \ifnum lines to stop TeX from
- % continuing to look for a <number>.
- %
- \ifnum\lccode\expandafter`\thearg=0\relax
- \numericenumerate % a number (we hope)
- \else
- % It's a letter.
- \ifnum\lccode\expandafter`\thearg=\expandafter`\thearg\relax
- \lowercaseenumerate % lowercase letter
- \else
- \uppercaseenumerate % uppercase letter
- \fi
- \fi
- \else
- % Multiple tokens in the argument. We hope it's a number.
- \numericenumerate
- \fi
-}
-
-% An @enumerate whose labels are integers. The starting integer is
-% given in \thearg.
-%
-\def\numericenumerate{%
- \itemno = \thearg
- \startenumeration{\the\itemno}%
-}
-
-% The starting (lowercase) letter is in \thearg.
-\def\lowercaseenumerate{%
- \itemno = \expandafter`\thearg
- \startenumeration{%
- % Be sure we're not beyond the end of the alphabet.
- \ifnum\itemno=0
- \errmessage{No more lowercase letters in @enumerate; get a bigger
- alphabet}%
- \fi
- \char\lccode\itemno
- }%
-}
-
-% The starting (uppercase) letter is in \thearg.
-\def\uppercaseenumerate{%
- \itemno = \expandafter`\thearg
- \startenumeration{%
- % Be sure we're not beyond the end of the alphabet.
- \ifnum\itemno=0
- \errmessage{No more uppercase letters in @enumerate; get a bigger
- alphabet}
- \fi
- \char\uccode\itemno
- }%
-}
-
-% Call \doitemize, adding a period to the first argument and supplying the
-% common last two arguments. Also subtract one from the initial value in
-% \itemno, since @item increments \itemno.
-%
-\def\startenumeration#1{%
- \advance\itemno by -1
- \doitemize{#1.}\flushcr
-}
-
-% @alphaenumerate and @capsenumerate are abbreviations for giving an arg
-% to @enumerate.
-%
-\def\alphaenumerate{\enumerate{a}}
-\def\capsenumerate{\enumerate{A}}
-\def\Ealphaenumerate{\Eenumerate}
-\def\Ecapsenumerate{\Eenumerate}
-
-
-% @multitable macros
-% Amy Hendrickson, 8/18/94, 3/6/96
-%
-% @multitable ... @end multitable will make as many columns as desired.
-% Contents of each column will wrap at width given in preamble. Width
-% can be specified either with sample text given in a template line,
-% or in percent of \hsize, the current width of text on page.
-
-% Table can continue over pages but will only break between lines.
-
-% To make preamble:
-%
-% Either define widths of columns in terms of percent of \hsize:
-% @multitable @columnfractions .25 .3 .45
-% @item ...
-%
-% Numbers following @columnfractions are the percent of the total
-% current hsize to be used for each column. You may use as many
-% columns as desired.
-
-
-% Or use a template:
-% @multitable {Column 1 template} {Column 2 template} {Column 3 template}
-% @item ...
-% using the widest term desired in each column.
-
-% Each new table line starts with @item, each subsequent new column
-% starts with @tab. Empty columns may be produced by supplying @tab's
-% with nothing between them for as many times as empty columns are needed,
-% ie, @tab@tab@tab will produce two empty columns.
-
-% @item, @tab do not need to be on their own lines, but it will not hurt
-% if they are.
-
-% Sample multitable:
-
-% @multitable {Column 1 template} {Column 2 template} {Column 3 template}
-% @item first col stuff @tab second col stuff @tab third col
-% @item
-% first col stuff
-% @tab
-% second col stuff
-% @tab
-% third col
-% @item first col stuff @tab second col stuff
-% @tab Many paragraphs of text may be used in any column.
-%
-% They will wrap at the width determined by the template.
-% @item@tab@tab This will be in third column.
-% @end multitable
-
-% Default dimensions may be reset by user.
-% @multitableparskip is vertical space between paragraphs in table.
-% @multitableparindent is paragraph indent in table.
-% @multitablecolmargin is horizontal space to be left between columns.
-% @multitablelinespace is space to leave between table items, baseline
-% to baseline.
-% 0pt means it depends on current normal line spacing.
-%
-\newskip\multitableparskip
-\newskip\multitableparindent
-\newdimen\multitablecolspace
-\newskip\multitablelinespace
-\multitableparskip=0pt
-\multitableparindent=6pt
-\multitablecolspace=12pt
-\multitablelinespace=0pt
-
-% Macros used to set up halign preamble:
-%
-\let\endsetuptable\relax
-\def\xendsetuptable{\endsetuptable}
-\let\columnfractions\relax
-\def\xcolumnfractions{\columnfractions}
-\newif\ifsetpercent
-
-% #1 is the @columnfraction, usually a decimal number like .5, but might
-% be just 1. We just use it, whatever it is.
-%
-\def\pickupwholefraction#1 {%
- \global\advance\colcount by 1
- \expandafter\xdef\csname col\the\colcount\endcsname{#1\hsize}%
- \setuptable
-}
-
-\newcount\colcount
-\def\setuptable#1{%
- \def\firstarg{#1}%
- \ifx\firstarg\xendsetuptable
- \let\go = \relax
- \else
- \ifx\firstarg\xcolumnfractions
- \global\setpercenttrue
- \else
- \ifsetpercent
- \let\go\pickupwholefraction
- \else
- \global\advance\colcount by 1
- \setbox0=\hbox{#1\unskip\space}% Add a normal word space as a
- % separator; typically that is always in the input, anyway.
- \expandafter\xdef\csname col\the\colcount\endcsname{\the\wd0}%
- \fi
- \fi
- \ifx\go\pickupwholefraction
- % Put the argument back for the \pickupwholefraction call, so
- % we'll always have a period there to be parsed.
- \def\go{\pickupwholefraction#1}%
- \else
- \let\go = \setuptable
- \fi%
- \fi
- \go
-}
-
-% multitable-only commands.
-%
-% @headitem starts a heading row, which we typeset in bold.
-% Assignments have to be global since we are inside the implicit group
-% of an alignment entry. Note that \everycr resets \everytab.
-\def\headitem{\checkenv\multitable \crcr \global\everytab={\bf}\the\everytab}%
-%
-% A \tab used to include \hskip1sp. But then the space in a template
-% line is not enough. That is bad. So let's go back to just `&' until
-% we encounter the problem it was intended to solve again.
-% --karl, nathan@acm.org, 20apr99.
-\def\tab{\checkenv\multitable &\the\everytab}%
-
-% @multitable ... @end multitable definitions:
-%
-\newtoks\everytab % insert after every tab.
-%
-\envdef\multitable{%
- \vskip\parskip
- \startsavinginserts
- %
- % @item within a multitable starts a normal row.
- % We use \def instead of \let so that if one of the multitable entries
- % contains an @itemize, we don't choke on the \item (seen as \crcr aka
- % \endtemplate) expanding \doitemize.
- \def\item{\crcr}%
- %
- \tolerance=9500
- \hbadness=9500
- \setmultitablespacing
- \parskip=\multitableparskip
- \parindent=\multitableparindent
- \overfullrule=0pt
- \global\colcount=0
- %
- \everycr = {%
- \noalign{%
- \global\everytab={}%
- \global\colcount=0 % Reset the column counter.
- % Check for saved footnotes, etc.
- \checkinserts
- % Keeps underfull box messages off when table breaks over pages.
- %\filbreak
- % Maybe so, but it also creates really weird page breaks when the
- % table breaks over pages. Wouldn't \vfil be better? Wait until the
- % problem manifests itself, so it can be fixed for real --karl.
- }%
- }%
- %
- \parsearg\domultitable
-}
-\def\domultitable#1{%
- % To parse everything between @multitable and @item:
- \setuptable#1 \endsetuptable
- %
- % This preamble sets up a generic column definition, which will
- % be used as many times as user calls for columns.
- % \vtop will set a single line and will also let text wrap and
- % continue for many paragraphs if desired.
- \halign\bgroup &%
- \global\advance\colcount by 1
- \multistrut
- \vtop{%
- % Use the current \colcount to find the correct column width:
- \hsize=\expandafter\csname col\the\colcount\endcsname
- %
- % In order to keep entries from bumping into each other
- % we will add a \leftskip of \multitablecolspace to all columns after
- % the first one.
- %
- % If a template has been used, we will add \multitablecolspace
- % to the width of each template entry.
- %
- % If the user has set preamble in terms of percent of \hsize we will
- % use that dimension as the width of the column, and the \leftskip
- % will keep entries from bumping into each other. Table will start at
- % left margin and final column will justify at right margin.
- %
- % Make sure we don't inherit \rightskip from the outer environment.
- \rightskip=0pt
- \ifnum\colcount=1
- % The first column will be indented with the surrounding text.
- \advance\hsize by\leftskip
- \else
- \ifsetpercent \else
- % If user has not set preamble in terms of percent of \hsize
- % we will advance \hsize by \multitablecolspace.
- \advance\hsize by \multitablecolspace
- \fi
- % In either case we will make \leftskip=\multitablecolspace:
- \leftskip=\multitablecolspace
- \fi
- % Ignoring space at the beginning and end avoids an occasional spurious
- % blank line, when TeX decides to break the line at the space before the
- % box from the multistrut, so the strut ends up on a line by itself.
- % For example:
- % @multitable @columnfractions .11 .89
- % @item @code{#}
- % @tab Legal holiday which is valid in major parts of the whole country.
- % Is automatically provided with highlighting sequences respectively
- % marking characters.
- \noindent\ignorespaces##\unskip\multistrut
- }\cr
-}
-\def\Emultitable{%
- \crcr
- \egroup % end the \halign
- \global\setpercentfalse
-}
-
-\def\setmultitablespacing{%
- \def\multistrut{\strut}% just use the standard line spacing
- %
- % Compute \multitablelinespace (if not defined by user) for use in
- % \multitableparskip calculation. We used define \multistrut based on
- % this, but (ironically) that caused the spacing to be off.
- % See bug-texinfo report from Werner Lemberg, 31 Oct 2004 12:52:20 +0100.
-\ifdim\multitablelinespace=0pt
-\setbox0=\vbox{X}\global\multitablelinespace=\the\baselineskip
-\global\advance\multitablelinespace by-\ht0
-\fi
-%% Test to see if parskip is larger than space between lines of
-%% table. If not, do nothing.
-%% If so, set to same dimension as multitablelinespace.
-\ifdim\multitableparskip>\multitablelinespace
-\global\multitableparskip=\multitablelinespace
-\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
- %% than skip between lines in the table.
-\fi%
-\ifdim\multitableparskip=0pt
-\global\multitableparskip=\multitablelinespace
-\global\advance\multitableparskip-7pt %% to keep parskip somewhat smaller
- %% than skip between lines in the table.
-\fi}
-
-
-\message{conditionals,}
-
-% @iftex, @ifnotdocbook, @ifnothtml, @ifnotinfo, @ifnotplaintext,
-% @ifnotxml always succeed. They currently do nothing; we don't
-% attempt to check whether the conditionals are properly nested. But we
-% have to remember that they are conditionals, so that @end doesn't
-% attempt to close an environment group.
-%
-\def\makecond#1{%
- \expandafter\let\csname #1\endcsname = \relax
- \expandafter\let\csname iscond.#1\endcsname = 1
-}
-\makecond{iftex}
-\makecond{ifnotdocbook}
-\makecond{ifnothtml}
-\makecond{ifnotinfo}
-\makecond{ifnotplaintext}
-\makecond{ifnotxml}
-
-% Ignore @ignore, @ifhtml, @ifinfo, and the like.
-%
-\def\direntry{\doignore{direntry}}
-\def\documentdescription{\doignore{documentdescription}}
-\def\docbook{\doignore{docbook}}
-\def\html{\doignore{html}}
-\def\ifdocbook{\doignore{ifdocbook}}
-\def\ifhtml{\doignore{ifhtml}}
-\def\ifinfo{\doignore{ifinfo}}
-\def\ifnottex{\doignore{ifnottex}}
-\def\ifplaintext{\doignore{ifplaintext}}
-\def\ifxml{\doignore{ifxml}}
-\def\ignore{\doignore{ignore}}
-\def\menu{\doignore{menu}}
-\def\xml{\doignore{xml}}
-
-% Ignore text until a line `@end #1', keeping track of nested conditionals.
-%
-% A count to remember the depth of nesting.
-\newcount\doignorecount
-
-\def\doignore#1{\begingroup
- % Scan in ``verbatim'' mode:
- \catcode`\@ = \other
- \catcode`\{ = \other
- \catcode`\} = \other
- %
- % Make sure that spaces turn into tokens that match what \doignoretext wants.
- \spaceisspace
- %
- % Count number of #1's that we've seen.
- \doignorecount = 0
- %
- % Swallow text until we reach the matching `@end #1'.
- \dodoignore{#1}%
-}
-
-{ \catcode`_=11 % We want to use \_STOP_ which cannot appear in texinfo source.
- \obeylines %
- %
- \gdef\dodoignore#1{%
- % #1 contains the command name as a string, e.g., `ifinfo'.
- %
- % Define a command to find the next `@end #1', which must be on a line
- % by itself.
- \long\def\doignoretext##1^^M@end #1{\doignoretextyyy##1^^M@#1\_STOP_}%
- % And this command to find another #1 command, at the beginning of a
- % line. (Otherwise, we would consider a line `@c @ifset', for
- % example, to count as an @ifset for nesting.)
- \long\def\doignoretextyyy##1^^M@#1##2\_STOP_{\doignoreyyy{##2}\_STOP_}%
- %
- % And now expand that command.
- \obeylines %
- \doignoretext ^^M%
- }%
-}
-
-\def\doignoreyyy#1{%
- \def\temp{#1}%
- \ifx\temp\empty % Nothing found.
- \let\next\doignoretextzzz
- \else % Found a nested condition, ...
- \advance\doignorecount by 1
- \let\next\doignoretextyyy % ..., look for another.
- % If we're here, #1 ends with ^^M\ifinfo (for example).
- \fi
- \next #1% the token \_STOP_ is present just after this macro.
-}
-
-% We have to swallow the remaining "\_STOP_".
-%
-\def\doignoretextzzz#1{%
- \ifnum\doignorecount = 0 % We have just found the outermost @end.
- \let\next\enddoignore
- \else % Still inside a nested condition.
- \advance\doignorecount by -1
- \let\next\doignoretext % Look for the next @end.
- \fi
- \next
-}
-
-% Finish off ignored text.
-\def\enddoignore{\endgroup\ignorespaces}
-
-
-% @set VAR sets the variable VAR to an empty value.
-% @set VAR REST-OF-LINE sets VAR to the value REST-OF-LINE.
-%
-% Since we want to separate VAR from REST-OF-LINE (which might be
-% empty), we can't just use \parsearg; we have to insert a space of our
-% own to delimit the rest of the line, and then take it out again if we
-% didn't need it.
-% We rely on the fact that \parsearg sets \catcode`\ =10.
-%
-\parseargdef\set{\setyyy#1 \endsetyyy}
-\def\setyyy#1 #2\endsetyyy{%
- {%
- \makevalueexpandable
- \def\temp{#2}%
- \edef\next{\gdef\makecsname{SET#1}}%
- \ifx\temp\empty
- \next{}%
- \else
- \setzzz#2\endsetzzz
- \fi
- }%
-}
-% Remove the trailing space \setxxx inserted.
-\def\setzzz#1 \endsetzzz{\next{#1}}
-
-% @clear VAR clears (i.e., unsets) the variable VAR.
-%
-\parseargdef\clear{%
- {%
- \makevalueexpandable
- \global\expandafter\let\csname SET#1\endcsname=\relax
- }%
-}
-
-% @value{foo} gets the text saved in variable foo.
-\def\value{\begingroup\makevalueexpandable\valuexxx}
-\def\valuexxx#1{\expandablevalue{#1}\endgroup}
-{
- \catcode`\- = \active \catcode`\_ = \active
- %
- \gdef\makevalueexpandable{%
- \let\value = \expandablevalue
- % We don't want these characters active, ...
- \catcode`\-=\other \catcode`\_=\other
- % ..., but we might end up with active ones in the argument if
- % we're called from @code, as @code{@value{foo-bar_}}, though.
- % So \let them to their normal equivalents.
- \let-\realdash \let_\normalunderscore
- }
-}
-
-% We have this subroutine so that we can handle at least some @value's
-% properly in indexes (we call \makevalueexpandable in \indexdummies).
-% The command has to be fully expandable (if the variable is set), since
-% the result winds up in the index file. This means that if the
-% variable's value contains other Texinfo commands, it's almost certain
-% it will fail (although perhaps we could fix that with sufficient work
-% to do a one-level expansion on the result, instead of complete).
-%
-\def\expandablevalue#1{%
- \expandafter\ifx\csname SET#1\endcsname\relax
- {[No value for ``#1'']}%
- \message{Variable `#1', used in @value, is not set.}%
- \else
- \csname SET#1\endcsname
- \fi
-}
-
-% @ifset VAR ... @end ifset reads the `...' iff VAR has been defined
-% with @set.
-%
-% To get special treatment of `@end ifset,' call \makeond and the redefine.
-%
-\makecond{ifset}
-\def\ifset{\parsearg{\doifset{\let\next=\ifsetfail}}}
-\def\doifset#1#2{%
- {%
- \makevalueexpandable
- \let\next=\empty
- \expandafter\ifx\csname SET#2\endcsname\relax
- #1% If not set, redefine \next.
- \fi
- \expandafter
- }\next
-}
-\def\ifsetfail{\doignore{ifset}}
-
-% @ifclear VAR ... @end ifclear reads the `...' iff VAR has never been
-% defined with @set, or has been undefined with @clear.
-%
-% The `\else' inside the `\doifset' parameter is a trick to reuse the
-% above code: if the variable is not set, do nothing, if it is set,
-% then redefine \next to \ifclearfail.
-%
-\makecond{ifclear}
-\def\ifclear{\parsearg{\doifset{\else \let\next=\ifclearfail}}}
-\def\ifclearfail{\doignore{ifclear}}
-
-% @dircategory CATEGORY -- specify a category of the dir file
-% which this file should belong to. Ignore this in TeX.
-\let\dircategory=\comment
-
-% @defininfoenclose.
-\let\definfoenclose=\comment
-
-
-\message{indexing,}
-% Index generation facilities
-
-% Define \newwrite to be identical to plain tex's \newwrite
-% except not \outer, so it can be used within macros and \if's.
-\edef\newwrite{\makecsname{ptexnewwrite}}
-
-% \newindex {foo} defines an index named foo.
-% It automatically defines \fooindex such that
-% \fooindex ...rest of line... puts an entry in the index foo.
-% It also defines \fooindfile to be the number of the output channel for
-% the file that accumulates this index. The file's extension is foo.
-% The name of an index should be no more than 2 characters long
-% for the sake of vms.
-%
-\def\newindex#1{%
- \iflinks
- \expandafter\newwrite \csname#1indfile\endcsname
- \openout \csname#1indfile\endcsname \jobname.#1 % Open the file
- \fi
- \expandafter\xdef\csname#1index\endcsname{% % Define @#1index
- \noexpand\doindex{#1}}
-}
-
-% @defindex foo == \newindex{foo}
-%
-\def\defindex{\parsearg\newindex}
-
-% Define @defcodeindex, like @defindex except put all entries in @code.
-%
-\def\defcodeindex{\parsearg\newcodeindex}
-%
-\def\newcodeindex#1{%
- \iflinks
- \expandafter\newwrite \csname#1indfile\endcsname
- \openout \csname#1indfile\endcsname \jobname.#1
- \fi
- \expandafter\xdef\csname#1index\endcsname{%
- \noexpand\docodeindex{#1}}%
-}
-
-
-% @synindex foo bar makes index foo feed into index bar.
-% Do this instead of @defindex foo if you don't want it as a separate index.
-%
-% @syncodeindex foo bar similar, but put all entries made for index foo
-% inside @code.
-%
-\def\synindex#1 #2 {\dosynindex\doindex{#1}{#2}}
-\def\syncodeindex#1 #2 {\dosynindex\docodeindex{#1}{#2}}
-
-% #1 is \doindex or \docodeindex, #2 the index getting redefined (foo),
-% #3 the target index (bar).
-\def\dosynindex#1#2#3{%
- % Only do \closeout if we haven't already done it, else we'll end up
- % closing the target index.
- \expandafter \ifx\csname donesynindex#2\endcsname \undefined
- % The \closeout helps reduce unnecessary open files; the limit on the
- % Acorn RISC OS is a mere 16 files.
- \expandafter\closeout\csname#2indfile\endcsname
- \expandafter\let\csname\donesynindex#2\endcsname = 1
- \fi
- % redefine \fooindfile:
- \expandafter\let\expandafter\temp\expandafter=\csname#3indfile\endcsname
- \expandafter\let\csname#2indfile\endcsname=\temp
- % redefine \fooindex:
- \expandafter\xdef\csname#2index\endcsname{\noexpand#1{#3}}%
-}
-
-% Define \doindex, the driver for all \fooindex macros.
-% Argument #1 is generated by the calling \fooindex macro,
-% and it is "foo", the name of the index.
-
-% \doindex just uses \parsearg; it calls \doind for the actual work.
-% This is because \doind is more useful to call from other macros.
-
-% There is also \dosubind {index}{topic}{subtopic}
-% which makes an entry in a two-level index such as the operation index.
-
-\def\doindex#1{\edef\indexname{#1}\parsearg\singleindexer}
-\def\singleindexer #1{\doind{\indexname}{#1}}
-
-% like the previous two, but they put @code around the argument.
-\def\docodeindex#1{\edef\indexname{#1}\parsearg\singlecodeindexer}
-\def\singlecodeindexer #1{\doind{\indexname}{\code{#1}}}
-
-% Take care of Texinfo commands that can appear in an index entry.
-% Since there are some commands we want to expand, and others we don't,
-% we have to laboriously prevent expansion for those that we don't.
-%
-\def\indexdummies{%
- \def\@{@}% change to @@ when we switch to @ as escape char in index files.
- \def\ {\realbackslash\space }%
- % Need these in case \tex is in effect and \{ is a \delimiter again.
- % But can't use \lbracecmd and \rbracecmd because texindex assumes
- % braces and backslashes are used only as delimiters.
- \let\{ = \mylbrace
- \let\} = \myrbrace
- %
- % \definedummyword defines \#1 as \realbackslash #1\space, thus
- % effectively preventing its expansion. This is used only for control
- % words, not control letters, because the \space would be incorrect
- % for control characters, but is needed to separate the control word
- % from whatever follows.
- %
- % For control letters, we have \definedummyletter, which omits the
- % space.
- %
- % These can be used both for control words that take an argument and
- % those that do not. If it is followed by {arg} in the input, then
- % that will dutifully get written to the index (or wherever).
- %
- \def\definedummyword##1{%
- \expandafter\def\csname ##1\endcsname{\realbackslash ##1\space}%
- }%
- \def\definedummyletter##1{%
- \expandafter\def\csname ##1\endcsname{\realbackslash ##1}%
- }%
- \let\definedummyaccent\definedummyletter
- %
- % Do the redefinitions.
- \commondummies
-}
-
-% For the aux file, @ is the escape character. So we want to redefine
-% everything using @ instead of \realbackslash. When everything uses
-% @, this will be simpler.
-%
-\def\atdummies{%
- \def\@{@@}%
- \def\ {@ }%
- \let\{ = \lbraceatcmd
- \let\} = \rbraceatcmd
- %
- % (See comments in \indexdummies.)
- \def\definedummyword##1{%
- \expandafter\def\csname ##1\endcsname{@##1\space}%
- }%
- \def\definedummyletter##1{%
- \expandafter\def\csname ##1\endcsname{@##1}%
- }%
- \let\definedummyaccent\definedummyletter
- %
- % Do the redefinitions.
- \commondummies
-}
-
-% Called from \indexdummies and \atdummies. \definedummyword and
-% \definedummyletter must be defined first.
-%
-\def\commondummies{%
- %
- \normalturnoffactive
- %
- \commondummiesnofonts
- %
- \definedummyletter{_}%
- %
- % Non-English letters.
- \definedummyword{AA}%
- \definedummyword{AE}%
- \definedummyword{L}%
- \definedummyword{OE}%
- \definedummyword{O}%
- \definedummyword{aa}%
- \definedummyword{ae}%
- \definedummyword{l}%
- \definedummyword{oe}%
- \definedummyword{o}%
- \definedummyword{ss}%
- \definedummyword{exclamdown}%
- \definedummyword{questiondown}%
- \definedummyword{ordf}%
- \definedummyword{ordm}%
- %
- % Although these internal commands shouldn't show up, sometimes they do.
- \definedummyword{bf}%
- \definedummyword{gtr}%
- \definedummyword{hat}%
- \definedummyword{less}%
- \definedummyword{sf}%
- \definedummyword{sl}%
- \definedummyword{tclose}%
- \definedummyword{tt}%
- %
- \definedummyword{LaTeX}%
- \definedummyword{TeX}%
- %
- % Assorted special characters.
- \definedummyword{bullet}%
- \definedummyword{comma}%
- \definedummyword{copyright}%
- \definedummyword{registeredsymbol}%
- \definedummyword{dots}%
- \definedummyword{enddots}%
- \definedummyword{equiv}%
- \definedummyword{error}%
- \definedummyword{euro}%
- \definedummyword{expansion}%
- \definedummyword{minus}%
- \definedummyword{pounds}%
- \definedummyword{point}%
- \definedummyword{print}%
- \definedummyword{result}%
- %
- % Handle some cases of @value -- where it does not contain any
- % (non-fully-expandable) commands.
- \makevalueexpandable
- %
- % Normal spaces, not active ones.
- \unsepspaces
- %
- % No macro expansion.
- \turnoffmacros
-}
-
-% \commondummiesnofonts: common to \commondummies and \indexnofonts.
-%
-% Better have this without active chars.
-{
- \catcode`\~=\other
- \gdef\commondummiesnofonts{%
- % Control letters and accents.
- \definedummyletter{!}%
- \definedummyaccent{"}%
- \definedummyaccent{'}%
- \definedummyletter{*}%
- \definedummyaccent{,}%
- \definedummyletter{.}%
- \definedummyletter{/}%
- \definedummyletter{:}%
- \definedummyaccent{=}%
- \definedummyletter{?}%
- \definedummyaccent{^}%
- \definedummyaccent{`}%
- \definedummyaccent{~}%
- \definedummyword{u}%
- \definedummyword{v}%
- \definedummyword{H}%
- \definedummyword{dotaccent}%
- \definedummyword{ringaccent}%
- \definedummyword{tieaccent}%
- \definedummyword{ubaraccent}%
- \definedummyword{udotaccent}%
- \definedummyword{dotless}%
- %
- % Texinfo font commands.
- \definedummyword{b}%
- \definedummyword{i}%
- \definedummyword{r}%
- \definedummyword{sc}%
- \definedummyword{t}%
- %
- % Commands that take arguments.
- \definedummyword{acronym}%
- \definedummyword{cite}%
- \definedummyword{code}%
- \definedummyword{command}%
- \definedummyword{dfn}%
- \definedummyword{emph}%
- \definedummyword{env}%
- \definedummyword{file}%
- \definedummyword{kbd}%
- \definedummyword{key}%
- \definedummyword{math}%
- \definedummyword{option}%
- \definedummyword{samp}%
- \definedummyword{strong}%
- \definedummyword{tie}%
- \definedummyword{uref}%
- \definedummyword{url}%
- \definedummyword{var}%
- \definedummyword{verb}%
- \definedummyword{w}%
- }
-}
-
-% \indexnofonts is used when outputting the strings to sort the index
-% by, and when constructing control sequence names. It eliminates all
-% control sequences and just writes whatever the best ASCII sort string
-% would be for a given command (usually its argument).
-%
-\def\indexnofonts{%
- % Accent commands should become @asis.
- \def\definedummyaccent##1{%
- \expandafter\let\csname ##1\endcsname\asis
- }%
- % We can just ignore other control letters.
- \def\definedummyletter##1{%
- \expandafter\def\csname ##1\endcsname{}%
- }%
- % Hopefully, all control words can become @asis.
- \let\definedummyword\definedummyaccent
- %
- \commondummiesnofonts
- %
- % Don't no-op \tt, since it isn't a user-level command
- % and is used in the definitions of the active chars like <, >, |, etc.
- % Likewise with the other plain tex font commands.
- %\let\tt=\asis
- %
- \def\ { }%
- \def\@{@}%
- % how to handle braces?
- \def\_{\normalunderscore}%
- %
- % Non-English letters.
- \def\AA{AA}%
- \def\AE{AE}%
- \def\L{L}%
- \def\OE{OE}%
- \def\O{O}%
- \def\aa{aa}%
- \def\ae{ae}%
- \def\l{l}%
- \def\oe{oe}%
- \def\o{o}%
- \def\ss{ss}%
- \def\exclamdown{!}%
- \def\questiondown{?}%
- \def\ordf{a}%
- \def\ordm{o}%
- %
- \def\LaTeX{LaTeX}%
- \def\TeX{TeX}%
- %
- % Assorted special characters.
- % (The following {} will end up in the sort string, but that's ok.)
- \def\bullet{bullet}%
- \def\comma{,}%
- \def\copyright{copyright}%
- \def\registeredsymbol{R}%
- \def\dots{...}%
- \def\enddots{...}%
- \def\equiv{==}%
- \def\error{error}%
- \def\euro{euro}%
- \def\expansion{==>}%
- \def\minus{-}%
- \def\pounds{pounds}%
- \def\point{.}%
- \def\print{-|}%
- \def\result{=>}%
- %
- % Don't write macro names.
- \emptyusermacros
-}
-
-\let\indexbackslash=0 %overridden during \printindex.
-\let\SETmarginindex=\relax % put index entries in margin (undocumented)?
-
-% Most index entries go through here, but \dosubind is the general case.
-% #1 is the index name, #2 is the entry text.
-\def\doind#1#2{\dosubind{#1}{#2}{}}
-
-% Workhorse for all \fooindexes.
-% #1 is name of index, #2 is stuff to put there, #3 is subentry --
-% empty if called from \doind, as we usually are (the main exception
-% is with most defuns, which call us directly).
-%
-\def\dosubind#1#2#3{%
- \iflinks
- {%
- % Store the main index entry text (including the third arg).
- \toks0 = {#2}%
- % If third arg is present, precede it with a space.
- \def\thirdarg{#3}%
- \ifx\thirdarg\empty \else
- \toks0 = \expandafter{\the\toks0 \space #3}%
- \fi
- %
- \edef\writeto{\csname#1indfile\endcsname}%
- %
- \ifvmode
- \dosubindsanitize
- \else
- \dosubindwrite
- \fi
- }%
- \fi
-}
-
-% Write the entry in \toks0 to the index file:
-%
-\def\dosubindwrite{%
- % Put the index entry in the margin if desired.
- \ifx\SETmarginindex\relax\else
- \insert\margin{\hbox{\vrule height8pt depth3pt width0pt \the\toks0}}%
- \fi
- %
- % Remember, we are within a group.
- \indexdummies % Must do this here, since \bf, etc expand at this stage
- \escapechar=`\\
- \def\backslashcurfont{\indexbackslash}% \indexbackslash isn't defined now
- % so it will be output as is; and it will print as backslash.
- %
- % Process the index entry with all font commands turned off, to
- % get the string to sort by.
- {\indexnofonts
- \edef\temp{\the\toks0}% need full expansion
- \xdef\indexsorttmp{\temp}%
- }%
- %
- % Set up the complete index entry, with both the sort key and
- % the original text, including any font commands. We write
- % three arguments to \entry to the .?? file (four in the
- % subentry case), texindex reduces to two when writing the .??s
- % sorted result.
- \edef\temp{%
- \write\writeto{%
- \string\entry{\indexsorttmp}{\noexpand\folio}{\the\toks0}}%
- }%
- \temp
-}
-
-% Take care of unwanted page breaks:
-%
-% If a skip is the last thing on the list now, preserve it
-% by backing up by \lastskip, doing the \write, then inserting
-% the skip again. Otherwise, the whatsit generated by the
-% \write will make \lastskip zero. The result is that sequences
-% like this:
-% @end defun
-% @tindex whatever
-% @defun ...
-% will have extra space inserted, because the \medbreak in the
-% start of the @defun won't see the skip inserted by the @end of
-% the previous defun.
-%
-% But don't do any of this if we're not in vertical mode. We
-% don't want to do a \vskip and prematurely end a paragraph.
-%
-% Avoid page breaks due to these extra skips, too.
-%
-% But wait, there is a catch there:
-% We'll have to check whether \lastskip is zero skip. \ifdim is not
-% sufficient for this purpose, as it ignores stretch and shrink parts
-% of the skip. The only way seems to be to check the textual
-% representation of the skip.
-%
-% The following is almost like \def\zeroskipmacro{0.0pt} except that
-% the ``p'' and ``t'' characters have catcode \other, not 11 (letter).
-%
-\edef\zeroskipmacro{\expandafter\the\csname z@skip\endcsname}
-%
-% ..., ready, GO:
-%
-\def\dosubindsanitize{%
- % \lastskip and \lastpenalty cannot both be nonzero simultaneously.
- \skip0 = \lastskip
- \edef\lastskipmacro{\the\lastskip}%
- \count255 = \lastpenalty
- %
- % If \lastskip is nonzero, that means the last item was a
- % skip. And since a skip is discardable, that means this
- % -\skip0 glue we're inserting is preceded by a
- % non-discardable item, therefore it is not a potential
- % breakpoint, therefore no \nobreak needed.
- \ifx\lastskipmacro\zeroskipmacro
- \else
- \vskip-\skip0
- \fi
- %
- \dosubindwrite
- %
- \ifx\lastskipmacro\zeroskipmacro
- % If \lastskip was zero, perhaps the last item was a penalty, and
- % perhaps it was >=10000, e.g., a \nobreak. In that case, we want
- % to re-insert the same penalty (values >10000 are used for various
- % signals); since we just inserted a non-discardable item, any
- % following glue (such as a \parskip) would be a breakpoint. For example:
- %
- % @deffn deffn-whatever
- % @vindex index-whatever
- % Description.
- % would allow a break between the index-whatever whatsit
- % and the "Description." paragraph.
- \ifnum\count255>9999 \penalty\count255 \fi
- \else
- % On the other hand, if we had a nonzero \lastskip,
- % this make-up glue would be preceded by a non-discardable item
- % (the whatsit from the \write), so we must insert a \nobreak.
- \nobreak\vskip\skip0
- \fi
-}
-
-% The index entry written in the file actually looks like
-% \entry {sortstring}{page}{topic}
-% or
-% \entry {sortstring}{page}{topic}{subtopic}
-% The texindex program reads in these files and writes files
-% containing these kinds of lines:
-% \initial {c}
-% before the first topic whose initial is c
-% \entry {topic}{pagelist}
-% for a topic that is used without subtopics
-% \primary {topic}
-% for the beginning of a topic that is used with subtopics
-% \secondary {subtopic}{pagelist}
-% for each subtopic.
-
-% Define the user-accessible indexing commands
-% @findex, @vindex, @kindex, @cindex.
-
-\def\findex {\fnindex}
-\def\kindex {\kyindex}
-\def\cindex {\cpindex}
-\def\vindex {\vrindex}
-\def\tindex {\tpindex}
-\def\pindex {\pgindex}
-
-\def\cindexsub {\begingroup\obeylines\cindexsub}
-{\obeylines %
-\gdef\cindexsub "#1" #2^^M{\endgroup %
-\dosubind{cp}{#2}{#1}}}
-
-% Define the macros used in formatting output of the sorted index material.
-
-% @printindex causes a particular index (the ??s file) to get printed.
-% It does not print any chapter heading (usually an @unnumbered).
-%
-\parseargdef\printindex{\begingroup
- \dobreak \chapheadingskip{10000}%
- %
- \smallfonts \rm
- \tolerance = 9500
- \everypar = {}% don't want the \kern\-parindent from indentation suppression.
- %
- % See if the index file exists and is nonempty.
- % Change catcode of @ here so that if the index file contains
- % \initial {@}
- % as its first line, TeX doesn't complain about mismatched braces
- % (because it thinks @} is a control sequence).
- \catcode`\@ = 11
- \openin 1 \jobname.#1s
- \ifeof 1
- % \enddoublecolumns gets confused if there is no text in the index,
- % and it loses the chapter title and the aux file entries for the
- % index. The easiest way to prevent this problem is to make sure
- % there is some text.
- \putwordIndexNonexistent
- \else
- %
- % If the index file exists but is empty, then \openin leaves \ifeof
- % false. We have to make TeX try to read something from the file, so
- % it can discover if there is anything in it.
- \read 1 to \temp
- \ifeof 1
- \putwordIndexIsEmpty
- \else
- % Index files are almost Texinfo source, but we use \ as the escape
- % character. It would be better to use @, but that's too big a change
- % to make right now.
- \def\indexbackslash{\backslashcurfont}%
- \catcode`\\ = 0
- \escapechar = `\\
- \begindoublecolumns
- \input \jobname.#1s
- \enddoublecolumns
- \fi
- \fi
- \closein 1
-\endgroup}
-
-% These macros are used by the sorted index file itself.
-% Change them to control the appearance of the index.
-
-\def\initial#1{{%
- % Some minor font changes for the special characters.
- \let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
- %
- % Remove any glue we may have, we'll be inserting our own.
- \removelastskip
- %
- % We like breaks before the index initials, so insert a bonus.
- \nobreak
- \vskip 0pt plus 3\baselineskip
- \penalty 0
- \vskip 0pt plus -3\baselineskip
- %
- % Typeset the initial. Making this add up to a whole number of
- % baselineskips increases the chance of the dots lining up from column
- % to column. It still won't often be perfect, because of the stretch
- % we need before each entry, but it's better.
- %
- % No shrink because it confuses \balancecolumns.
- \vskip 1.67\baselineskip plus .5\baselineskip
- \leftline{\secbf #1}%
- % Do our best not to break after the initial.
- \nobreak
- \vskip .33\baselineskip plus .1\baselineskip
-}}
-
-% \entry typesets a paragraph consisting of the text (#1), dot leaders, and
-% then page number (#2) flushed to the right margin. It is used for index
-% and table of contents entries. The paragraph is indented by \leftskip.
-%
-% A straightforward implementation would start like this:
-% \def\entry#1#2{...
-% But this frozes the catcodes in the argument, and can cause problems to
-% @code, which sets - active. This problem was fixed by a kludge---
-% ``-'' was active throughout whole index, but this isn't really right.
-%
-% The right solution is to prevent \entry from swallowing the whole text.
-% --kasal, 21nov03
-\def\entry{%
- \begingroup
- %
- % Start a new paragraph if necessary, so our assignments below can't
- % affect previous text.
- \par
- %
- % Do not fill out the last line with white space.
- \parfillskip = 0in
- %
- % No extra space above this paragraph.
- \parskip = 0in
- %
- % Do not prefer a separate line ending with a hyphen to fewer lines.
- \finalhyphendemerits = 0
- %
- % \hangindent is only relevant when the entry text and page number
- % don't both fit on one line. In that case, bob suggests starting the
- % dots pretty far over on the line. Unfortunately, a large
- % indentation looks wrong when the entry text itself is broken across
- % lines. So we use a small indentation and put up with long leaders.
- %
- % \hangafter is reset to 1 (which is the value we want) at the start
- % of each paragraph, so we need not do anything with that.
- \hangindent = 2em
- %
- % When the entry text needs to be broken, just fill out the first line
- % with blank space.
- \rightskip = 0pt plus1fil
- %
- % A bit of stretch before each entry for the benefit of balancing
- % columns.
- \vskip 0pt plus1pt
- %
- % Swallow the left brace of the text (first parameter):
- \afterassignment\doentry
- \let\temp =
-}
-\def\doentry{%
- \bgroup % Instead of the swallowed brace.
- \noindent
- \aftergroup\finishentry
- % And now comes the text of the entry.
-}
-\def\finishentry#1{%
- % #1 is the page number.
- %
- % The following is kludged to not output a line of dots in the index if
- % there are no page numbers. The next person who breaks this will be
- % cursed by a Unix daemon.
- \def\tempa{{\rm }}%
- \def\tempb{#1}%
- \edef\tempc{\tempa}%
- \edef\tempd{\tempb}%
- \ifx\tempc\tempd
- \ %
- \else
- %
- % If we must, put the page number on a line of its own, and fill out
- % this line with blank space. (The \hfil is overwhelmed with the
- % fill leaders glue in \indexdotfill if the page number does fit.)
- \hfil\penalty50
- \null\nobreak\indexdotfill % Have leaders before the page number.
- %
- % The `\ ' here is removed by the implicit \unskip that TeX does as
- % part of (the primitive) \par. Without it, a spurious underfull
- % \hbox ensues.
- \ifpdf
- \pdfgettoks#1.%
- \ \the\toksA
- \else
- \ #1%
- \fi
- \fi
- \par
- \endgroup
-}
-
-% Like \dotfill except takes at least 1 em.
-\def\indexdotfill{\cleaders
- \hbox{$\mathsurround=0pt \mkern1.5mu ${\it .}$ \mkern1.5mu$}\hskip 1em plus 1fill}
-
-\def\primary #1{\line{#1\hfil}}
-
-\newskip\secondaryindent \secondaryindent=0.5cm
-\def\secondary#1#2{{%
- \parfillskip=0in
- \parskip=0in
- \hangindent=1in
- \hangafter=1
- \noindent\hskip\secondaryindent\hbox{#1}\indexdotfill
- \ifpdf
- \pdfgettoks#2.\ \the\toksA % The page number ends the paragraph.
- \else
- #2
- \fi
- \par
-}}
-
-% Define two-column mode, which we use to typeset indexes.
-% Adapted from the TeXbook, page 416, which is to say,
-% the manmac.tex format used to print the TeXbook itself.
-\catcode`\@=11
-
-\newbox\partialpage
-\newdimen\doublecolumnhsize
-
-\def\begindoublecolumns{\begingroup % ended by \enddoublecolumns
- % Grab any single-column material above us.
- \output = {%
- %
- % Here is a possibility not foreseen in manmac: if we accumulate a
- % whole lot of material, we might end up calling this \output
- % routine twice in a row (see the doublecol-lose test, which is
- % essentially a couple of indexes with @setchapternewpage off). In
- % that case we just ship out what is in \partialpage with the normal
- % output routine. Generally, \partialpage will be empty when this
- % runs and this will be a no-op. See the indexspread.tex test case.
- \ifvoid\partialpage \else
- \onepageout{\pagecontents\partialpage}%
- \fi
- %
- \global\setbox\partialpage = \vbox{%
- % Unvbox the main output page.
- \unvbox\PAGE
- \kern-\topskip \kern\baselineskip
- }%
- }%
- \eject % run that output routine to set \partialpage
- %
- % Use the double-column output routine for subsequent pages.
- \output = {\doublecolumnout}%
- %
- % Change the page size parameters. We could do this once outside this
- % routine, in each of @smallbook, @afourpaper, and the default 8.5x11
- % format, but then we repeat the same computation. Repeating a couple
- % of assignments once per index is clearly meaningless for the
- % execution time, so we may as well do it in one place.
- %
- % First we halve the line length, less a little for the gutter between
- % the columns. We compute the gutter based on the line length, so it
- % changes automatically with the paper format. The magic constant
- % below is chosen so that the gutter has the same value (well, +-<1pt)
- % as it did when we hard-coded it.
- %
- % We put the result in a separate register, \doublecolumhsize, so we
- % can restore it in \pagesofar, after \hsize itself has (potentially)
- % been clobbered.
- %
- \doublecolumnhsize = \hsize
- \advance\doublecolumnhsize by -.04154\hsize
- \divide\doublecolumnhsize by 2
- \hsize = \doublecolumnhsize
- %
- % Double the \vsize as well. (We don't need a separate register here,
- % since nobody clobbers \vsize.)
- \vsize = 2\vsize
-}
-
-% The double-column output routine for all double-column pages except
-% the last.
-%
-\def\doublecolumnout{%
- \splittopskip=\topskip \splitmaxdepth=\maxdepth
- % Get the available space for the double columns -- the normal
- % (undoubled) page height minus any material left over from the
- % previous page.
- \dimen@ = \vsize
- \divide\dimen@ by 2
- \advance\dimen@ by -\ht\partialpage
- %
- % box0 will be the left-hand column, box2 the right.
- \setbox0=\vsplit255 to\dimen@ \setbox2=\vsplit255 to\dimen@
- \onepageout\pagesofar
- \unvbox255
- \penalty\outputpenalty
-}
-%
-% Re-output the contents of the output page -- any previous material,
-% followed by the two boxes we just split, in box0 and box2.
-\def\pagesofar{%
- \unvbox\partialpage
- %
- \hsize = \doublecolumnhsize
- \wd0=\hsize \wd2=\hsize
- \hbox to\pagewidth{\box0\hfil\box2}%
-}
-%
-% All done with double columns.
-\def\enddoublecolumns{%
- \output = {%
- % Split the last of the double-column material. Leave it on the
- % current page, no automatic page break.
- \balancecolumns
- %
- % If we end up splitting too much material for the current page,
- % though, there will be another page break right after this \output
- % invocation ends. Having called \balancecolumns once, we do not
- % want to call it again. Therefore, reset \output to its normal
- % definition right away. (We hope \balancecolumns will never be
- % called on to balance too much material, but if it is, this makes
- % the output somewhat more palatable.)
- \global\output = {\onepageout{\pagecontents\PAGE}}%
- }%
- \eject
- \endgroup % started in \begindoublecolumns
- %
- % \pagegoal was set to the doubled \vsize above, since we restarted
- % the current page. We're now back to normal single-column
- % typesetting, so reset \pagegoal to the normal \vsize (after the
- % \endgroup where \vsize got restored).
- \pagegoal = \vsize
-}
-%
-% Called at the end of the double column material.
-\def\balancecolumns{%
- \setbox0 = \vbox{\unvbox255}% like \box255 but more efficient, see p.120.
- \dimen@ = \ht0
- \advance\dimen@ by \topskip
- \advance\dimen@ by-\baselineskip
- \divide\dimen@ by 2 % target to split to
- %debug\message{final 2-column material height=\the\ht0, target=\the\dimen@.}%
- \splittopskip = \topskip
- % Loop until we get a decent breakpoint.
- {%
- \vbadness = 10000
- \loop
- \global\setbox3 = \copy0
- \global\setbox1 = \vsplit3 to \dimen@
- \ifdim\ht3>\dimen@
- \global\advance\dimen@ by 1pt
- \repeat
- }%
- %debug\message{split to \the\dimen@, column heights: \the\ht1, \the\ht3.}%
- \setbox0=\vbox to\dimen@{\unvbox1}%
- \setbox2=\vbox to\dimen@{\unvbox3}%
- %
- \pagesofar
-}
-\catcode`\@ = \other
-
-
-\message{sectioning,}
-% Chapters, sections, etc.
-
-% \unnumberedno is an oxymoron, of course. But we count the unnumbered
-% sections so that we can refer to them unambiguously in the pdf
-% outlines by their "section number". We avoid collisions with chapter
-% numbers by starting them at 10000. (If a document ever has 10000
-% chapters, we're in trouble anyway, I'm sure.)
-\newcount\unnumberedno \unnumberedno = 10000
-\newcount\chapno
-\newcount\secno \secno=0
-\newcount\subsecno \subsecno=0
-\newcount\subsubsecno \subsubsecno=0
-
-% This counter is funny since it counts through charcodes of letters A, B, ...
-\newcount\appendixno \appendixno = `\@
-%
-% \def\appendixletter{\char\the\appendixno}
-% We do the following ugly conditional instead of the above simple
-% construct for the sake of pdftex, which needs the actual
-% letter in the expansion, not just typeset.
-%
-\def\appendixletter{%
- \ifnum\appendixno=`A A%
- \else\ifnum\appendixno=`B B%
- \else\ifnum\appendixno=`C C%
- \else\ifnum\appendixno=`D D%
- \else\ifnum\appendixno=`E E%
- \else\ifnum\appendixno=`F F%
- \else\ifnum\appendixno=`G G%
- \else\ifnum\appendixno=`H H%
- \else\ifnum\appendixno=`I I%
- \else\ifnum\appendixno=`J J%
- \else\ifnum\appendixno=`K K%
- \else\ifnum\appendixno=`L L%
- \else\ifnum\appendixno=`M M%
- \else\ifnum\appendixno=`N N%
- \else\ifnum\appendixno=`O O%
- \else\ifnum\appendixno=`P P%
- \else\ifnum\appendixno=`Q Q%
- \else\ifnum\appendixno=`R R%
- \else\ifnum\appendixno=`S S%
- \else\ifnum\appendixno=`T T%
- \else\ifnum\appendixno=`U U%
- \else\ifnum\appendixno=`V V%
- \else\ifnum\appendixno=`W W%
- \else\ifnum\appendixno=`X X%
- \else\ifnum\appendixno=`Y Y%
- \else\ifnum\appendixno=`Z Z%
- % The \the is necessary, despite appearances, because \appendixletter is
- % expanded while writing the .toc file. \char\appendixno is not
- % expandable, thus it is written literally, thus all appendixes come out
- % with the same letter (or @) in the toc without it.
- \else\char\the\appendixno
- \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
- \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
-
-% Each @chapter defines this as the name of the chapter.
-% page headings and footings can use it. @section does likewise.
-% However, they are not reliable, because we don't use marks.
-\def\thischapter{}
-\def\thissection{}
-
-\newcount\absseclevel % used to calculate proper heading level
-\newcount\secbase\secbase=0 % @raisesections/@lowersections modify this count
-
-% @raisesections: treat @section as chapter, @subsection as section, etc.
-\def\raisesections{\global\advance\secbase by -1}
-\let\up=\raisesections % original BFox name
-
-% @lowersections: treat @chapter as section, @section as subsection, etc.
-\def\lowersections{\global\advance\secbase by 1}
-\let\down=\lowersections % original BFox name
-
-% we only have subsub.
-\chardef\maxseclevel = 3
-%
-% A numbered section within an unnumbered changes to unnumbered too.
-% To achive this, remember the "biggest" unnum. sec. we are currently in:
-\chardef\unmlevel = \maxseclevel
-%
-% Trace whether the current chapter is an appendix or not:
-% \chapheadtype is "N" or "A", unnumbered chapters are ignored.
-\def\chapheadtype{N}
-
-% Choose a heading macro
-% #1 is heading type
-% #2 is heading level
-% #3 is text for heading
-\def\genhead#1#2#3{%
- % Compute the abs. sec. level:
- \absseclevel=#2
- \advance\absseclevel by \secbase
- % Make sure \absseclevel doesn't fall outside the range:
- \ifnum \absseclevel < 0
- \absseclevel = 0
- \else
- \ifnum \absseclevel > 3
- \absseclevel = 3
- \fi
- \fi
- % The heading type:
- \def\headtype{#1}%
- \if \headtype U%
- \ifnum \absseclevel < \unmlevel
- \chardef\unmlevel = \absseclevel
- \fi
- \else
- % Check for appendix sections:
- \ifnum \absseclevel = 0
- \edef\chapheadtype{\headtype}%
- \else
- \if \headtype A\if \chapheadtype N%
- \errmessage{@appendix... within a non-appendix chapter}%
- \fi\fi
- \fi
- % Check for numbered within unnumbered:
- \ifnum \absseclevel > \unmlevel
- \def\headtype{U}%
- \else
- \chardef\unmlevel = 3
- \fi
- \fi
- % Now print the heading:
- \if \headtype U%
- \ifcase\absseclevel
- \unnumberedzzz{#3}%
- \or \unnumberedseczzz{#3}%
- \or \unnumberedsubseczzz{#3}%
- \or \unnumberedsubsubseczzz{#3}%
- \fi
- \else
- \if \headtype A%
- \ifcase\absseclevel
- \appendixzzz{#3}%
- \or \appendixsectionzzz{#3}%
- \or \appendixsubseczzz{#3}%
- \or \appendixsubsubseczzz{#3}%
- \fi
- \else
- \ifcase\absseclevel
- \chapterzzz{#3}%
- \or \seczzz{#3}%
- \or \numberedsubseczzz{#3}%
- \or \numberedsubsubseczzz{#3}%
- \fi
- \fi
- \fi
- \suppressfirstparagraphindent
-}
-
-% an interface:
-\def\numhead{\genhead N}
-\def\apphead{\genhead A}
-\def\unnmhead{\genhead U}
-
-% @chapter, @appendix, @unnumbered. Increment top-level counter, reset
-% all lower-level sectioning counters to zero.
-%
-% Also set \chaplevelprefix, which we prepend to @float sequence numbers
-% (e.g., figures), q.v. By default (before any chapter), that is empty.
-\let\chaplevelprefix = \empty
-%
-\outer\parseargdef\chapter{\numhead0{#1}} % normally numhead0 calls chapterzzz
-\def\chapterzzz#1{%
- % section resetting is \global in case the chapter is in a group, such
- % as an @include file.
- \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
- \global\advance\chapno by 1
- %
- % Used for \float.
- \gdef\chaplevelprefix{\the\chapno.}%
- \resetallfloatnos
- %
- \message{\putwordChapter\space \the\chapno}%
- %
- % Write the actual heading.
- \chapmacro{#1}{Ynumbered}{\the\chapno}%
- %
- % So @section and the like are numbered underneath this chapter.
- \global\let\section = \numberedsec
- \global\let\subsection = \numberedsubsec
- \global\let\subsubsection = \numberedsubsubsec
-}
-
-\outer\parseargdef\appendix{\apphead0{#1}} % normally apphead0 calls appendixzzz
-\def\appendixzzz#1{%
- \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
- \global\advance\appendixno by 1
- \gdef\chaplevelprefix{\appendixletter.}%
- \resetallfloatnos
- %
- \def\appendixnum{\putwordAppendix\space \appendixletter}%
- \message{\appendixnum}%
- %
- \chapmacro{#1}{Yappendix}{\appendixletter}%
- %
- \global\let\section = \appendixsec
- \global\let\subsection = \appendixsubsec
- \global\let\subsubsection = \appendixsubsubsec
-}
-
-\outer\parseargdef\unnumbered{\unnmhead0{#1}} % normally unnmhead0 calls unnumberedzzz
-\def\unnumberedzzz#1{%
- \global\secno=0 \global\subsecno=0 \global\subsubsecno=0
- \global\advance\unnumberedno by 1
- %
- % Since an unnumbered has no number, no prefix for figures.
- \global\let\chaplevelprefix = \empty
- \resetallfloatnos
- %
- % This used to be simply \message{#1}, but TeX fully expands the
- % argument to \message. Therefore, if #1 contained @-commands, TeX
- % expanded them. For example, in `@unnumbered The @cite{Book}', TeX
- % expanded @cite (which turns out to cause errors because \cite is meant
- % to be executed, not expanded).
- %
- % Anyway, we don't want the fully-expanded definition of @cite to appear
- % as a result of the \message, we just want `@cite' itself. We use
- % \the<toks register> to achieve this: TeX expands \the<toks> only once,
- % simply yielding the contents of <toks register>. (We also do this for
- % the toc entries.)
- \toks0 = {#1}%
- \message{(\the\toks0)}%
- %
- \chapmacro{#1}{Ynothing}{\the\unnumberedno}%
- %
- \global\let\section = \unnumberedsec
- \global\let\subsection = \unnumberedsubsec
- \global\let\subsubsection = \unnumberedsubsubsec
-}
-
-% @centerchap is like @unnumbered, but the heading is centered.
-\outer\parseargdef\centerchap{%
- % Well, we could do the following in a group, but that would break
- % an assumption that \chapmacro is called at the outermost level.
- % Thus we are safer this way: --kasal, 24feb04
- \let\centerparametersmaybe = \centerparameters
- \unnmhead0{#1}%
- \let\centerparametersmaybe = \relax
-}
-
-% @top is like @unnumbered.
-\let\top\unnumbered
-
-% Sections.
-\outer\parseargdef\numberedsec{\numhead1{#1}} % normally calls seczzz
-\def\seczzz#1{%
- \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1
- \sectionheading{#1}{sec}{Ynumbered}{\the\chapno.\the\secno}%
-}
-
-\outer\parseargdef\appendixsection{\apphead1{#1}} % normally calls appendixsectionzzz
-\def\appendixsectionzzz#1{%
- \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1
- \sectionheading{#1}{sec}{Yappendix}{\appendixletter.\the\secno}%
-}
-\let\appendixsec\appendixsection
-
-\outer\parseargdef\unnumberedsec{\unnmhead1{#1}} % normally calls unnumberedseczzz
-\def\unnumberedseczzz#1{%
- \global\subsecno=0 \global\subsubsecno=0 \global\advance\secno by 1
- \sectionheading{#1}{sec}{Ynothing}{\the\unnumberedno.\the\secno}%
-}
-
-% Subsections.
-\outer\parseargdef\numberedsubsec{\numhead2{#1}} % normally calls numberedsubseczzz
-\def\numberedsubseczzz#1{%
- \global\subsubsecno=0 \global\advance\subsecno by 1
- \sectionheading{#1}{subsec}{Ynumbered}{\the\chapno.\the\secno.\the\subsecno}%
-}
-
-\outer\parseargdef\appendixsubsec{\apphead2{#1}} % normally calls appendixsubseczzz
-\def\appendixsubseczzz#1{%
- \global\subsubsecno=0 \global\advance\subsecno by 1
- \sectionheading{#1}{subsec}{Yappendix}%
- {\appendixletter.\the\secno.\the\subsecno}%
-}
-
-\outer\parseargdef\unnumberedsubsec{\unnmhead2{#1}} %normally calls unnumberedsubseczzz
-\def\unnumberedsubseczzz#1{%
- \global\subsubsecno=0 \global\advance\subsecno by 1
- \sectionheading{#1}{subsec}{Ynothing}%
- {\the\unnumberedno.\the\secno.\the\subsecno}%
-}
-
-% Subsubsections.
-\outer\parseargdef\numberedsubsubsec{\numhead3{#1}} % normally numberedsubsubseczzz
-\def\numberedsubsubseczzz#1{%
- \global\advance\subsubsecno by 1
- \sectionheading{#1}{subsubsec}{Ynumbered}%
- {\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno}%
-}
-
-\outer\parseargdef\appendixsubsubsec{\apphead3{#1}} % normally appendixsubsubseczzz
-\def\appendixsubsubseczzz#1{%
- \global\advance\subsubsecno by 1
- \sectionheading{#1}{subsubsec}{Yappendix}%
- {\appendixletter.\the\secno.\the\subsecno.\the\subsubsecno}%
-}
-
-\outer\parseargdef\unnumberedsubsubsec{\unnmhead3{#1}} %normally unnumberedsubsubseczzz
-\def\unnumberedsubsubseczzz#1{%
- \global\advance\subsubsecno by 1
- \sectionheading{#1}{subsubsec}{Ynothing}%
- {\the\unnumberedno.\the\secno.\the\subsecno.\the\subsubsecno}%
-}
-
-% These macros control what the section commands do, according
-% to what kind of chapter we are in (ordinary, appendix, or unnumbered).
-% Define them by default for a numbered chapter.
-\let\section = \numberedsec
-\let\subsection = \numberedsubsec
-\let\subsubsection = \numberedsubsubsec
-
-% Define @majorheading, @heading and @subheading
-
-% NOTE on use of \vbox for chapter headings, section headings, and such:
-% 1) We use \vbox rather than the earlier \line to permit
-% overlong headings to fold.
-% 2) \hyphenpenalty is set to 10000 because hyphenation in a
-% heading is obnoxious; this forbids it.
-% 3) Likewise, headings look best if no \parindent is used, and
-% if justification is not attempted. Hence \raggedright.
-
-
-\def\majorheading{%
- {\advance\chapheadingskip by 10pt \chapbreak }%
- \parsearg\chapheadingzzz
-}
-
-\def\chapheading{\chapbreak \parsearg\chapheadingzzz}
-\def\chapheadingzzz#1{%
- {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
- \parindent=0pt\raggedright
- \rm #1\hfill}}%
- \bigskip \par\penalty 200\relax
- \suppressfirstparagraphindent
-}
-
-% @heading, @subheading, @subsubheading.
-\parseargdef\heading{\sectionheading{#1}{sec}{Yomitfromtoc}{}
- \suppressfirstparagraphindent}
-\parseargdef\subheading{\sectionheading{#1}{subsec}{Yomitfromtoc}{}
- \suppressfirstparagraphindent}
-\parseargdef\subsubheading{\sectionheading{#1}{subsubsec}{Yomitfromtoc}{}
- \suppressfirstparagraphindent}
-
-% These macros generate a chapter, section, etc. heading only
-% (including whitespace, linebreaking, etc. around it),
-% given all the information in convenient, parsed form.
-
-%%% Args are the skip and penalty (usually negative)
-\def\dobreak#1#2{\par\ifdim\lastskip<#1\removelastskip\penalty#2\vskip#1\fi}
-
-%%% Define plain chapter starts, and page on/off switching for it
-% Parameter controlling skip before chapter headings (if needed)
-
-\newskip\chapheadingskip
-
-\def\chapbreak{\dobreak \chapheadingskip {-4000}}
-\def\chappager{\par\vfill\supereject}
-\def\chapoddpage{\chappager \ifodd\pageno \else \hbox to 0pt{} \chappager\fi}
-
-\def\setchapternewpage #1 {\csname CHAPPAG#1\endcsname}
-
-\def\CHAPPAGoff{%
-\global\let\contentsalignmacro = \chappager
-\global\let\pchapsepmacro=\chapbreak
-\global\let\pagealignmacro=\chappager}
-
-\def\CHAPPAGon{%
-\global\let\contentsalignmacro = \chappager
-\global\let\pchapsepmacro=\chappager
-\global\let\pagealignmacro=\chappager
-\global\def\HEADINGSon{\HEADINGSsingle}}
-
-\def\CHAPPAGodd{%
-\global\let\contentsalignmacro = \chapoddpage
-\global\let\pchapsepmacro=\chapoddpage
-\global\let\pagealignmacro=\chapoddpage
-\global\def\HEADINGSon{\HEADINGSdouble}}
-
-\CHAPPAGon
-
-% Chapter opening.
-%
-% #1 is the text, #2 is the section type (Ynumbered, Ynothing,
-% Yappendix, Yomitfromtoc), #3 the chapter number.
-%
-% To test against our argument.
-\def\Ynothingkeyword{Ynothing}
-\def\Yomitfromtockeyword{Yomitfromtoc}
-\def\Yappendixkeyword{Yappendix}
-%
-\def\chapmacro#1#2#3{%
- \pchapsepmacro
- {%
- \chapfonts \rm
- %
- % Have to define \thissection before calling \donoderef, because the
- % xref code eventually uses it. On the other hand, it has to be called
- % after \pchapsepmacro, or the headline will change too soon.
- \gdef\thissection{#1}%
- \gdef\thischaptername{#1}%
- %
- % Only insert the separating space if we have a chapter/appendix
- % number, and don't print the unnumbered ``number''.
- \def\temptype{#2}%
- \ifx\temptype\Ynothingkeyword
- \setbox0 = \hbox{}%
- \def\toctype{unnchap}%
- \gdef\thischapter{#1}%
- \else\ifx\temptype\Yomitfromtockeyword
- \setbox0 = \hbox{}% contents like unnumbered, but no toc entry
- \def\toctype{omit}%
- \gdef\thischapter{}%
- \else\ifx\temptype\Yappendixkeyword
- \setbox0 = \hbox{\putwordAppendix{} #3\enspace}%
- \def\toctype{app}%
- % We don't substitute the actual chapter name into \thischapter
- % because we don't want its macros evaluated now. And we don't
- % use \thissection because that changes with each section.
- %
- \xdef\thischapter{\putwordAppendix{} \appendixletter:
- \noexpand\thischaptername}%
- \else
- \setbox0 = \hbox{#3\enspace}%
- \def\toctype{numchap}%
- \xdef\thischapter{\putwordChapter{} \the\chapno:
- \noexpand\thischaptername}%
- \fi\fi\fi
- %
- % Write the toc entry for this chapter. Must come before the
- % \donoderef, because we include the current node name in the toc
- % entry, and \donoderef resets it to empty.
- \writetocentry{\toctype}{#1}{#3}%
- %
- % For pdftex, we have to write out the node definition (aka, make
- % the pdfdest) after any page break, but before the actual text has
- % been typeset. If the destination for the pdf outline is after the
- % text, then jumping from the outline may wind up with the text not
- % being visible, for instance under high magnification.
- \donoderef{#2}%
- %
- % Typeset the actual heading.
- \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
- \hangindent=\wd0 \centerparametersmaybe
- \unhbox0 #1\par}%
- }%
- \nobreak\bigskip % no page break after a chapter title
- \nobreak
-}
-
-% @centerchap -- centered and unnumbered.
-\let\centerparametersmaybe = \relax
-\def\centerparameters{%
- \advance\rightskip by 3\rightskip
- \leftskip = \rightskip
- \parfillskip = 0pt
-}
-
-
-% I don't think this chapter style is supported any more, so I'm not
-% updating it with the new noderef stuff. We'll see. --karl, 11aug03.
-%
-\def\setchapterstyle #1 {\csname CHAPF#1\endcsname}
-%
-\def\unnchfopen #1{%
-\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
- \parindent=0pt\raggedright
- \rm #1\hfill}}\bigskip \par\nobreak
-}
-\def\chfopen #1#2{\chapoddpage {\chapfonts
-\vbox to 3in{\vfil \hbox to\hsize{\hfil #2} \hbox to\hsize{\hfil #1} \vfil}}%
-\par\penalty 5000 %
-}
-\def\centerchfopen #1{%
-\chapoddpage {\chapfonts \vbox{\hyphenpenalty=10000\tolerance=5000
- \parindent=0pt
- \hfill {\rm #1}\hfill}}\bigskip \par\nobreak
-}
-\def\CHAPFopen{%
- \global\let\chapmacro=\chfopen
- \global\let\centerchapmacro=\centerchfopen}
-
-
-% Section titles. These macros combine the section number parts and
-% call the generic \sectionheading to do the printing.
-%
-\newskip\secheadingskip
-\def\secheadingbreak{\dobreak \secheadingskip{-1000}}
-
-% Subsection titles.
-\newskip\subsecheadingskip
-\def\subsecheadingbreak{\dobreak \subsecheadingskip{-500}}
-
-% Subsubsection titles.
-\def\subsubsecheadingskip{\subsecheadingskip}
-\def\subsubsecheadingbreak{\subsecheadingbreak}
-
-
-% Print any size, any type, section title.
-%
-% #1 is the text, #2 is the section level (sec/subsec/subsubsec), #3 is
-% the section type for xrefs (Ynumbered, Ynothing, Yappendix), #4 is the
-% section number.
-%
-\def\sectionheading#1#2#3#4{%
- {%
- % Switch to the right set of fonts.
- \csname #2fonts\endcsname \rm
- %
- % Insert space above the heading.
- \csname #2headingbreak\endcsname
- %
- % Only insert the space after the number if we have a section number.
- \def\sectionlevel{#2}%
- \def\temptype{#3}%
- %
- \ifx\temptype\Ynothingkeyword
- \setbox0 = \hbox{}%
- \def\toctype{unn}%
- \gdef\thissection{#1}%
- \else\ifx\temptype\Yomitfromtockeyword
- % for @headings -- no section number, don't include in toc,
- % and don't redefine \thissection.
- \setbox0 = \hbox{}%
- \def\toctype{omit}%
- \let\sectionlevel=\empty
- \else\ifx\temptype\Yappendixkeyword
- \setbox0 = \hbox{#4\enspace}%
- \def\toctype{app}%
- \gdef\thissection{#1}%
- \else
- \setbox0 = \hbox{#4\enspace}%
- \def\toctype{num}%
- \gdef\thissection{#1}%
- \fi\fi\fi
- %
- % Write the toc entry (before \donoderef). See comments in \chfplain.
- \writetocentry{\toctype\sectionlevel}{#1}{#4}%
- %
- % Write the node reference (= pdf destination for pdftex).
- % Again, see comments in \chfplain.
- \donoderef{#3}%
- %
- % Output the actual section heading.
- \vbox{\hyphenpenalty=10000 \tolerance=5000 \parindent=0pt \raggedright
- \hangindent=\wd0 % zero if no section number
- \unhbox0 #1}%
- }%
- % Add extra space after the heading -- half of whatever came above it.
- % Don't allow stretch, though.
- \kern .5 \csname #2headingskip\endcsname
- %
- % Do not let the kern be a potential breakpoint, as it would be if it
- % was followed by glue.
- \nobreak
- %
- % We'll almost certainly start a paragraph next, so don't let that
- % glue accumulate. (Not a breakpoint because it's preceded by a
- % discardable item.)
- \vskip-\parskip
- %
- % This is purely so the last item on the list is a known \penalty >
- % 10000. This is so \startdefun can avoid allowing breakpoints after
- % section headings. Otherwise, it would insert a valid breakpoint between:
- %
- % @section sec-whatever
- % @deffn def-whatever
- \penalty 10001
-}
-
-
-\message{toc,}
-% Table of contents.
-\newwrite\tocfile
-
-% Write an entry to the toc file, opening it if necessary.
-% Called from @chapter, etc.
-%
-% Example usage: \writetocentry{sec}{Section Name}{\the\chapno.\the\secno}
-% We append the current node name (if any) and page number as additional
-% arguments for the \{chap,sec,...}entry macros which will eventually
-% read this. The node name is used in the pdf outlines as the
-% destination to jump to.
-%
-% We open the .toc file for writing here instead of at @setfilename (or
-% any other fixed time) so that @contents can be anywhere in the document.
-% But if #1 is `omit', then we don't do anything. This is used for the
-% table of contents chapter openings themselves.
-%
-\newif\iftocfileopened
-\def\omitkeyword{omit}%
-%
-\def\writetocentry#1#2#3{%
- \edef\writetoctype{#1}%
- \ifx\writetoctype\omitkeyword \else
- \iftocfileopened\else
- \immediate\openout\tocfile = \jobname.toc
- \global\tocfileopenedtrue
- \fi
- %
- \iflinks
- \toks0 = {#2}%
- \toks2 = \expandafter{\lastnode}%
- \edef\temp{\write\tocfile{\realbackslash #1entry{\the\toks0}{#3}%
- {\the\toks2}{\noexpand\folio}}}%
- \temp
- \fi
- \fi
- %
- % Tell \shipout to create a pdf destination on each page, if we're
- % writing pdf. These are used in the table of contents. We can't
- % just write one on every page because the title pages are numbered
- % 1 and 2 (the page numbers aren't printed), and so are the first
- % two pages of the document. Thus, we'd have two destinations named
- % `1', and two named `2'.
- \ifpdf \global\pdfmakepagedesttrue \fi
-}
-
-\newskip\contentsrightmargin \contentsrightmargin=1in
-\newcount\savepageno
-\newcount\lastnegativepageno \lastnegativepageno = -1
-
-% Prepare to read what we've written to \tocfile.
-%
-\def\startcontents#1{%
- % If @setchapternewpage on, and @headings double, the contents should
- % start on an odd page, unlike chapters. Thus, we maintain
- % \contentsalignmacro in parallel with \pagealignmacro.
- % From: Torbjorn Granlund <tege@matematik.su.se>
- \contentsalignmacro
- \immediate\closeout\tocfile
- %
- % Don't need to put `Contents' or `Short Contents' in the headline.
- % It is abundantly clear what they are.
- \def\thischapter{}%
- \chapmacro{#1}{Yomitfromtoc}{}%
- %
- \savepageno = \pageno
- \begingroup % Set up to handle contents files properly.
- \catcode`\\=0 \catcode`\{=1 \catcode`\}=2 \catcode`\@=11
- % We can't do this, because then an actual ^ in a section
- % title fails, e.g., @chapter ^ -- exponentiation. --karl, 9jul97.
- %\catcode`\^=7 % to see ^^e4 as \"a etc. juha@piuha.ydi.vtt.fi
- \raggedbottom % Worry more about breakpoints than the bottom.
- \advance\hsize by -\contentsrightmargin % Don't use the full line length.
- %
- % Roman numerals for page numbers.
- \ifnum \pageno>0 \global\pageno = \lastnegativepageno \fi
-}
-
-
-% Normal (long) toc.
-\def\contents{%
- \startcontents{\putwordTOC}%
- \openin 1 \jobname.toc
- \ifeof 1 \else
- \input \jobname.toc
- \fi
- \vfill \eject
- \contentsalignmacro % in case @setchapternewpage odd is in effect
- \ifeof 1 \else
- \pdfmakeoutlines
- \fi
- \closein 1
- \endgroup
- \lastnegativepageno = \pageno
- \global\pageno = \savepageno
-}
-
-% And just the chapters.
-\def\summarycontents{%
- \startcontents{\putwordShortTOC}%
- %
- \let\numchapentry = \shortchapentry
- \let\appentry = \shortchapentry
- \let\unnchapentry = \shortunnchapentry
- % We want a true roman here for the page numbers.
- \secfonts
- \let\rm=\shortcontrm \let\bf=\shortcontbf
- \let\sl=\shortcontsl \let\tt=\shortconttt
- \rm
- \hyphenpenalty = 10000
- \advance\baselineskip by 1pt % Open it up a little.
- \def\numsecentry##1##2##3##4{}
- \let\appsecentry = \numsecentry
- \let\unnsecentry = \numsecentry
- \let\numsubsecentry = \numsecentry
- \let\appsubsecentry = \numsecentry
- \let\unnsubsecentry = \numsecentry
- \let\numsubsubsecentry = \numsecentry
- \let\appsubsubsecentry = \numsecentry
- \let\unnsubsubsecentry = \numsecentry
- \openin 1 \jobname.toc
- \ifeof 1 \else
- \input \jobname.toc
- \fi
- \closein 1
- \vfill \eject
- \contentsalignmacro % in case @setchapternewpage odd is in effect
- \endgroup
- \lastnegativepageno = \pageno
- \global\pageno = \savepageno
-}
-\let\shortcontents = \summarycontents
-
-% Typeset the label for a chapter or appendix for the short contents.
-% The arg is, e.g., `A' for an appendix, or `3' for a chapter.
-%
-\def\shortchaplabel#1{%
- % This space should be enough, since a single number is .5em, and the
- % widest letter (M) is 1em, at least in the Computer Modern fonts.
- % But use \hss just in case.
- % (This space doesn't include the extra space that gets added after
- % the label; that gets put in by \shortchapentry above.)
- %
- % We'd like to right-justify chapter numbers, but that looks strange
- % with appendix letters. And right-justifying numbers and
- % left-justifying letters looks strange when there is less than 10
- % chapters. Have to read the whole toc once to know how many chapters
- % there are before deciding ...
- \hbox to 1em{#1\hss}%
-}
-
-% These macros generate individual entries in the table of contents.
-% The first argument is the chapter or section name.
-% The last argument is the page number.
-% The arguments in between are the chapter number, section number, ...
-
-% Chapters, in the main contents.
-\def\numchapentry#1#2#3#4{\dochapentry{#2\labelspace#1}{#4}}
-%
-% Chapters, in the short toc.
-% See comments in \dochapentry re vbox and related settings.
-\def\shortchapentry#1#2#3#4{%
- \tocentry{\shortchaplabel{#2}\labelspace #1}{\doshortpageno\bgroup#4\egroup}%
-}
-
-% Appendices, in the main contents.
-% Need the word Appendix, and a fixed-size box.
-%
-\def\appendixbox#1{%
- % We use M since it's probably the widest letter.
- \setbox0 = \hbox{\putwordAppendix{} M}%
- \hbox to \wd0{\putwordAppendix{} #1\hss}}
-%
-\def\appentry#1#2#3#4{\dochapentry{\appendixbox{#2}\labelspace#1}{#4}}
-
-% Unnumbered chapters.
-\def\unnchapentry#1#2#3#4{\dochapentry{#1}{#4}}
-\def\shortunnchapentry#1#2#3#4{\tocentry{#1}{\doshortpageno\bgroup#4\egroup}}
-
-% Sections.
-\def\numsecentry#1#2#3#4{\dosecentry{#2\labelspace#1}{#4}}
-\let\appsecentry=\numsecentry
-\def\unnsecentry#1#2#3#4{\dosecentry{#1}{#4}}
-
-% Subsections.
-\def\numsubsecentry#1#2#3#4{\dosubsecentry{#2\labelspace#1}{#4}}
-\let\appsubsecentry=\numsubsecentry
-\def\unnsubsecentry#1#2#3#4{\dosubsecentry{#1}{#4}}
-
-% And subsubsections.
-\def\numsubsubsecentry#1#2#3#4{\dosubsubsecentry{#2\labelspace#1}{#4}}
-\let\appsubsubsecentry=\numsubsubsecentry
-\def\unnsubsubsecentry#1#2#3#4{\dosubsubsecentry{#1}{#4}}
-
-% This parameter controls the indentation of the various levels.
-% Same as \defaultparindent.
-\newdimen\tocindent \tocindent = 15pt
-
-% Now for the actual typesetting. In all these, #1 is the text and #2 is the
-% page number.
-%
-% If the toc has to be broken over pages, we want it to be at chapters
-% if at all possible; hence the \penalty.
-\def\dochapentry#1#2{%
- \penalty-300 \vskip1\baselineskip plus.33\baselineskip minus.25\baselineskip
- \begingroup
- \chapentryfonts
- \tocentry{#1}{\dopageno\bgroup#2\egroup}%
- \endgroup
- \nobreak\vskip .25\baselineskip plus.1\baselineskip
-}
-
-\def\dosecentry#1#2{\begingroup
- \secentryfonts \leftskip=\tocindent
- \tocentry{#1}{\dopageno\bgroup#2\egroup}%
-\endgroup}
-
-\def\dosubsecentry#1#2{\begingroup
- \subsecentryfonts \leftskip=2\tocindent
- \tocentry{#1}{\dopageno\bgroup#2\egroup}%
-\endgroup}
-
-\def\dosubsubsecentry#1#2{\begingroup
- \subsubsecentryfonts \leftskip=3\tocindent
- \tocentry{#1}{\dopageno\bgroup#2\egroup}%
-\endgroup}
-
-% We use the same \entry macro as for the index entries.
-\let\tocentry = \entry
-
-% Space between chapter (or whatever) number and the title.
-\def\labelspace{\hskip1em \relax}
-
-\def\dopageno#1{{\rm #1}}
-\def\doshortpageno#1{{\rm #1}}
-
-\def\chapentryfonts{\secfonts \rm}
-\def\secentryfonts{\textfonts}
-\def\subsecentryfonts{\textfonts}
-\def\subsubsecentryfonts{\textfonts}
-
-
-\message{environments,}
-% @foo ... @end foo.
-
-% @point{}, @result{}, @expansion{}, @print{}, @equiv{}.
-%
-% Since these characters are used in examples, it should be an even number of
-% \tt widths. Each \tt character is 1en, so two makes it 1em.
-%
-\def\point{$\star$}
-\def\result{\leavevmode\raise.15ex\hbox to 1em{\hfil$\Rightarrow$\hfil}}
-\def\expansion{\leavevmode\raise.1ex\hbox to 1em{\hfil$\mapsto$\hfil}}
-\def\print{\leavevmode\lower.1ex\hbox to 1em{\hfil$\dashv$\hfil}}
-\def\equiv{\leavevmode\lower.1ex\hbox to 1em{\hfil$\ptexequiv$\hfil}}
-
-% The @error{} command.
-% Adapted from the TeXbook's \boxit.
-%
-\newbox\errorbox
-%
-{\tentt \global\dimen0 = 3em}% Width of the box.
-\dimen2 = .55pt % Thickness of rules
-% The text. (`r' is open on the right, `e' somewhat less so on the left.)
-\setbox0 = \hbox{\kern-.75pt \tensf error\kern-1.5pt}
-%
-\setbox\errorbox=\hbox to \dimen0{\hfil
- \hsize = \dimen0 \advance\hsize by -5.8pt % Space to left+right.
- \advance\hsize by -2\dimen2 % Rules.
- \vbox{%
- \hrule height\dimen2
- \hbox{\vrule width\dimen2 \kern3pt % Space to left of text.
- \vtop{\kern2.4pt \box0 \kern2.4pt}% Space above/below.
- \kern3pt\vrule width\dimen2}% Space to right.
- \hrule height\dimen2}
- \hfil}
-%
-\def\error{\leavevmode\lower.7ex\copy\errorbox}
-
-% @tex ... @end tex escapes into raw Tex temporarily.
-% One exception: @ is still an escape character, so that @end tex works.
-% But \@ or @@ will get a plain tex @ character.
-
-\envdef\tex{%
- \catcode `\\=0 \catcode `\{=1 \catcode `\}=2
- \catcode `\$=3 \catcode `\&=4 \catcode `\#=6
- \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie
- \catcode `\%=14
- \catcode `\+=\other
- \catcode `\"=\other
- \catcode `\|=\other
- \catcode `\<=\other
- \catcode `\>=\other
- \escapechar=`\\
- %
- \let\b=\ptexb
- \let\bullet=\ptexbullet
- \let\c=\ptexc
- \let\,=\ptexcomma
- \let\.=\ptexdot
- \let\dots=\ptexdots
- \let\equiv=\ptexequiv
- \let\!=\ptexexclam
- \let\i=\ptexi
- \let\indent=\ptexindent
- \let\noindent=\ptexnoindent
- \let\{=\ptexlbrace
- \let\+=\tabalign
- \let\}=\ptexrbrace
- \let\/=\ptexslash
- \let\*=\ptexstar
- \let\t=\ptext
- %
- \def\endldots{\mathinner{\ldots\ldots\ldots\ldots}}%
- \def\enddots{\relax\ifmmode\endldots\else$\mathsurround=0pt \endldots\,$\fi}%
- \def\@{@}%
-}
-% There is no need to define \Etex.
-
-% Define @lisp ... @end lisp.
-% @lisp environment forms a group so it can rebind things,
-% including the definition of @end lisp (which normally is erroneous).
-
-% Amount to narrow the margins by for @lisp.
-\newskip\lispnarrowing \lispnarrowing=0.4in
-
-% This is the definition that ^^M gets inside @lisp, @example, and other
-% such environments. \null is better than a space, since it doesn't
-% have any width.
-\def\lisppar{\null\endgraf}
-
-% This space is always present above and below environments.
-\newskip\envskipamount \envskipamount = 0pt
-
-% Make spacing and below environment symmetrical. We use \parskip here
-% to help in doing that, since in @example-like environments \parskip
-% is reset to zero; thus the \afterenvbreak inserts no space -- but the
-% start of the next paragraph will insert \parskip.
-%
-\def\aboveenvbreak{{%
- % =10000 instead of <10000 because of a special case in \itemzzz and
- % \sectionheading, q.v.
- \ifnum \lastpenalty=10000 \else
- \advance\envskipamount by \parskip
- \endgraf
- \ifdim\lastskip<\envskipamount
- \removelastskip
- % it's not a good place to break if the last penalty was \nobreak
- % or better ...
- \ifnum\lastpenalty<10000 \penalty-50 \fi
- \vskip\envskipamount
- \fi
- \fi
-}}
-
-\let\afterenvbreak = \aboveenvbreak
-
-% \nonarrowing is a flag. If "set", @lisp etc don't narrow margins.
-\let\nonarrowing=\relax
-
-% @cartouche ... @end cartouche: draw rectangle w/rounded corners around
-% environment contents.
-\font\circle=lcircle10
-\newdimen\circthick
-\newdimen\cartouter\newdimen\cartinner
-\newskip\normbskip\newskip\normpskip\newskip\normlskip
-\circthick=\fontdimen8\circle
-%
-\def\ctl{{\circle\char'013\hskip -6pt}}% 6pt from pl file: 1/2charwidth
-\def\ctr{{\hskip 6pt\circle\char'010}}
-\def\cbl{{\circle\char'012\hskip -6pt}}
-\def\cbr{{\hskip 6pt\circle\char'011}}
-\def\carttop{\hbox to \cartouter{\hskip\lskip
- \ctl\leaders\hrule height\circthick\hfil\ctr
- \hskip\rskip}}
-\def\cartbot{\hbox to \cartouter{\hskip\lskip
- \cbl\leaders\hrule height\circthick\hfil\cbr
- \hskip\rskip}}
-%
-\newskip\lskip\newskip\rskip
-
-\envdef\cartouche{%
- \ifhmode\par\fi % can't be in the midst of a paragraph.
- \startsavinginserts
- \lskip=\leftskip \rskip=\rightskip
- \leftskip=0pt\rightskip=0pt % we want these *outside*.
- \cartinner=\hsize \advance\cartinner by-\lskip
- \advance\cartinner by-\rskip
- \cartouter=\hsize
- \advance\cartouter by 18.4pt % allow for 3pt kerns on either
- % side, and for 6pt waste from
- % each corner char, and rule thickness
- \normbskip=\baselineskip \normpskip=\parskip \normlskip=\lineskip
- % Flag to tell @lisp, etc., not to narrow margin.
- \let\nonarrowing=\comment
- \vbox\bgroup
- \baselineskip=0pt\parskip=0pt\lineskip=0pt
- \carttop
- \hbox\bgroup
- \hskip\lskip
- \vrule\kern3pt
- \vbox\bgroup
- \kern3pt
- \hsize=\cartinner
- \baselineskip=\normbskip
- \lineskip=\normlskip
- \parskip=\normpskip
- \vskip -\parskip
- \comment % For explanation, see the end of \def\group.
-}
-\def\Ecartouche{%
- \ifhmode\par\fi
- \kern3pt
- \egroup
- \kern3pt\vrule
- \hskip\rskip
- \egroup
- \cartbot
- \egroup
- \checkinserts
-}
-
-
-% This macro is called at the beginning of all the @example variants,
-% inside a group.
-\def\nonfillstart{%
- \aboveenvbreak
- \hfuzz = 12pt % Don't be fussy
- \sepspaces % Make spaces be word-separators rather than space tokens.
- \let\par = \lisppar % don't ignore blank lines
- \obeylines % each line of input is a line of output
- \parskip = 0pt
- \parindent = 0pt
- \emergencystretch = 0pt % don't try to avoid overfull boxes
- % @cartouche defines \nonarrowing to inhibit narrowing
- % at next level down.
- \ifx\nonarrowing\relax
- \advance \leftskip by \lispnarrowing
- \exdentamount=\lispnarrowing
- \fi
- \let\exdent=\nofillexdent
-}
-
-% If you want all examples etc. small: @set dispenvsize small.
-% If you want even small examples the full size: @set dispenvsize nosmall.
-% This affects the following displayed environments:
-% @example, @display, @format, @lisp
-%
-\def\smallword{small}
-\def\nosmallword{nosmall}
-\let\SETdispenvsize\relax
-\def\setnormaldispenv{%
- \ifx\SETdispenvsize\smallword
- \smallexamplefonts \rm
- \fi
-}
-\def\setsmalldispenv{%
- \ifx\SETdispenvsize\nosmallword
- \else
- \smallexamplefonts \rm
- \fi
-}
-
-% We often define two environments, @foo and @smallfoo.
-% Let's do it by one command:
-\def\makedispenv #1#2{
- \expandafter\envdef\csname#1\endcsname {\setnormaldispenv #2}
- \expandafter\envdef\csname small#1\endcsname {\setsmalldispenv #2}
- \expandafter\let\csname E#1\endcsname \afterenvbreak
- \expandafter\let\csname Esmall#1\endcsname \afterenvbreak
-}
-
-% Define two synonyms:
-\def\maketwodispenvs #1#2#3{
- \makedispenv{#1}{#3}
- \makedispenv{#2}{#3}
-}
-
-% @lisp: indented, narrowed, typewriter font; @example: same as @lisp.
-%
-% @smallexample and @smalllisp: use smaller fonts.
-% Originally contributed by Pavel@xerox.
-%
-\maketwodispenvs {lisp}{example}{%
- \nonfillstart
- \tt
- \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special.
- \gobble % eat return
-}
-
-% @display/@smalldisplay: same as @lisp except keep current font.
-%
-\makedispenv {display}{%
- \nonfillstart
- \gobble
-}
-
-% @format/@smallformat: same as @display except don't narrow margins.
-%
-\makedispenv{format}{%
- \let\nonarrowing = t%
- \nonfillstart
- \gobble
-}
-
-% @flushleft: same as @format, but doesn't obey \SETdispenvsize.
-\envdef\flushleft{%
- \let\nonarrowing = t%
- \nonfillstart
- \gobble
-}
-\let\Eflushleft = \afterenvbreak
-
-% @flushright.
-%
-\envdef\flushright{%
- \let\nonarrowing = t%
- \nonfillstart
- \advance\leftskip by 0pt plus 1fill
- \gobble
-}
-\let\Eflushright = \afterenvbreak
-
-
-% @quotation does normal linebreaking (hence we can't use \nonfillstart)
-% and narrows the margins. We keep \parskip nonzero in general, since
-% we're doing normal filling. So, when using \aboveenvbreak and
-% \afterenvbreak, temporarily make \parskip 0.
-%
-\envdef\quotation{%
- {\parskip=0pt \aboveenvbreak}% because \aboveenvbreak inserts \parskip
- \parindent=0pt
- %
- % @cartouche defines \nonarrowing to inhibit narrowing at next level down.
- \ifx\nonarrowing\relax
- \advance\leftskip by \lispnarrowing
- \advance\rightskip by \lispnarrowing
- \exdentamount = \lispnarrowing
- \let\nonarrowing = \relax
- \fi
- \parsearg\quotationlabel
-}
-
-% We have retained a nonzero parskip for the environment, since we're
-% doing normal filling.
-%
-\def\Equotation{%
- \par
- \ifx\quotationauthor\undefined\else
- % indent a bit.
- \leftline{\kern 2\leftskip \sl ---\quotationauthor}%
- \fi
- {\parskip=0pt \afterenvbreak}%
-}
-
-% If we're given an argument, typeset it in bold with a colon after.
-\def\quotationlabel#1{%
- \def\temp{#1}%
- \ifx\temp\empty \else
- {\bf #1: }%
- \fi
-}
-
-
-% LaTeX-like @verbatim...@end verbatim and @verb{<char>...<char>}
-% If we want to allow any <char> as delimiter,
-% we need the curly braces so that makeinfo sees the @verb command, eg:
-% `@verbx...x' would look like the '@verbx' command. --janneke@gnu.org
-%
-% [Knuth]: Donald Ervin Knuth, 1996. The TeXbook.
-%
-% [Knuth] p.344; only we need to do the other characters Texinfo sets
-% active too. Otherwise, they get lost as the first character on a
-% verbatim line.
-\def\dospecials{%
- \do\ \do\\\do\{\do\}\do\$\do\&%
- \do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~%
- \do\<\do\>\do\|\do\@\do+\do\"%
-}
-%
-% [Knuth] p. 380
-\def\uncatcodespecials{%
- \def\do##1{\catcode`##1=\other}\dospecials}
-%
-% [Knuth] pp. 380,381,391
-% Disable Spanish ligatures ?` and !` of \tt font
-\begingroup
- \catcode`\`=\active\gdef`{\relax\lq}
-\endgroup
-%
-% Setup for the @verb command.
-%
-% Eight spaces for a tab
-\begingroup
- \catcode`\^^I=\active
- \gdef\tabeightspaces{\catcode`\^^I=\active\def^^I{\ \ \ \ \ \ \ \ }}
-\endgroup
-%
-\def\setupverb{%
- \tt % easiest (and conventionally used) font for verbatim
- \def\par{\leavevmode\endgraf}%
- \catcode`\`=\active
- \tabeightspaces
- % Respect line breaks,
- % print special symbols as themselves, and
- % make each space count
- % must do in this order:
- \obeylines \uncatcodespecials \sepspaces
-}
-
-% Setup for the @verbatim environment
-%
-% Real tab expansion
-\newdimen\tabw \setbox0=\hbox{\tt\space} \tabw=8\wd0 % tab amount
-%
-\def\starttabbox{\setbox0=\hbox\bgroup}
-\begingroup
- \catcode`\^^I=\active
- \gdef\tabexpand{%
- \catcode`\^^I=\active
- \def^^I{\leavevmode\egroup
- \dimen0=\wd0 % the width so far, or since the previous tab
- \divide\dimen0 by\tabw
- \multiply\dimen0 by\tabw % compute previous multiple of \tabw
- \advance\dimen0 by\tabw % advance to next multiple of \tabw
- \wd0=\dimen0 \box0 \starttabbox
- }%
- }
-\endgroup
-\def\setupverbatim{%
- \nonfillstart
- \advance\leftskip by -\defbodyindent
- % Easiest (and conventionally used) font for verbatim
- \tt
- \def\par{\leavevmode\egroup\box0\endgraf}%
- \catcode`\`=\active
- \tabexpand
- % Respect line breaks,
- % print special symbols as themselves, and
- % make each space count
- % must do in this order:
- \obeylines \uncatcodespecials \sepspaces
- \everypar{\starttabbox}%
-}
-
-% Do the @verb magic: verbatim text is quoted by unique
-% delimiter characters. Before first delimiter expect a
-% right brace, after last delimiter expect closing brace:
-%
-% \def\doverb'{'<char>#1<char>'}'{#1}
-%
-% [Knuth] p. 382; only eat outer {}
-\begingroup
- \catcode`[=1\catcode`]=2\catcode`\{=\other\catcode`\}=\other
- \gdef\doverb{#1[\def\next##1#1}[##1\endgroup]\next]
-\endgroup
-%
-\def\verb{\begingroup\setupverb\doverb}
-%
-%
-% Do the @verbatim magic: define the macro \doverbatim so that
-% the (first) argument ends when '@end verbatim' is reached, ie:
-%
-% \def\doverbatim#1@end verbatim{#1}
-%
-% For Texinfo it's a lot easier than for LaTeX,
-% because texinfo's \verbatim doesn't stop at '\end{verbatim}':
-% we need not redefine '\', '{' and '}'.
-%
-% Inspired by LaTeX's verbatim command set [latex.ltx]
-%
-\begingroup
- \catcode`\ =\active
- \obeylines %
- % ignore everything up to the first ^^M, that's the newline at the end
- % of the @verbatim input line itself. Otherwise we get an extra blank
- % line in the output.
- \xdef\doverbatim#1^^M#2@end verbatim{#2\noexpand\end\gobble verbatim}%
- % We really want {...\end verbatim} in the body of the macro, but
- % without the active space; thus we have to use \xdef and \gobble.
-\endgroup
-%
-\envdef\verbatim{%
- \setupverbatim\doverbatim
-}
-\let\Everbatim = \afterenvbreak
-
-
-% @verbatiminclude FILE - insert text of file in verbatim environment.
-%
-\def\verbatiminclude{\parseargusing\filenamecatcodes\doverbatiminclude}
-%
-\def\doverbatiminclude#1{%
- {%
- \makevalueexpandable
- \setupverbatim
- \input #1
- \afterenvbreak
- }%
-}
-
-% @copying ... @end copying.
-% Save the text away for @insertcopying later.
-%
-% We save the uninterpreted tokens, rather than creating a box.
-% Saving the text in a box would be much easier, but then all the
-% typesetting commands (@smallbook, font changes, etc.) have to be done
-% beforehand -- and a) we want @copying to be done first in the source
-% file; b) letting users define the frontmatter in as flexible order as
-% possible is very desirable.
-%
-\def\copying{\checkenv{}\begingroup\scanargctxt\docopying}
-\def\docopying#1@end copying{\endgroup\def\copyingtext{#1}}
-%
-\def\insertcopying{%
- \begingroup
- \parindent = 0pt % paragraph indentation looks wrong on title page
- \scanexp\copyingtext
- \endgroup
-}
-
-\message{defuns,}
-% @defun etc.
-
-\newskip\defbodyindent \defbodyindent=.4in
-\newskip\defargsindent \defargsindent=50pt
-\newskip\deflastargmargin \deflastargmargin=18pt
-
-% Start the processing of @deffn:
-\def\startdefun{%
- \ifnum\lastpenalty<10000
- \medbreak
- \else
- % If there are two @def commands in a row, we'll have a \nobreak,
- % which is there to keep the function description together with its
- % header. But if there's nothing but headers, we need to allow a
- % break somewhere. Check specifically for penalty 10002, inserted
- % by \defargscommonending, instead of 10000, since the sectioning
- % commands also insert a nobreak penalty, and we don't want to allow
- % a break between a section heading and a defun.
- %
- \ifnum\lastpenalty=10002 \penalty2000 \fi
- %
- % Similarly, after a section heading, do not allow a break.
- % But do insert the glue.
- \medskip % preceded by discardable penalty, so not a breakpoint
- \fi
- %
- \parindent=0in
- \advance\leftskip by \defbodyindent
- \exdentamount=\defbodyindent
-}
-
-\def\dodefunx#1{%
- % First, check whether we are in the right environment:
- \checkenv#1%
- %
- % As above, allow line break if we have multiple x headers in a row.
- % It's not a great place, though.
- \ifnum\lastpenalty=10002 \penalty3000 \fi
- %
- % And now, it's time to reuse the body of the original defun:
- \expandafter\gobbledefun#1%
-}
-\def\gobbledefun#1\startdefun{}
-
-% \printdefunline \deffnheader{text}
-%
-\def\printdefunline#1#2{%
- \begingroup
- % call \deffnheader:
- #1#2 \endheader
- % common ending:
- \interlinepenalty = 10000
- \advance\rightskip by 0pt plus 1fil
- \endgraf
- \nobreak\vskip -\parskip
- \penalty 10002 % signal to \startdefun and \dodefunx
- % Some of the @defun-type tags do not enable magic parentheses,
- % rendering the following check redundant. But we don't optimize.
- \checkparencounts
- \endgroup
-}
-
-\def\Edefun{\endgraf\medbreak}
-
-% \makedefun{deffn} creates \deffn, \deffnx and \Edeffn;
-% the only thing remainnig is to define \deffnheader.
-%
-\def\makedefun#1{%
- \expandafter\let\csname E#1\endcsname = \Edefun
- \edef\temp{\noexpand\domakedefun
- \makecsname{#1}\makecsname{#1x}\makecsname{#1header}}%
- \temp
-}
-
-% \domakedefun \deffn \deffnx \deffnheader
-%
-% Define \deffn and \deffnx, without parameters.
-% \deffnheader has to be defined explicitly.
-%
-\def\domakedefun#1#2#3{%
- \envdef#1{%
- \startdefun
- \parseargusing\activeparens{\printdefunline#3}%
- }%
- \def#2{\dodefunx#1}%
- \def#3%
-}
-
-%%% Untyped functions:
-
-% @deffn category name args
-\makedefun{deffn}{\deffngeneral{}}
-
-% @deffn category class name args
-\makedefun{defop}#1 {\defopon{#1\ \putwordon}}
-
-% \defopon {category on}class name args
-\def\defopon#1#2 {\deffngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
-
-% \deffngeneral {subind}category name args
-%
-\def\deffngeneral#1#2 #3 #4\endheader{%
- % Remember that \dosubind{fn}{foo}{} is equivalent to \doind{fn}{foo}.
- \dosubind{fn}{\code{#3}}{#1}%
- \defname{#2}{}{#3}\magicamp\defunargs{#4\unskip}%
-}
-
-%%% Typed functions:
-
-% @deftypefn category type name args
-\makedefun{deftypefn}{\deftypefngeneral{}}
-
-% @deftypeop category class type name args
-\makedefun{deftypeop}#1 {\deftypeopon{#1\ \putwordon}}
-
-% \deftypeopon {category on}class type name args
-\def\deftypeopon#1#2 {\deftypefngeneral{\putwordon\ \code{#2}}{#1\ \code{#2}} }
-
-% \deftypefngeneral {subind}category type name args
-%
-\def\deftypefngeneral#1#2 #3 #4 #5\endheader{%
- \dosubind{fn}{\code{#4}}{#1}%
- \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
-}
-
-%%% Typed variables:
-
-% @deftypevr category type var args
-\makedefun{deftypevr}{\deftypecvgeneral{}}
-
-% @deftypecv category class type var args
-\makedefun{deftypecv}#1 {\deftypecvof{#1\ \putwordof}}
-
-% \deftypecvof {category of}class type var args
-\def\deftypecvof#1#2 {\deftypecvgeneral{\putwordof\ \code{#2}}{#1\ \code{#2}} }
-
-% \deftypecvgeneral {subind}category type var args
-%
-\def\deftypecvgeneral#1#2 #3 #4 #5\endheader{%
- \dosubind{vr}{\code{#4}}{#1}%
- \defname{#2}{#3}{#4}\defunargs{#5\unskip}%
-}
-
-%%% Untyped variables:
-
-% @defvr category var args
-\makedefun{defvr}#1 {\deftypevrheader{#1} {} }
-
-% @defcv category class var args
-\makedefun{defcv}#1 {\defcvof{#1\ \putwordof}}
-
-% \defcvof {category of}class var args
-\def\defcvof#1#2 {\deftypecvof{#1}#2 {} }
-
-%%% Type:
-% @deftp category name args
-\makedefun{deftp}#1 #2 #3\endheader{%
- \doind{tp}{\code{#2}}%
- \defname{#1}{}{#2}\defunargs{#3\unskip}%
-}
-
-% Remaining @defun-like shortcuts:
-\makedefun{defun}{\deffnheader{\putwordDeffunc} }
-\makedefun{defmac}{\deffnheader{\putwordDefmac} }
-\makedefun{defspec}{\deffnheader{\putwordDefspec} }
-\makedefun{deftypefun}{\deftypefnheader{\putwordDeffunc} }
-\makedefun{defvar}{\defvrheader{\putwordDefvar} }
-\makedefun{defopt}{\defvrheader{\putwordDefopt} }
-\makedefun{deftypevar}{\deftypevrheader{\putwordDefvar} }
-\makedefun{defmethod}{\defopon\putwordMethodon}
-\makedefun{deftypemethod}{\deftypeopon\putwordMethodon}
-\makedefun{defivar}{\defcvof\putwordInstanceVariableof}
-\makedefun{deftypeivar}{\deftypecvof\putwordInstanceVariableof}
-
-% \defname, which formats the name of the @def (not the args).
-% #1 is the category, such as "Function".
-% #2 is the return type, if any.
-% #3 is the function name.
-%
-% We are followed by (but not passed) the arguments, if any.
-%
-\def\defname#1#2#3{%
- % Get the values of \leftskip and \rightskip as they were outside the @def...
- \advance\leftskip by -\defbodyindent
- %
- % How we'll format the type name. Putting it in brackets helps
- % distinguish it from the body text that may end up on the next line
- % just below it.
- \def\temp{#1}%
- \setbox0=\hbox{\kern\deflastargmargin \ifx\temp\empty\else [\rm\temp]\fi}
- %
- % Figure out line sizes for the paragraph shape.
- % The first line needs space for \box0; but if \rightskip is nonzero,
- % we need only space for the part of \box0 which exceeds it:
- \dimen0=\hsize \advance\dimen0 by -\wd0 \advance\dimen0 by \rightskip
- % The continuations:
- \dimen2=\hsize \advance\dimen2 by -\defargsindent
- % (plain.tex says that \dimen1 should be used only as global.)
- \parshape 2 0in \dimen0 \defargsindent \dimen2
- %
- % Put the type name to the right margin.
- \noindent
- \hbox to 0pt{%
- \hfil\box0 \kern-\hsize
- % \hsize has to be shortened this way:
- \kern\leftskip
- % Intentionally do not respect \rightskip, since we need the space.
- }%
- %
- % Allow all lines to be underfull without complaint:
- \tolerance=10000 \hbadness=10000
- \exdentamount=\defbodyindent
- {%
- % defun fonts. We use typewriter by default (used to be bold) because:
- % . we're printing identifiers, they should be in tt in principle.
- % . in languages with many accents, such as Czech or French, it's
- % common to leave accents off identifiers. The result looks ok in
- % tt, but exceedingly strange in rm.
- % . we don't want -- and --- to be treated as ligatures.
- % . this still does not fix the ?` and !` ligatures, but so far no
- % one has made identifiers using them :).
- \df \tt
- \def\temp{#2}% return value type
- \ifx\temp\empty\else \tclose{\temp} \fi
- #3% output function name
- }%
- {\rm\enskip}% hskip 0.5 em of \tenrm
- %
- \boldbrax
- % arguments will be output next, if any.
-}
-
-% Print arguments in slanted roman (not ttsl), inconsistently with using
-% tt for the name. This is because literal text is sometimes needed in
-% the argument list (groff manual), and ttsl and tt are not very
-% distinguishable. Prevent hyphenation at `-' chars.
-%
-\def\defunargs#1{%
- % use sl by default (not ttsl),
- % tt for the names.
- \df \sl \hyphenchar\font=0
- %
- % On the other hand, if an argument has two dashes (for instance), we
- % want a way to get ttsl. Let's try @var for that.
- \let\var=\ttslanted
- #1%
- \sl\hyphenchar\font=45
-}
-
-% We want ()&[] to print specially on the defun line.
-%
-\def\activeparens{%
- \catcode`\(=\active \catcode`\)=\active
- \catcode`\[=\active \catcode`\]=\active
- \catcode`\&=\active
-}
-
-% Make control sequences which act like normal parenthesis chars.
-\let\lparen = ( \let\rparen = )
-
-% Be sure that we always have a definition for `(', etc. For example,
-% if the fn name has parens in it, \boldbrax will not be in effect yet,
-% so TeX would otherwise complain about undefined control sequence.
-{
- \activeparens
- \global\let(=\lparen \global\let)=\rparen
- \global\let[=\lbrack \global\let]=\rbrack
- \global\let& = \&
-
- \gdef\boldbrax{\let(=\opnr\let)=\clnr\let[=\lbrb\let]=\rbrb}
- \gdef\magicamp{\let&=\amprm}
-}
-
-\newcount\parencount
-
-% If we encounter &foo, then turn on ()-hacking afterwards
-\newif\ifampseen
-\def\amprm#1 {\ampseentrue{\bf\&#1 }}
-
-\def\parenfont{%
- \ifampseen
- % At the first level, print parens in roman,
- % otherwise use the default font.
- \ifnum \parencount=1 \rm \fi
- \else
- % The \sf parens (in \boldbrax) actually are a little bolder than
- % the contained text. This is especially needed for [ and ] .
- \sf
- \fi
-}
-\def\infirstlevel#1{%
- \ifampseen
- \ifnum\parencount=1
- #1%
- \fi
- \fi
-}
-\def\bfafterword#1 {#1 \bf}
-
-\def\opnr{%
- \global\advance\parencount by 1
- {\parenfont(}%
- \infirstlevel \bfafterword
-}
-\def\clnr{%
- {\parenfont)}%
- \infirstlevel \sl
- \global\advance\parencount by -1
-}
-
-\newcount\brackcount
-\def\lbrb{%
- \global\advance\brackcount by 1
- {\bf[}%
-}
-\def\rbrb{%
- {\bf]}%
- \global\advance\brackcount by -1
-}
-
-\def\checkparencounts{%
- \ifnum\parencount=0 \else \badparencount \fi
- \ifnum\brackcount=0 \else \badbrackcount \fi
-}
-\def\badparencount{%
- \errmessage{Unbalanced parentheses in @def}%
- \global\parencount=0
-}
-\def\badbrackcount{%
- \errmessage{Unbalanced square braces in @def}%
- \global\brackcount=0
-}
-
-
-\message{macros,}
-% @macro.
-
-% To do this right we need a feature of e-TeX, \scantokens,
-% which we arrange to emulate with a temporary file in ordinary TeX.
-\ifx\eTeXversion\undefined
- \newwrite\macscribble
- \def\scantokens#1{%
- \toks0={#1}%
- \immediate\openout\macscribble=\jobname.tmp
- \immediate\write\macscribble{\the\toks0}%
- \immediate\closeout\macscribble
- \input \jobname.tmp
- }
-\fi
-
-\def\scanmacro#1{%
- \begingroup
- \newlinechar`\^^M
- \let\xeatspaces\eatspaces
- % Undo catcode changes of \startcontents and \doprintindex
- % When called from @insertcopying or (short)caption, we need active
- % backslash to get it printed correctly. Previously, we had
- % \catcode`\\=\other instead. We'll see whether a problem appears
- % with macro expansion. --kasal, 19aug04
- \catcode`\@=0 \catcode`\\=\active \escapechar=`\@
- % ... and \example
- \spaceisspace
- %
- % Append \endinput to make sure that TeX does not see the ending newline.
- %
- % I've verified that it is necessary both for e-TeX and for ordinary TeX
- % --kasal, 29nov03
- \scantokens{#1\endinput}%
- \endgroup
-}
-
-\def\scanexp#1{%
- \edef\temp{\noexpand\scanmacro{#1}}%
- \temp
-}
-
-\newcount\paramno % Count of parameters
-\newtoks\macname % Macro name
-\newif\ifrecursive % Is it recursive?
-\def\macrolist{} % List of all defined macros in the form
- % \do\macro1\do\macro2...
-
-% Utility routines.
-% This does \let #1 = #2, with \csnames; that is,
-% \let \csname#1\endcsname = \csname#2\endcsname
-% (except of course we have to play expansion games).
-%
-\def\cslet#1#2{%
- \expandafter\let
- \csname#1\expandafter\endcsname
- \csname#2\endcsname
-}
-
-% Trim leading and trailing spaces off a string.
-% Concepts from aro-bend problem 15 (see CTAN).
-{\catcode`\@=11
-\gdef\eatspaces #1{\expandafter\trim@\expandafter{#1 }}
-\gdef\trim@ #1{\trim@@ @#1 @ #1 @ @@}
-\gdef\trim@@ #1@ #2@ #3@@{\trim@@@\empty #2 @}
-\def\unbrace#1{#1}
-\unbrace{\gdef\trim@@@ #1 } #2@{#1}
-}
-
-% Trim a single trailing ^^M off a string.
-{\catcode`\^^M=\other \catcode`\Q=3%
-\gdef\eatcr #1{\eatcra #1Q^^MQ}%
-\gdef\eatcra#1^^MQ{\eatcrb#1Q}%
-\gdef\eatcrb#1Q#2Q{#1}%
-}
-
-% Macro bodies are absorbed as an argument in a context where
-% all characters are catcode 10, 11 or 12, except \ which is active
-% (as in normal texinfo). It is necessary to change the definition of \.
-
-% It's necessary to have hard CRs when the macro is executed. This is
-% done by making ^^M (\endlinechar) catcode 12 when reading the macro
-% body, and then making it the \newlinechar in \scanmacro.
-
-\def\scanctxt{%
- \catcode`\"=\other
- \catcode`\+=\other
- \catcode`\<=\other
- \catcode`\>=\other
- \catcode`\@=\other
- \catcode`\^=\other
- \catcode`\_=\other
- \catcode`\|=\other
- \catcode`\~=\other
-}
-
-\def\scanargctxt{%
- \scanctxt
- \catcode`\\=\other
- \catcode`\^^M=\other
-}
-
-\def\macrobodyctxt{%
- \scanctxt
- \catcode`\{=\other
- \catcode`\}=\other
- \catcode`\^^M=\other
- \usembodybackslash
-}
-
-\def\macroargctxt{%
- \scanctxt
- \catcode`\\=\other
-}
-
-% \mbodybackslash is the definition of \ in @macro bodies.
-% It maps \foo\ => \csname macarg.foo\endcsname => #N
-% where N is the macro parameter number.
-% We define \csname macarg.\endcsname to be \realbackslash, so
-% \\ in macro replacement text gets you a backslash.
-
-{\catcode`@=0 @catcode`@\=@active
- @gdef@usembodybackslash{@let\=@mbodybackslash}
- @gdef@mbodybackslash#1\{@csname macarg.#1@endcsname}
-}
-\expandafter\def\csname macarg.\endcsname{\realbackslash}
-
-\def\macro{\recursivefalse\parsearg\macroxxx}
-\def\rmacro{\recursivetrue\parsearg\macroxxx}
-
-\def\macroxxx#1{%
- \getargs{#1}% now \macname is the macname and \argl the arglist
- \ifx\argl\empty % no arguments
- \paramno=0%
- \else
- \expandafter\parsemargdef \argl;%
- \fi
- \if1\csname ismacro.\the\macname\endcsname
- \message{Warning: redefining \the\macname}%
- \else
- \expandafter\ifx\csname \the\macname\endcsname \relax
- \else \errmessage{Macro name \the\macname\space already defined}\fi
- \global\cslet{macsave.\the\macname}{\the\macname}%
- \global\expandafter\let\csname ismacro.\the\macname\endcsname=1%
- % Add the macroname to \macrolist
- \toks0 = \expandafter{\macrolist\do}%
- \xdef\macrolist{\the\toks0
- \expandafter\noexpand\csname\the\macname\endcsname}%
- \fi
- \begingroup \macrobodyctxt
- \ifrecursive \expandafter\parsermacbody
- \else \expandafter\parsemacbody
- \fi}
-
-\parseargdef\unmacro{%
- \if1\csname ismacro.#1\endcsname
- \global\cslet{#1}{macsave.#1}%
- \global\expandafter\let \csname ismacro.#1\endcsname=0%
- % Remove the macro name from \macrolist:
- \begingroup
- \expandafter\let\csname#1\endcsname \relax
- \let\do\unmacrodo
- \xdef\macrolist{\macrolist}%
- \endgroup
- \else
- \errmessage{Macro #1 not defined}%
- \fi
-}
-
-% Called by \do from \dounmacro on each macro. The idea is to omit any
-% macro definitions that have been changed to \relax.
-%
-\def\unmacrodo#1{%
- \ifx#1\relax
- % remove this
- \else
- \noexpand\do \noexpand #1%
- \fi
-}
-
-% This makes use of the obscure feature that if the last token of a
-% <parameter list> is #, then the preceding argument is delimited by
-% an opening brace, and that opening brace is not consumed.
-\def\getargs#1{\getargsxxx#1{}}
-\def\getargsxxx#1#{\getmacname #1 \relax\getmacargs}
-\def\getmacname #1 #2\relax{\macname={#1}}
-\def\getmacargs#1{\def\argl{#1}}
-
-% Parse the optional {params} list. Set up \paramno and \paramlist
-% so \defmacro knows what to do. Define \macarg.blah for each blah
-% in the params list, to be ##N where N is the position in that list.
-% That gets used by \mbodybackslash (above).
-
-% We need to get `macro parameter char #' into several definitions.
-% The technique used is stolen from LaTeX: let \hash be something
-% unexpandable, insert that wherever you need a #, and then redefine
-% it to # just before using the token list produced.
-%
-% The same technique is used to protect \eatspaces till just before
-% the macro is used.
-
-\def\parsemargdef#1;{\paramno=0\def\paramlist{}%
- \let\hash\relax\let\xeatspaces\relax\parsemargdefxxx#1,;,}
-\def\parsemargdefxxx#1,{%
- \if#1;\let\next=\relax
- \else \let\next=\parsemargdefxxx
- \advance\paramno by 1%
- \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname
- {\xeatspaces{\hash\the\paramno}}%
- \edef\paramlist{\paramlist\hash\the\paramno,}%
- \fi\next}
-
-% These two commands read recursive and nonrecursive macro bodies.
-% (They're different since rec and nonrec macros end differently.)
-
-\long\def\parsemacbody#1@end macro%
-{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
-\long\def\parsermacbody#1@end rmacro%
-{\xdef\temp{\eatcr{#1}}\endgroup\defmacro}%
-
-% This defines the macro itself. There are six cases: recursive and
-% nonrecursive macros of zero, one, and many arguments.
-% Much magic with \expandafter here.
-% \xdef is used so that macro definitions will survive the file
-% they're defined in; @include reads the file inside a group.
-\def\defmacro{%
- \let\hash=##% convert placeholders to macro parameter chars
- \ifrecursive
- \ifcase\paramno
- % 0
- \expandafter\xdef\csname\the\macname\endcsname{%
- \noexpand\scanmacro{\temp}}%
- \or % 1
- \expandafter\xdef\csname\the\macname\endcsname{%
- \bgroup\noexpand\macroargctxt
- \noexpand\braceorline
- \expandafter\noexpand\csname\the\macname xxx\endcsname}%
- \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
- \egroup\noexpand\scanmacro{\temp}}%
- \else % many
- \expandafter\xdef\csname\the\macname\endcsname{%
- \bgroup\noexpand\macroargctxt
- \noexpand\csname\the\macname xx\endcsname}%
- \expandafter\xdef\csname\the\macname xx\endcsname##1{%
- \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
- \expandafter\expandafter
- \expandafter\xdef
- \expandafter\expandafter
- \csname\the\macname xxx\endcsname
- \paramlist{\egroup\noexpand\scanmacro{\temp}}%
- \fi
- \else
- \ifcase\paramno
- % 0
- \expandafter\xdef\csname\the\macname\endcsname{%
- \noexpand\norecurse{\the\macname}%
- \noexpand\scanmacro{\temp}\egroup}%
- \or % 1
- \expandafter\xdef\csname\the\macname\endcsname{%
- \bgroup\noexpand\macroargctxt
- \noexpand\braceorline
- \expandafter\noexpand\csname\the\macname xxx\endcsname}%
- \expandafter\xdef\csname\the\macname xxx\endcsname##1{%
- \egroup
- \noexpand\norecurse{\the\macname}%
- \noexpand\scanmacro{\temp}\egroup}%
- \else % many
- \expandafter\xdef\csname\the\macname\endcsname{%
- \bgroup\noexpand\macroargctxt
- \expandafter\noexpand\csname\the\macname xx\endcsname}%
- \expandafter\xdef\csname\the\macname xx\endcsname##1{%
- \expandafter\noexpand\csname\the\macname xxx\endcsname ##1,}%
- \expandafter\expandafter
- \expandafter\xdef
- \expandafter\expandafter
- \csname\the\macname xxx\endcsname
- \paramlist{%
- \egroup
- \noexpand\norecurse{\the\macname}%
- \noexpand\scanmacro{\temp}\egroup}%
- \fi
- \fi}
-
-\def\norecurse#1{\bgroup\cslet{#1}{macsave.#1}}
-
-% \braceorline decides whether the next nonwhitespace character is a
-% {. If so it reads up to the closing }, if not, it reads the whole
-% line. Whatever was read is then fed to the next control sequence
-% as an argument (by \parsebrace or \parsearg)
-\def\braceorline#1{\let\next=#1\futurelet\nchar\braceorlinexxx}
-\def\braceorlinexxx{%
- \ifx\nchar\bgroup\else
- \expandafter\parsearg
- \fi \next}
-
-% We want to disable all macros during \shipout so that they are not
-% expanded by \write.
-\def\turnoffmacros{\begingroup \def\do##1{\let\noexpand##1=\relax}%
- \edef\next{\macrolist}\expandafter\endgroup\next}
-
-% For \indexnofonts, we need to get rid of all macros, leaving only the
-% arguments (if present). Of course this is not nearly correct, but it
-% is the best we can do for now. makeinfo does not expand macros in the
-% argument to @deffn, which ends up writing an index entry, and texindex
-% isn't prepared for an index sort entry that starts with \.
-%
-% Since macro invocations are followed by braces, we can just redefine them
-% to take a single TeX argument. The case of a macro invocation that
-% goes to end-of-line is not handled.
-%
-\def\emptyusermacros{\begingroup
- \def\do##1{\let\noexpand##1=\noexpand\asis}%
- \edef\next{\macrolist}\expandafter\endgroup\next}
-
-
-% @alias.
-% We need some trickery to remove the optional spaces around the equal
-% sign. Just make them active and then expand them all to nothing.
-\def\alias{\parseargusing\obeyspaces\aliasxxx}
-\def\aliasxxx #1{\aliasyyy#1\relax}
-\def\aliasyyy #1=#2\relax{%
- {%
- \expandafter\let\obeyedspace=\empty
- \xdef\next{\global\let\makecsname{#1}=\makecsname{#2}}%
- }%
- \next
-}
-
-
-\message{cross references,}
-
-\newwrite\auxfile
-
-\newif\ifhavexrefs % True if xref values are known.
-\newif\ifwarnedxrefs % True if we warned once that they aren't known.
-
-% @inforef is relatively simple.
-\def\inforef #1{\inforefzzz #1,,,,**}
-\def\inforefzzz #1,#2,#3,#4**{\putwordSee{} \putwordInfo{} \putwordfile{} \file{\ignorespaces #3{}},
- node \samp{\ignorespaces#1{}}}
-
-% @node's only job in TeX is to define \lastnode, which is used in
-% cross-references. The @node line might or might not have commas, and
-% might or might not have spaces before the first comma, like:
-% @node foo , bar , ...
-% We don't want such trailing spaces in the node name.
-%
-\parseargdef\node{\checkenv{}\donode #1 ,\finishnodeparse}
-%
-% also remove a trailing comma, in case of something like this:
-% @node Help-Cross, , , Cross-refs
-\def\donode#1 ,#2\finishnodeparse{\dodonode #1,\finishnodeparse}
-\def\dodonode#1,#2\finishnodeparse{\gdef\lastnode{#1}}
-
-\let\nwnode=\node
-\let\lastnode=\empty
-
-% Write a cross-reference definition for the current node. #1 is the
-% type (Ynumbered, Yappendix, Ynothing).
-%
-\def\donoderef#1{%
- \ifx\lastnode\empty\else
- \setref{\lastnode}{#1}%
- \global\let\lastnode=\empty
- \fi
-}
-
-% @anchor{NAME} -- define xref target at arbitrary point.
-%
-\newcount\savesfregister
-%
-\def\savesf{\relax \ifhmode \savesfregister=\spacefactor \fi}
-\def\restoresf{\relax \ifhmode \spacefactor=\savesfregister \fi}
-\def\anchor#1{\savesf \setref{#1}{Ynothing}\restoresf \ignorespaces}
-
-% \setref{NAME}{SNT} defines a cross-reference point NAME (a node or an
-% anchor), which consists of three parts:
-% 1) NAME-title - the current sectioning name taken from \thissection,
-% or the anchor name.
-% 2) NAME-snt - section number and type, passed as the SNT arg, or
-% empty for anchors.
-% 3) NAME-pg - the page number.
-%
-% This is called from \donoderef, \anchor, and \dofloat. In the case of
-% floats, there is an additional part, which is not written here:
-% 4) NAME-lof - the text as it should appear in a @listoffloats.
-%
-\def\setref#1#2{%
- \pdfmkdest{#1}%
- \iflinks
- {%
- \atdummies % preserve commands, but don't expand them
- \turnoffactive
- \otherbackslash
- \edef\writexrdef##1##2{%
- \write\auxfile{@xrdef{#1-% #1 of \setref, expanded by the \edef
- ##1}{##2}}% these are parameters of \writexrdef
- }%
- \toks0 = \expandafter{\thissection}%
- \immediate \writexrdef{title}{\the\toks0 }%
- \immediate \writexrdef{snt}{\csname #2\endcsname}% \Ynumbered etc.
- \writexrdef{pg}{\folio}% will be written later, during \shipout
- }%
- \fi
-}
-
-% @xref, @pxref, and @ref generate cross-references. For \xrefX, #1 is
-% the node name, #2 the name of the Info cross-reference, #3 the printed
-% node name, #4 the name of the Info file, #5 the name of the printed
-% manual. All but the node name can be omitted.
-%
-\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]}
-\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]}
-\def\ref#1{\xrefX[#1,,,,,,,]}
-\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup
- \unsepspaces
- \def\printedmanual{\ignorespaces #5}%
- \def\printedrefname{\ignorespaces #3}%
- \setbox1=\hbox{\printedmanual\unskip}%
- \setbox0=\hbox{\printedrefname\unskip}%
- \ifdim \wd0 = 0pt
- % No printed node name was explicitly given.
- \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax
- % Use the node name inside the square brackets.
- \def\printedrefname{\ignorespaces #1}%
- \else
- % Use the actual chapter/section title appear inside
- % the square brackets. Use the real section title if we have it.
- \ifdim \wd1 > 0pt
- % It is in another manual, so we don't have it.
- \def\printedrefname{\ignorespaces #1}%
- \else
- \ifhavexrefs
- % We know the real title if we have the xref values.
- \def\printedrefname{\refx{#1-title}{}}%
- \else
- % Otherwise just copy the Info node name.
- \def\printedrefname{\ignorespaces #1}%
- \fi%
- \fi
- \fi
- \fi
- %
- % Make link in pdf output.
- \ifpdf
- \leavevmode
- \getfilename{#4}%
- {\turnoffactive \otherbackslash
- \ifnum\filenamelength>0
- \startlink attr{/Border [0 0 0]}%
- goto file{\the\filename.pdf} name{#1}%
- \else
- \startlink attr{/Border [0 0 0]}%
- goto name{\pdfmkpgn{#1}}%
- \fi
- }%
- \linkcolor
- \fi
- %
- % Float references are printed completely differently: "Figure 1.2"
- % instead of "[somenode], p.3". We distinguish them by the
- % LABEL-title being set to a magic string.
- {%
- % Have to otherify everything special to allow the \csname to
- % include an _ in the xref name, etc.
- \indexnofonts
- \turnoffactive
- \otherbackslash
- \expandafter\global\expandafter\let\expandafter\Xthisreftitle
- \csname XR#1-title\endcsname
- }%
- \iffloat\Xthisreftitle
- % If the user specified the print name (third arg) to the ref,
- % print it instead of our usual "Figure 1.2".
- \ifdim\wd0 = 0pt
- \refx{#1-snt}%
- \else
- \printedrefname
- \fi
- %
- % if the user also gave the printed manual name (fifth arg), append
- % "in MANUALNAME".
- \ifdim \wd1 > 0pt
- \space \putwordin{} \cite{\printedmanual}%
- \fi
- \else
- % node/anchor (non-float) references.
- %
- % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
- % insert empty discretionaries after hyphens, which means that it will
- % not find a line break at a hyphen in a node names. Since some manuals
- % are best written with fairly long node names, containing hyphens, this
- % is a loss. Therefore, we give the text of the node name again, so it
- % is as if TeX is seeing it for the first time.
- \ifdim \wd1 > 0pt
- \putwordsection{} ``\printedrefname'' \putwordin{} \cite{\printedmanual}%
- \else
- % _ (for example) has to be the character _ for the purposes of the
- % control sequence corresponding to the node, but it has to expand
- % into the usual \leavevmode...\vrule stuff for purposes of
- % printing. So we \turnoffactive for the \refx-snt, back on for the
- % printing, back off for the \refx-pg.
- {\turnoffactive \otherbackslash
- % Only output a following space if the -snt ref is nonempty; for
- % @unnumbered and @anchor, it won't be.
- \setbox2 = \hbox{\ignorespaces \refx{#1-snt}{}}%
- \ifdim \wd2 > 0pt \refx{#1-snt}\space\fi
- }%
- % output the `[mynode]' via a macro so it can be overridden.
- \xrefprintnodename\printedrefname
- %
- % But we always want a comma and a space:
- ,\space
- %
- % output the `page 3'.
- \turnoffactive \otherbackslash \putwordpage\tie\refx{#1-pg}{}%
- \fi
- \fi
- \endlink
-\endgroup}
-
-% This macro is called from \xrefX for the `[nodename]' part of xref
-% output. It's a separate macro only so it can be changed more easily,
-% since square brackets don't work well in some documents. Particularly
-% one that Bob is working on :).
-%
-\def\xrefprintnodename#1{[#1]}
-
-% Things referred to by \setref.
-%
-\def\Ynothing{}
-\def\Yomitfromtoc{}
-\def\Ynumbered{%
- \ifnum\secno=0
- \putwordChapter@tie \the\chapno
- \else \ifnum\subsecno=0
- \putwordSection@tie \the\chapno.\the\secno
- \else \ifnum\subsubsecno=0
- \putwordSection@tie \the\chapno.\the\secno.\the\subsecno
- \else
- \putwordSection@tie \the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
- \fi\fi\fi
-}
-\def\Yappendix{%
- \ifnum\secno=0
- \putwordAppendix@tie @char\the\appendixno{}%
- \else \ifnum\subsecno=0
- \putwordSection@tie @char\the\appendixno.\the\secno
- \else \ifnum\subsubsecno=0
- \putwordSection@tie @char\the\appendixno.\the\secno.\the\subsecno
- \else
- \putwordSection@tie
- @char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno
- \fi\fi\fi
-}
-
-% Define \refx{NAME}{SUFFIX} to reference a cross-reference string named NAME.
-% If its value is nonempty, SUFFIX is output afterward.
-%
-\def\refx#1#2{%
- {%
- \indexnofonts
- \otherbackslash
- \expandafter\global\expandafter\let\expandafter\thisrefX
- \csname XR#1\endcsname
- }%
- \ifx\thisrefX\relax
- % If not defined, say something at least.
- \angleleft un\-de\-fined\angleright
- \iflinks
- \ifhavexrefs
- \message{\linenumber Undefined cross reference `#1'.}%
- \else
- \ifwarnedxrefs\else
- \global\warnedxrefstrue
- \message{Cross reference values unknown; you must run TeX again.}%
- \fi
- \fi
- \fi
- \else
- % It's defined, so just use it.
- \thisrefX
- \fi
- #2% Output the suffix in any case.
-}
-
-% This is the macro invoked by entries in the aux file. Usually it's
-% just a \def (we prepend XR to the control sequence name to avoid
-% collisions). But if this is a float type, we have more work to do.
-%
-\def\xrdef#1#2{%
- \expandafter\gdef\csname XR#1\endcsname{#2}% remember this xref value.
- %
- % Was that xref control sequence that we just defined for a float?
- \expandafter\iffloat\csname XR#1\endcsname
- % it was a float, and we have the (safe) float type in \iffloattype.
- \expandafter\let\expandafter\floatlist
- \csname floatlist\iffloattype\endcsname
- %
- % Is this the first time we've seen this float type?
- \expandafter\ifx\floatlist\relax
- \toks0 = {\do}% yes, so just \do
- \else
- % had it before, so preserve previous elements in list.
- \toks0 = \expandafter{\floatlist\do}%
- \fi
- %
- % Remember this xref in the control sequence \floatlistFLOATTYPE,
- % for later use in \listoffloats.
- \expandafter\xdef\csname floatlist\iffloattype\endcsname{\the\toks0{#1}}%
- \fi
-}
-
-% Read the last existing aux file, if any. No error if none exists.
-%
-\def\tryauxfile{%
- \openin 1 \jobname.aux
- \ifeof 1 \else
- \readauxfile
- \global\havexrefstrue
- \fi
- \closein 1
-}
-
-\def\readauxfile{\begingroup
- \catcode`\^^@=\other
- \catcode`\^^A=\other
- \catcode`\^^B=\other
- \catcode`\^^C=\other
- \catcode`\^^D=\other
- \catcode`\^^E=\other
- \catcode`\^^F=\other
- \catcode`\^^G=\other
- \catcode`\^^H=\other
- \catcode`\^^K=\other
- \catcode`\^^L=\other
- \catcode`\^^N=\other
- \catcode`\^^P=\other
- \catcode`\^^Q=\other
- \catcode`\^^R=\other
- \catcode`\^^S=\other
- \catcode`\^^T=\other
- \catcode`\^^U=\other
- \catcode`\^^V=\other
- \catcode`\^^W=\other
- \catcode`\^^X=\other
- \catcode`\^^Z=\other
- \catcode`\^^[=\other
- \catcode`\^^\=\other
- \catcode`\^^]=\other
- \catcode`\^^^=\other
- \catcode`\^^_=\other
- % It was suggested to set the catcode of ^ to 7, which would allow ^^e4 etc.
- % in xref tags, i.e., node names. But since ^^e4 notation isn't
- % supported in the main text, it doesn't seem desirable. Furthermore,
- % that is not enough: for node names that actually contain a ^
- % character, we would end up writing a line like this: 'xrdef {'hat
- % b-title}{'hat b} and \xrdef does a \csname...\endcsname on the first
- % argument, and \hat is not an expandable control sequence. It could
- % all be worked out, but why? Either we support ^^ or we don't.
- %
- % The other change necessary for this was to define \auxhat:
- % \def\auxhat{\def^{'hat }}% extra space so ok if followed by letter
- % and then to call \auxhat in \setq.
- %
- \catcode`\^=\other
- %
- % Special characters. Should be turned off anyway, but...
- \catcode`\~=\other
- \catcode`\[=\other
- \catcode`\]=\other
- \catcode`\"=\other
- \catcode`\_=\other
- \catcode`\|=\other
- \catcode`\<=\other
- \catcode`\>=\other
- \catcode`\$=\other
- \catcode`\#=\other
- \catcode`\&=\other
- \catcode`\%=\other
- \catcode`+=\other % avoid \+ for paranoia even though we've turned it off
- %
- % This is to support \ in node names and titles, since the \
- % characters end up in a \csname. It's easier than
- % leaving it active and making its active definition an actual \
- % character. What I don't understand is why it works in the *value*
- % of the xrdef. Seems like it should be a catcode12 \, and that
- % should not typeset properly. But it works, so I'm moving on for
- % now. --karl, 15jan04.
- \catcode`\\=\other
- %
- % Make the characters 128-255 be printing characters.
- {%
- \count 1=128
- \def\loop{%
- \catcode\count 1=\other
- \advance\count 1 by 1
- \ifnum \count 1<256 \loop \fi
- }%
- }%
- %
- % @ is our escape character in .aux files, and we need braces.
- \catcode`\{=1
- \catcode`\}=2
- \catcode`\@=0
- %
- \input \jobname.aux
-\endgroup}
-
-
-\message{insertions,}
-% including footnotes.
-
-\newcount \footnoteno
-
-% The trailing space in the following definition for supereject is
-% vital for proper filling; pages come out unaligned when you do a
-% pagealignmacro call if that space before the closing brace is
-% removed. (Generally, numeric constants should always be followed by a
-% space to prevent strange expansion errors.)
-\def\supereject{\par\penalty -20000\footnoteno =0 }
-
-% @footnotestyle is meaningful for info output only.
-\let\footnotestyle=\comment
-
-{\catcode `\@=11
-%
-% Auto-number footnotes. Otherwise like plain.
-\gdef\footnote{%
- \let\indent=\ptexindent
- \let\noindent=\ptexnoindent
- \global\advance\footnoteno by \@ne
- \edef\thisfootno{$^{\the\footnoteno}$}%
- %
- % In case the footnote comes at the end of a sentence, preserve the
- % extra spacing after we do the footnote number.
- \let\@sf\empty
- \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\ptexslash\fi
- %
- % Remove inadvertent blank space before typesetting the footnote number.
- \unskip
- \thisfootno\@sf
- \dofootnote
-}%
-
-% Don't bother with the trickery in plain.tex to not require the
-% footnote text as a parameter. Our footnotes don't need to be so general.
-%
-% Oh yes, they do; otherwise, @ifset (and anything else that uses
-% \parseargline) fails inside footnotes because the tokens are fixed when
-% the footnote is read. --karl, 16nov96.
-%
-\gdef\dofootnote{%
- \insert\footins\bgroup
- % We want to typeset this text as a normal paragraph, even if the
- % footnote reference occurs in (for example) a display environment.
- % So reset some parameters.
- \hsize=\pagewidth
- \interlinepenalty\interfootnotelinepenalty
- \splittopskip\ht\strutbox % top baseline for broken footnotes
- \splitmaxdepth\dp\strutbox
- \floatingpenalty\@MM
- \leftskip\z@skip
- \rightskip\z@skip
- \spaceskip\z@skip
- \xspaceskip\z@skip
- \parindent\defaultparindent
- %
- \smallfonts \rm
- %
- % Because we use hanging indentation in footnotes, a @noindent appears
- % to exdent this text, so make it be a no-op. makeinfo does not use
- % hanging indentation so @noindent can still be needed within footnote
- % text after an @example or the like (not that this is good style).
- \let\noindent = \relax
- %
- % Hang the footnote text off the number. Use \everypar in case the
- % footnote extends for more than one paragraph.
- \everypar = {\hang}%
- \textindent{\thisfootno}%
- %
- % Don't crash into the line above the footnote text. Since this
- % expands into a box, it must come within the paragraph, lest it
- % provide a place where TeX can split the footnote.
- \footstrut
- \futurelet\next\fo@t
-}
-}%end \catcode `\@=11
-
-% In case a @footnote appears in a vbox, save the footnote text and create
-% the real \insert just after the vbox finished. Otherwise, the insertion
-% would be lost.
-% Similarily, if a @footnote appears inside an alignment, save the footnote
-% text to a box and make the \insert when a row of the table is finished.
-% And the same can be done for other insert classes. --kasal, 16nov03.
-
-% Replace the \insert primitive by a cheating macro.
-% Deeper inside, just make sure that the saved insertions are not spilled
-% out prematurely.
-%
-\def\startsavinginserts{%
- \ifx \insert\ptexinsert
- \let\insert\saveinsert
- \else
- \let\checkinserts\relax
- \fi
-}
-
-% This \insert replacement works for both \insert\footins{foo} and
-% \insert\footins\bgroup foo\egroup, but it doesn't work for \insert27{foo}.
-%
-\def\saveinsert#1{%
- \edef\next{\noexpand\savetobox \makeSAVEname#1}%
- \afterassignment\next
- % swallow the left brace
- \let\temp =
-}
-\def\makeSAVEname#1{\makecsname{SAVE\expandafter\gobble\string#1}}
-\def\savetobox#1{\global\setbox#1 = \vbox\bgroup \unvbox#1}
-
-\def\checksaveins#1{\ifvoid#1\else \placesaveins#1\fi}
-
-\def\placesaveins#1{%
- \ptexinsert \csname\expandafter\gobblesave\string#1\endcsname
- {\box#1}%
-}
-
-% eat @SAVE -- beware, all of them have catcode \other:
-{
- \def\dospecials{\do S\do A\do V\do E} \uncatcodespecials % ;-)
- \gdef\gobblesave @SAVE{}
-}
-
-% initialization:
-\def\newsaveins #1{%
- \edef\next{\noexpand\newsaveinsX \makeSAVEname#1}%
- \next
-}
-\def\newsaveinsX #1{%
- \csname newbox\endcsname #1%
- \expandafter\def\expandafter\checkinserts\expandafter{\checkinserts
- \checksaveins #1}%
-}
-
-% initialize:
-\let\checkinserts\empty
-\newsaveins\footins
-\newsaveins\margin
-
-
-% @image. We use the macros from epsf.tex to support this.
-% If epsf.tex is not installed and @image is used, we complain.
-%
-% Check for and read epsf.tex up front. If we read it only at @image
-% time, we might be inside a group, and then its definitions would get
-% undone and the next image would fail.
-\openin 1 = epsf.tex
-\ifeof 1 \else
- % Do not bother showing banner with epsf.tex v2.7k (available in
- % doc/epsf.tex and on ctan).
- \def\epsfannounce{\toks0 = }%
- \input epsf.tex
-\fi
-\closein 1
-%
-% We will only complain once about lack of epsf.tex.
-\newif\ifwarnednoepsf
-\newhelp\noepsfhelp{epsf.tex must be installed for images to
- work. It is also included in the Texinfo distribution, or you can get
- it from ftp://tug.org/tex/epsf.tex.}
-%
-\def\image#1{%
- \ifx\epsfbox\undefined
- \ifwarnednoepsf \else
- \errhelp = \noepsfhelp
- \errmessage{epsf.tex not found, images will be ignored}%
- \global\warnednoepsftrue
- \fi
- \else
- \imagexxx #1,,,,,\finish
- \fi
-}
-%
-% Arguments to @image:
-% #1 is (mandatory) image filename; we tack on .eps extension.
-% #2 is (optional) width, #3 is (optional) height.
-% #4 is (ignored optional) html alt text.
-% #5 is (ignored optional) extension.
-% #6 is just the usual extra ignored arg for parsing this stuff.
-\newif\ifimagevmode
-\def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup
- \catcode`\^^M = 5 % in case we're inside an example
- \normalturnoffactive % allow _ et al. in names
- % If the image is by itself, center it.
- \ifvmode
- \imagevmodetrue
- \nobreak\bigskip
- % Usually we'll have text after the image which will insert
- % \parskip glue, so insert it here too to equalize the space
- % above and below.
- \nobreak\vskip\parskip
- \nobreak
- \line\bgroup\hss
- \fi
- %
- % Output the image.
- \ifpdf
- \dopdfimage{#1}{#2}{#3}%
- \else
- % \epsfbox itself resets \epsf?size at each figure.
- \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \epsfxsize=#2\relax \fi
- \setbox0 = \hbox{\ignorespaces #3}\ifdim\wd0 > 0pt \epsfysize=#3\relax \fi
- \epsfbox{#1.eps}%
- \fi
- %
- \ifimagevmode \hss \egroup \bigbreak \fi % space after the image
-\endgroup}
-
-
-% @float FLOATTYPE,LABEL,LOC ... @end float for displayed figures, tables,
-% etc. We don't actually implement floating yet, we always include the
-% float "here". But it seemed the best name for the future.
-%
-\envparseargdef\float{\eatcommaspace\eatcommaspace\dofloat#1, , ,\finish}
-
-% There may be a space before second and/or third parameter; delete it.
-\def\eatcommaspace#1, {#1,}
-
-% #1 is the optional FLOATTYPE, the text label for this float, typically
-% "Figure", "Table", "Example", etc. Can't contain commas. If omitted,
-% this float will not be numbered and cannot be referred to.
-%
-% #2 is the optional xref label. Also must be present for the float to
-% be referable.
-%
-% #3 is the optional positioning argument; for now, it is ignored. It
-% will somehow specify the positions allowed to float to (here, top, bottom).
-%
-% We keep a separate counter for each FLOATTYPE, which we reset at each
-% chapter-level command.
-\let\resetallfloatnos=\empty
-%
-\def\dofloat#1,#2,#3,#4\finish{%
- \let\thiscaption=\empty
- \let\thisshortcaption=\empty
- %
- % don't lose footnotes inside @float.
- %
- % BEWARE: when the floats start float, we have to issue warning whenever an
- % insert appears inside a float which could possibly float. --kasal, 26may04
- %
- \startsavinginserts
- %
- % We can't be used inside a paragraph.
- \par
- %
- \vtop\bgroup
- \def\floattype{#1}%
- \def\floatlabel{#2}%
- \def\floatloc{#3}% we do nothing with this yet.
- %
- \ifx\floattype\empty
- \let\safefloattype=\empty
- \else
- {%
- % the floattype might have accents or other special characters,
- % but we need to use it in a control sequence name.
- \indexnofonts
- \turnoffactive
- \xdef\safefloattype{\floattype}%
- }%
- \fi
- %
- % If label is given but no type, we handle that as the empty type.
- \ifx\floatlabel\empty \else
- % We want each FLOATTYPE to be numbered separately (Figure 1,
- % Table 1, Figure 2, ...). (And if no label, no number.)
- %
- \expandafter\getfloatno\csname\safefloattype floatno\endcsname
- \global\advance\floatno by 1
- %
- {%
- % This magic value for \thissection is output by \setref as the
- % XREFLABEL-title value. \xrefX uses it to distinguish float
- % labels (which have a completely different output format) from
- % node and anchor labels. And \xrdef uses it to construct the
- % lists of floats.
- %
- \edef\thissection{\floatmagic=\safefloattype}%
- \setref{\floatlabel}{Yfloat}%
- }%
- \fi
- %
- % start with \parskip glue, I guess.
- \vskip\parskip
- %
- % Don't suppress indentation if a float happens to start a section.
- \restorefirstparagraphindent
-}
-
-% we have these possibilities:
-% @float Foo,lbl & @caption{Cap}: Foo 1.1: Cap
-% @float Foo,lbl & no caption: Foo 1.1
-% @float Foo & @caption{Cap}: Foo: Cap
-% @float Foo & no caption: Foo
-% @float ,lbl & Caption{Cap}: 1.1: Cap
-% @float ,lbl & no caption: 1.1
-% @float & @caption{Cap}: Cap
-% @float & no caption:
-%
-\def\Efloat{%
- \let\floatident = \empty
- %
- % In all cases, if we have a float type, it comes first.
- \ifx\floattype\empty \else \def\floatident{\floattype}\fi
- %
- % If we have an xref label, the number comes next.
- \ifx\floatlabel\empty \else
- \ifx\floattype\empty \else % if also had float type, need tie first.
- \appendtomacro\floatident{\tie}%
- \fi
- % the number.
- \appendtomacro\floatident{\chaplevelprefix\the\floatno}%
- \fi
- %
- % Start the printed caption with what we've constructed in
- % \floatident, but keep it separate; we need \floatident again.
- \let\captionline = \floatident
- %
- \ifx\thiscaption\empty \else
- \ifx\floatident\empty \else
- \appendtomacro\captionline{: }% had ident, so need a colon between
- \fi
- %
- % caption text.
- \appendtomacro\captionline{\scanexp\thiscaption}%
- \fi
- %
- % If we have anything to print, print it, with space before.
- % Eventually this needs to become an \insert.
- \ifx\captionline\empty \else
- \vskip.5\parskip
- \captionline
- %
- % Space below caption.
- \vskip\parskip
- \fi
- %
- % If have an xref label, write the list of floats info. Do this
- % after the caption, to avoid chance of it being a breakpoint.
- \ifx\floatlabel\empty \else
- % Write the text that goes in the lof to the aux file as
- % \floatlabel-lof. Besides \floatident, we include the short
- % caption if specified, else the full caption if specified, else nothing.
- {%
- \atdummies \turnoffactive \otherbackslash
- % since we read the caption text in the macro world, where ^^M
- % is turned into a normal character, we have to scan it back, so
- % we don't write the literal three characters "^^M" into the aux file.
- \scanexp{%
- \xdef\noexpand\gtemp{%
- \ifx\thisshortcaption\empty
- \thiscaption
- \else
- \thisshortcaption
- \fi
- }%
- }%
- \immediate\write\auxfile{@xrdef{\floatlabel-lof}{\floatident
- \ifx\gtemp\empty \else : \gtemp \fi}}%
- }%
- \fi
- \egroup % end of \vtop
- %
- % place the captured inserts
- %
- % BEWARE: when the floats start float, we have to issue warning whenever an
- % insert appears inside a float which could possibly float. --kasal, 26may04
- %
- \checkinserts
-}
-
-% Append the tokens #2 to the definition of macro #1, not expanding either.
-%
-\def\appendtomacro#1#2{%
- \expandafter\def\expandafter#1\expandafter{#1#2}%
-}
-
-% @caption, @shortcaption
-%
-\def\caption{\docaption\thiscaption}
-\def\shortcaption{\docaption\thisshortcaption}
-\def\docaption{\checkenv\float \bgroup\scanargctxt\defcaption}
-\def\defcaption#1#2{\egroup \def#1{#2}}
-
-% The parameter is the control sequence identifying the counter we are
-% going to use. Create it if it doesn't exist and assign it to \floatno.
-\def\getfloatno#1{%
- \ifx#1\relax
- % Haven't seen this figure type before.
- \csname newcount\endcsname #1%
- %
- % Remember to reset this floatno at the next chap.
- \expandafter\gdef\expandafter\resetallfloatnos
- \expandafter{\resetallfloatnos #1=0 }%
- \fi
- \let\floatno#1%
-}
-
-% \setref calls this to get the XREFLABEL-snt value. We want an @xref
-% to the FLOATLABEL to expand to "Figure 3.1". We call \setref when we
-% first read the @float command.
-%
-\def\Yfloat{\floattype@tie \chaplevelprefix\the\floatno}%
-
-% Magic string used for the XREFLABEL-title value, so \xrefX can
-% distinguish floats from other xref types.
-\def\floatmagic{!!float!!}
-
-% #1 is the control sequence we are passed; we expand into a conditional
-% which is true if #1 represents a float ref. That is, the magic
-% \thissection value which we \setref above.
-%
-\def\iffloat#1{\expandafter\doiffloat#1==\finish}
-%
-% #1 is (maybe) the \floatmagic string. If so, #2 will be the
-% (safe) float type for this float. We set \iffloattype to #2.
-%
-\def\doiffloat#1=#2=#3\finish{%
- \def\temp{#1}%
- \def\iffloattype{#2}%
- \ifx\temp\floatmagic
-}
-
-% @listoffloats FLOATTYPE - print a list of floats like a table of contents.
-%
-\parseargdef\listoffloats{%
- \def\floattype{#1}% floattype
- {%
- % the floattype might have accents or other special characters,
- % but we need to use it in a control sequence name.
- \indexnofonts
- \turnoffactive
- \xdef\safefloattype{\floattype}%
- }%
- %
- % \xrdef saves the floats as a \do-list in \floatlistSAFEFLOATTYPE.
- \expandafter\ifx\csname floatlist\safefloattype\endcsname \relax
- \ifhavexrefs
- % if the user said @listoffloats foo but never @float foo.
- \message{\linenumber No `\safefloattype' floats to list.}%
- \fi
- \else
- \begingroup
- \leftskip=\tocindent % indent these entries like a toc
- \let\do=\listoffloatsdo
- \csname floatlist\safefloattype\endcsname
- \endgroup
- \fi
-}
-
-% This is called on each entry in a list of floats. We're passed the
-% xref label, in the form LABEL-title, which is how we save it in the
-% aux file. We strip off the -title and look up \XRLABEL-lof, which
-% has the text we're supposed to typeset here.
-%
-% Figures without xref labels will not be included in the list (since
-% they won't appear in the aux file).
-%
-\def\listoffloatsdo#1{\listoffloatsdoentry#1\finish}
-\def\listoffloatsdoentry#1-title\finish{{%
- % Can't fully expand XR#1-lof because it can contain anything. Just
- % pass the control sequence. On the other hand, XR#1-pg is just the
- % page number, and we want to fully expand that so we can get a link
- % in pdf output.
- \toksA = \expandafter{\csname XR#1-lof\endcsname}%
- %
- % use the same \entry macro we use to generate the TOC and index.
- \edef\writeentry{\noexpand\entry{\the\toksA}{\csname XR#1-pg\endcsname}}%
- \writeentry
-}}
-
-\message{localization,}
-% and i18n.
-
-% @documentlanguage is usually given very early, just after
-% @setfilename. If done too late, it may not override everything
-% properly. Single argument is the language abbreviation.
-% It would be nice if we could set up a hyphenation file here.
-%
-\parseargdef\documentlanguage{%
- \tex % read txi-??.tex file in plain TeX.
- % Read the file if it exists.
- \openin 1 txi-#1.tex
- \ifeof 1
- \errhelp = \nolanghelp
- \errmessage{Cannot read language file txi-#1.tex}%
- \else
- \input txi-#1.tex
- \fi
- \closein 1
- \endgroup
-}
-\newhelp\nolanghelp{The given language definition file cannot be found or
-is empty. Maybe you need to install it? In the current directory
-should work if nowhere else does.}
-
-
-% @documentencoding should change something in TeX eventually, most
-% likely, but for now just recognize it.
-\let\documentencoding = \comment
-
-
-% Page size parameters.
-%
-\newdimen\defaultparindent \defaultparindent = 15pt
-
-\chapheadingskip = 15pt plus 4pt minus 2pt
-\secheadingskip = 12pt plus 3pt minus 2pt
-\subsecheadingskip = 9pt plus 2pt minus 2pt
-
-% Prevent underfull vbox error messages.
-\vbadness = 10000
-
-% Don't be so finicky about underfull hboxes, either.
-\hbadness = 2000
-
-% Following George Bush, just get rid of widows and orphans.
-\widowpenalty=10000
-\clubpenalty=10000
-
-% Use TeX 3.0's \emergencystretch to help line breaking, but if we're
-% using an old version of TeX, don't do anything. We want the amount of
-% stretch added to depend on the line length, hence the dependence on
-% \hsize. We call this whenever the paper size is set.
-%
-\def\setemergencystretch{%
- \ifx\emergencystretch\thisisundefined
- % Allow us to assign to \emergencystretch anyway.
- \def\emergencystretch{\dimen0}%
- \else
- \emergencystretch = .15\hsize
- \fi
-}
-
-% Parameters in order: 1) textheight; 2) textwidth; 3) voffset;
-% 4) hoffset; 5) binding offset; 6) topskip; 7) physical page height; 8)
-% physical page width.
-%
-% We also call \setleading{\textleading}, so the caller should define
-% \textleading. The caller should also set \parskip.
-%
-\def\internalpagesizes#1#2#3#4#5#6#7#8{%
- \voffset = #3\relax
- \topskip = #6\relax
- \splittopskip = \topskip
- %
- \vsize = #1\relax
- \advance\vsize by \topskip
- \outervsize = \vsize
- \advance\outervsize by 2\topandbottommargin
- \pageheight = \vsize
- %
- \hsize = #2\relax
- \outerhsize = \hsize
- \advance\outerhsize by 0.5in
- \pagewidth = \hsize
- %
- \normaloffset = #4\relax
- \bindingoffset = #5\relax
- %
- \ifpdf
- \pdfpageheight #7\relax
- \pdfpagewidth #8\relax
- \fi
- %
- \setleading{\textleading}
- %
- \parindent = \defaultparindent
- \setemergencystretch
-}
-
-% @letterpaper (the default).
-\def\letterpaper{{\globaldefs = 1
- \parskip = 3pt plus 2pt minus 1pt
- \textleading = 13.2pt
- %
- % If page is nothing but text, make it come out even.
- \internalpagesizes{46\baselineskip}{6in}%
- {\voffset}{.25in}%
- {\bindingoffset}{36pt}%
- {11in}{8.5in}%
-}}
-
-% Use @smallbook to reset parameters for 7x9.5 (or so) format.
-\def\smallbook{{\globaldefs = 1
- \parskip = 2pt plus 1pt
- \textleading = 12pt
- %
- \internalpagesizes{7.5in}{5in}%
- {\voffset}{.25in}%
- {\bindingoffset}{16pt}%
- {9.25in}{7in}%
- %
- \lispnarrowing = 0.3in
- \tolerance = 700
- \hfuzz = 1pt
- \contentsrightmargin = 0pt
- \defbodyindent = .5cm
-}}
-
-% Use @afourpaper to print on European A4 paper.
-\def\afourpaper{{\globaldefs = 1
- \parskip = 3pt plus 2pt minus 1pt
- \textleading = 13.2pt
- %
- % Double-side printing via postscript on Laserjet 4050
- % prints double-sided nicely when \bindingoffset=10mm and \hoffset=-6mm.
- % To change the settings for a different printer or situation, adjust
- % \normaloffset until the front-side and back-side texts align. Then
- % do the same for \bindingoffset. You can set these for testing in
- % your texinfo source file like this:
- % @tex
- % \global\normaloffset = -6mm
- % \global\bindingoffset = 10mm
- % @end tex
- \internalpagesizes{51\baselineskip}{160mm}
- {\voffset}{\hoffset}%
- {\bindingoffset}{44pt}%
- {297mm}{210mm}%
- %
- \tolerance = 700
- \hfuzz = 1pt
- \contentsrightmargin = 0pt
- \defbodyindent = 5mm
-}}
-
-% Use @afivepaper to print on European A5 paper.
-% From romildo@urano.iceb.ufop.br, 2 July 2000.
-% He also recommends making @example and @lisp be small.
-\def\afivepaper{{\globaldefs = 1
- \parskip = 2pt plus 1pt minus 0.1pt
- \textleading = 12.5pt
- %
- \internalpagesizes{160mm}{120mm}%
- {\voffset}{\hoffset}%
- {\bindingoffset}{8pt}%
- {210mm}{148mm}%
- %
- \lispnarrowing = 0.2in
- \tolerance = 800
- \hfuzz = 1.2pt
- \contentsrightmargin = 0pt
- \defbodyindent = 2mm
- \tableindent = 12mm
-}}
-
-% A specific text layout, 24x15cm overall, intended for A4 paper.
-\def\afourlatex{{\globaldefs = 1
- \afourpaper
- \internalpagesizes{237mm}{150mm}%
- {\voffset}{4.6mm}%
- {\bindingoffset}{7mm}%
- {297mm}{210mm}%
- %
- % Must explicitly reset to 0 because we call \afourpaper.
- \globaldefs = 0
-}}
-
-% Use @afourwide to print on A4 paper in landscape format.
-\def\afourwide{{\globaldefs = 1
- \afourpaper
- \internalpagesizes{241mm}{165mm}%
- {\voffset}{-2.95mm}%
- {\bindingoffset}{7mm}%
- {297mm}{210mm}%
- \globaldefs = 0
-}}
-
-% @pagesizes TEXTHEIGHT[,TEXTWIDTH]
-% Perhaps we should allow setting the margins, \topskip, \parskip,
-% and/or leading, also. Or perhaps we should compute them somehow.
-%
-\parseargdef\pagesizes{\pagesizesyyy #1,,\finish}
-\def\pagesizesyyy#1,#2,#3\finish{{%
- \setbox0 = \hbox{\ignorespaces #2}\ifdim\wd0 > 0pt \hsize=#2\relax \fi
- \globaldefs = 1
- %
- \parskip = 3pt plus 2pt minus 1pt
- \setleading{\textleading}%
- %
- \dimen0 = #1
- \advance\dimen0 by \voffset
- %
- \dimen2 = \hsize
- \advance\dimen2 by \normaloffset
- %
- \internalpagesizes{#1}{\hsize}%
- {\voffset}{\normaloffset}%
- {\bindingoffset}{44pt}%
- {\dimen0}{\dimen2}%
-}}
-
-% Set default to letter.
-%
-\letterpaper
-
-
-\message{and turning on texinfo input format.}
-
-% Define macros to output various characters with catcode for normal text.
-\catcode`\"=\other
-\catcode`\~=\other
-\catcode`\^=\other
-\catcode`\_=\other
-\catcode`\|=\other
-\catcode`\<=\other
-\catcode`\>=\other
-\catcode`\+=\other
-\catcode`\$=\other
-\def\normaldoublequote{"}
-\def\normaltilde{~}
-\def\normalcaret{^}
-\def\normalunderscore{_}
-\def\normalverticalbar{|}
-\def\normalless{<}
-\def\normalgreater{>}
-\def\normalplus{+}
-\def\normaldollar{$}%$ font-lock fix
-
-% This macro is used to make a character print one way in \tt
-% (where it can probably be output as-is), and another way in other fonts,
-% where something hairier probably needs to be done.
-%
-% #1 is what to print if we are indeed using \tt; #2 is what to print
-% otherwise. Since all the Computer Modern typewriter fonts have zero
-% interword stretch (and shrink), and it is reasonable to expect all
-% typewriter fonts to have this, we can check that font parameter.
-%
-\def\ifusingtt#1#2{\ifdim \fontdimen3\font=0pt #1\else #2\fi}
-
-% Same as above, but check for italic font. Actually this also catches
-% non-italic slanted fonts since it is impossible to distinguish them from
-% italic fonts. But since this is only used by $ and it uses \sl anyway
-% this is not a problem.
-\def\ifusingit#1#2{\ifdim \fontdimen1\font>0pt #1\else #2\fi}
-
-% Turn off all special characters except @
-% (and those which the user can use as if they were ordinary).
-% Most of these we simply print from the \tt font, but for some, we can
-% use math or other variants that look better in normal text.
-
-\catcode`\"=\active
-\def\activedoublequote{{\tt\char34}}
-\let"=\activedoublequote
-\catcode`\~=\active
-\def~{{\tt\char126}}
-\chardef\hat=`\^
-\catcode`\^=\active
-\def^{{\tt \hat}}
-
-\catcode`\_=\active
-\def_{\ifusingtt\normalunderscore\_}
-% Subroutine for the previous macro.
-\def\_{\leavevmode \kern.07em \vbox{\hrule width.3em height.1ex}\kern .07em }
-
-\catcode`\|=\active
-\def|{{\tt\char124}}
-\chardef \less=`\<
-\catcode`\<=\active
-\def<{{\tt \less}}
-\chardef \gtr=`\>
-\catcode`\>=\active
-\def>{{\tt \gtr}}
-\catcode`\+=\active
-\def+{{\tt \char 43}}
-\catcode`\$=\active
-\def${\ifusingit{{\sl\$}}\normaldollar}%$ font-lock fix
-
-% If a .fmt file is being used, characters that might appear in a file
-% name cannot be active until we have parsed the command line.
-% So turn them off again, and have \everyjob (or @setfilename) turn them on.
-% \otherifyactive is called near the end of this file.
-\def\otherifyactive{\catcode`+=\other \catcode`\_=\other}
-
-\catcode`\@=0
-
-% \backslashcurfont outputs one backslash character in current font,
-% as in \char`\\.
-\global\chardef\backslashcurfont=`\\
-\global\let\rawbackslashxx=\backslashcurfont % let existing .??s files work
-
-% \rawbackslash defines an active \ to do \backslashcurfont.
-% \otherbackslash defines an active \ to be a literal `\' character with
-% catcode other.
-{\catcode`\\=\active
- @gdef@rawbackslash{@let\=@backslashcurfont}
- @gdef@otherbackslash{@let\=@realbackslash}
-}
-
-% \realbackslash is an actual character `\' with catcode other.
-{\catcode`\\=\other @gdef@realbackslash{\}}
-
-% \normalbackslash outputs one backslash in fixed width font.
-\def\normalbackslash{{\tt\backslashcurfont}}
-
-\catcode`\\=\active
-
-% Used sometimes to turn off (effectively) the active characters
-% even after parsing them.
-@def@turnoffactive{%
- @let"=@normaldoublequote
- @let\=@realbackslash
- @let~=@normaltilde
- @let^=@normalcaret
- @let_=@normalunderscore
- @let|=@normalverticalbar
- @let<=@normalless
- @let>=@normalgreater
- @let+=@normalplus
- @let$=@normaldollar %$ font-lock fix
- @unsepspaces
-}
-
-% Same as @turnoffactive except outputs \ as {\tt\char`\\} instead of
-% the literal character `\'. (Thus, \ is not expandable when this is in
-% effect.)
-%
-@def@normalturnoffactive{@turnoffactive @let\=@normalbackslash}
-
-% Make _ and + \other characters, temporarily.
-% This is canceled by @fixbackslash.
-@otherifyactive
-
-% If a .fmt file is being used, we don't want the `\input texinfo' to show up.
-% That is what \eatinput is for; after that, the `\' should revert to printing
-% a backslash.
-%
-@gdef@eatinput input texinfo{@fixbackslash}
-@global@let\ = @eatinput
-
-% On the other hand, perhaps the file did not have a `\input texinfo'. Then
-% the first `\{ in the file would cause an error. This macro tries to fix
-% that, assuming it is called before the first `\' could plausibly occur.
-% Also back turn on active characters that might appear in the input
-% file name, in case not using a pre-dumped format.
-%
-@gdef@fixbackslash{%
- @ifx\@eatinput @let\ = @normalbackslash @fi
- @catcode`+=@active
- @catcode`@_=@active
-}
-
-% Say @foo, not \foo, in error messages.
-@escapechar = `@@
-
-% These look ok in all fonts, so just make them not special.
-@catcode`@& = @other
-@catcode`@# = @other
-@catcode`@% = @other
-
-
-@c Local variables:
-@c eval: (add-hook 'write-file-hooks 'time-stamp)
-@c page-delimiter: "^\\\\message"
-@c time-stamp-start: "def\\\\texinfoversion{"
-@c time-stamp-format: "%:y-%02m-%02d.%02H"
-@c time-stamp-end: "}"
-@c End:
-
-@c vim:sw=2:
-
-@ignore
- arch-tag: e1b36e32-c96e-4135-a41a-0b2efa2ea115
-@end ignore
diff --git a/isisd/Makefile.am b/isisd/Makefile.am
index 9c303390..8a682a49 100644
--- a/isisd/Makefile.am
+++ b/isisd/Makefile.am
@@ -2,7 +2,6 @@
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib \
@ISIS_TOPOLOGY_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
INSTALL_SDATA=@INSTALL@ -m 600
LIBS = @LIBS@
@@ -13,8 +12,6 @@ noinst_LIBRARIES = libisis.a
sbin_PROGRAMS = isisd
SUBDIRS = topology
-isis_method = @ISIS_METHOD@
-
libisis_a_SOURCES = \
isis_adjacency.c isis_lsp.c dict.c isis_circuit.c isis_pdu.c \
isis_tlv.c isisd.c isis_misc.c isis_zebra.c isis_dr.c \
@@ -30,13 +27,10 @@ noinst_HEADERS = \
include-netbsd/clnp.h include-netbsd/esis.h include-netbsd/iso.h
isisd_SOURCES = \
- isis_main.c $(libisis_a_SOURCES)
-
-isisd_LDADD = $(isis_method) @ISIS_TOPOLOGY_LIB@ ../lib/libzebra.la @LIBCAP@
-
-isisd_DEPENDENCIES = $(isis_method)
+ isis_main.c $(libisis_a_SOURCES) \
+ isis_bpf.c isis_dlpi.c isis_pfpacket.c
-EXTRA_DIST = isis_bpf.c isis_dlpi.c isis_pfpacket.c
+isisd_LDADD = @ISIS_TOPOLOGY_LIB@ ../lib/libzebra.la @LIBCAP@
examplesdir = $(exampledir)
dist_examples_DATA = isisd.conf.sample
diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c
index aab8d1a3..de34bea9 100644
--- a/isisd/isis_adjacency.c
+++ b/isisd/isis_adjacency.c
@@ -172,7 +172,7 @@ isis_adj_state_change (struct isis_adjacency *adj, enum isis_adj_state state,
circuit->upadjcount[level - 1]++;
if (state == ISIS_ADJ_DOWN)
{
- isis_delete_adj (adj, adj->circuit->u.bc.adjdb[level - 1]);
+ listnode_delete (adj->circuit->u.bc.adjdb[level - 1], adj);
circuit->upadjcount[level - 1]--;
}
diff --git a/isisd/isis_bpf.c b/isisd/isis_bpf.c
index 8c3602db..05f11386 100644
--- a/isisd/isis_bpf.c
+++ b/isisd/isis_bpf.c
@@ -21,6 +21,7 @@
*/
#include <zebra.h>
+#if ISIS_METHOD == ISIS_METHOD_BPF
#include <net/if.h>
#include <netinet/if_ether.h>
#include <sys/time.h>
@@ -339,3 +340,5 @@ isis_send_pdu_p2p (struct isis_circuit *circuit, int level)
{
return ISIS_OK;
}
+
+#endif /* ISIS_METHOD == ISIS_METHOD_BPF */
diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c
index d2923b57..99e2bf6f 100644
--- a/isisd/isis_circuit.c
+++ b/isisd/isis_circuit.c
@@ -142,6 +142,11 @@ isis_circuit_deconfigure (struct isis_circuit *circuit,
struct isis_area *area)
{
+ /* destroy adjacencies */
+ if (circuit->u.bc.adjdb[0])
+ isis_adjdb_iterate (circuit->u.bc.adjdb[0], (void(*) (struct isis_adjacency *, void *)) isis_delete_adj, circuit->u.bc.adjdb[0]);
+ if (circuit->u.bc.adjdb[1])
+ isis_adjdb_iterate (circuit->u.bc.adjdb[1], (void(*) (struct isis_adjacency *, void *)) isis_delete_adj, circuit->u.bc.adjdb[1]);
/* Remove circuit from area */
listnode_delete (area->circuit_list, circuit);
/* Free the index of SRM and SSN flags */
@@ -602,6 +607,13 @@ isis_circuit_down (struct isis_circuit *circuit)
{
THREAD_TIMER_OFF (circuit->u.p2p.t_send_p2p_hello);
}
+
+ if (circuit->t_send_psnp[0]) {
+ THREAD_TIMER_OFF (circuit->t_send_psnp[0]);
+ }
+ if (circuit->t_send_psnp[1]) {
+ THREAD_TIMER_OFF (circuit->t_send_psnp[1]);
+ }
/* close the socket */
close (circuit->fd);
@@ -818,6 +830,21 @@ isis_interface_config_write (struct vty *vty)
}
}
}
+ if (c->passwd.type==ISIS_PASSWD_TYPE_HMAC_MD5)
+ {
+ vty_out (vty, " isis password md5 %s%s", c->passwd.passwd,
+ VTY_NEWLINE);
+ write++;
+ }
+ else
+ {
+ if (c->passwd.type==ISIS_PASSWD_TYPE_CLEARTXT)
+ {
+ vty_out (vty, " isis password clear %s%s", c->passwd.passwd,
+ VTY_NEWLINE);
+ write++;
+ }
+ }
}
}
@@ -1010,11 +1037,44 @@ DEFUN (no_isis_circuit_type,
return CMD_SUCCESS;
}
-DEFUN (isis_passwd,
- isis_passwd_cmd,
- "isis password WORD",
+DEFUN (isis_passwd_md5,
+ isis_passwd_md5_cmd,
+ "isis password md5 WORD",
+ "IS-IS commands\n"
+ "Configure the authentication password for interface\n"
+ "Authentication Type\n"
+ "Password\n")
+{
+ struct isis_circuit *circuit;
+ struct interface *ifp;
+ int len;
+
+ ifp = vty->index;
+ circuit = ifp->info;
+ if (circuit == NULL)
+ {
+ return CMD_WARNING;
+ }
+
+ len = strlen (argv[0]);
+ if (len > 254)
+ {
+ vty_out (vty, "Too long circuit password (>254)%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ circuit->passwd.len = len;
+ circuit->passwd.type = ISIS_PASSWD_TYPE_HMAC_MD5;
+ strncpy ((char *)circuit->passwd.passwd, argv[0], 255);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (isis_passwd_clear,
+ isis_passwd_clear_cmd,
+ "isis password clear WORD",
"IS-IS commands\n"
"Configure the authentication password for interface\n"
+ "Authentication Type\n"
"Password\n")
{
struct isis_circuit *circuit;
@@ -1063,7 +1123,6 @@ DEFUN (no_isis_passwd,
return CMD_SUCCESS;
}
-
DEFUN (isis_priority,
isis_priority_cmd,
"isis priority <0-127>",
@@ -2074,7 +2133,8 @@ isis_circuit_init ()
install_element (INTERFACE_NODE, &isis_circuit_type_cmd);
install_element (INTERFACE_NODE, &no_isis_circuit_type_cmd);
- install_element (INTERFACE_NODE, &isis_passwd_cmd);
+ install_element (INTERFACE_NODE, &isis_passwd_clear_cmd);
+ install_element (INTERFACE_NODE, &isis_passwd_md5_cmd);
install_element (INTERFACE_NODE, &no_isis_passwd_cmd);
install_element (INTERFACE_NODE, &isis_priority_cmd);
diff --git a/isisd/isis_circuit.h b/isisd/isis_circuit.h
index a7e719f6..f32d1dda 100644
--- a/isisd/isis_circuit.h
+++ b/isisd/isis_circuit.h
@@ -65,6 +65,7 @@ struct isis_p2p_info
struct isis_circuit
{
int state;
+ int connected;
u_char circuit_id; /* l1/l2 p2p/bcast CircuitID */
struct isis_area *area; /* back pointer to the area */
struct interface *interface; /* interface info from z */
diff --git a/isisd/isis_common.h b/isisd/isis_common.h
index 26338556..334d3394 100644
--- a/isisd/isis_common.h
+++ b/isisd/isis_common.h
@@ -35,6 +35,7 @@ struct isis_passwd
u_char len;
#define ISIS_PASSWD_TYPE_UNUSED 0
#define ISIS_PASSWD_TYPE_CLEARTXT 1
+#define ISIS_PASSWD_TYPE_HMAC_MD5 54
#define ISIS_PASSWD_TYPE_PRIVATE 255
u_char type;
/* Authenticate SNPs? */
diff --git a/isisd/isis_csm.c b/isisd/isis_csm.c
index 80d0c906..6cdde46a 100644
--- a/isisd/isis_csm.c
+++ b/isisd/isis_csm.c
@@ -112,6 +112,7 @@ isis_csm_state_change (int event, struct isis_circuit *circuit, void *arg)
isis_circuit_configure (circuit, (struct isis_area *) arg);
isis_circuit_up (circuit);
circuit->state = C_STATE_UP;
+ circuit->connected = 1;
isis_event_circuit_state_change (circuit, 1);
listnode_delete (isis->init_circ_list, circuit);
break;
@@ -136,9 +137,12 @@ isis_csm_state_change (int event, struct isis_circuit *circuit, void *arg)
zlog_warn ("circuit already enabled");
break;
case IF_UP_FROM_Z:
- isis_circuit_if_add (circuit, (struct interface *) arg);
- isis_circuit_up (circuit);
+ if (!circuit->connected) {
+ isis_circuit_if_add (circuit, (struct interface *) arg);
+ isis_circuit_up (circuit);
+ }
circuit->state = C_STATE_UP;
+ circuit->connected = 1;
isis_event_circuit_state_change (circuit, 1);
break;
case ISIS_DISABLE:
@@ -167,7 +171,6 @@ isis_csm_state_change (int event, struct isis_circuit *circuit, void *arg)
isis_event_circuit_state_change (circuit, 0);
break;
case IF_DOWN_FROM_Z:
- isis_circuit_if_del (circuit);
circuit->state = C_STATE_CONF;
isis_event_circuit_state_change (circuit, 0);
break;
diff --git a/isisd/isis_dlpi.c b/isisd/isis_dlpi.c
index 3cbe0b4f..fe872a95 100644
--- a/isisd/isis_dlpi.c
+++ b/isisd/isis_dlpi.c
@@ -21,6 +21,7 @@
*/
#include <zebra.h>
+#if ISIS_METHOD == ISIS_METHOD_DLPI
#include <net/if.h>
#include <netinet/if_ether.h>
#include <sys/types.h>
@@ -622,3 +623,5 @@ isis_send_pdu_bcast (struct isis_circuit *circuit, int level)
sock_buff, stream_get_endp (circuit->snd_stream) + LLC_LEN, 0);
return ISIS_OK;
}
+
+#endif /* ISIS_METHOD == ISIS_METHOD_DLPI */
diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c
index 50289db3..fd40bb37 100644
--- a/isisd/isis_lsp.c
+++ b/isisd/isis_lsp.c
@@ -353,10 +353,25 @@ isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
pdulen - ISIS_FIXED_HDR_LEN
- ISIS_LSP_HDR_LEN, &expected, &found, &tlvs);
+
if (retval || !(found & TLVFLAG_AUTH_INFO))
return 1; /* Auth fail (parsing failed or no auth-tlv) */
- return authentication_check (passwd, &tlvs.auth_info);
+ switch (tlvs.auth_info.type)
+ {
+ case ISIS_PASSWD_TYPE_HMAC_MD5:
+ zlog_debug("Got LSP with ISIS_PASSWD_TYPE_HMAC_MD5");
+ break;
+ case ISIS_PASSWD_TYPE_CLEARTXT:
+ zlog_debug("Got LSP with ISIS_PASSWD_TYPE_CLEARTXT");
+ break;
+ default:
+ zlog_debug("Unknown authentication type in LSP");
+ break;
+ }
+
+ return 0;
+ /* return authentication_check (passwd, &tlvs.auth_info);*/
}
static void
@@ -1640,7 +1655,7 @@ lsp_regenerate_schedule (struct isis_area *area)
if (diff < MIN_LSP_GEN_INTERVAL)
{
area->lsp_regenerate_pending[0] = 1;
- thread_add_timer (master, lsp_l1_regenerate, area,
+ area->t_lsp_l1_regenerate=thread_add_timer (master, lsp_l1_regenerate, area,
MIN_LSP_GEN_INTERVAL - diff);
goto L2;
}
@@ -1663,7 +1678,7 @@ L2:
if (diff < MIN_LSP_GEN_INTERVAL)
{
area->lsp_regenerate_pending[1] = 1;
- thread_add_timer (master, lsp_l2_regenerate, area,
+ area->t_lsp_l2_regenerate=thread_add_timer (master, lsp_l2_regenerate, area,
MIN_LSP_GEN_INTERVAL - diff);
return ISIS_OK;
}
@@ -2037,6 +2052,8 @@ lsp_tick (struct thread *thread)
{
for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit))
{
+ if (circuit->state != C_STATE_UP)
+ continue;
for (ALL_LIST_ELEMENTS_RO (lsp_list, lspnode, lsp))
{
if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit))
diff --git a/isisd/isis_lsp.h b/isisd/isis_lsp.h
index adbde78e..8d648d05 100644
--- a/isisd/isis_lsp.h
+++ b/isisd/isis_lsp.h
@@ -58,7 +58,6 @@ struct isis_lsp
#endif
/* used for 60 second counting when rem_lifetime is zero */
int age_out;
- struct isis_adjacency *adj;
/* FIXME: For now only topology LSP's use this. Is it helpful for others? */
struct isis_area *area;
struct tlvs tlv_data; /* Simplifies TLV access */
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index c5e824c1..d457d25e 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -34,6 +34,7 @@
#include "privs.h"
#include "sigevent.h"
#include "filter.h"
+#include "paths.h"
#include "isisd/dict.h"
#include "include-netbsd/iso.h"
@@ -45,7 +46,10 @@
#include "isisd/isis_dynhn.h"
/* Default configuration file name */
-#define ISISD_DEFAULT_CONFIG "isisd.conf"
+#define ISISD_CONFIG_NAME "isisd.conf"
+#define ISISD_PID_NAME "isisd.pid"
+#define ISISD_VTY_NAME "isisd.vty"
+
/* Default vty port */
#define ISISD_VTY_PORT 2608
@@ -73,6 +77,7 @@ struct zebra_privs_t isisd_privs = {
/* isisd options */
struct option longopts[] = {
{"daemon", no_argument, NULL, 'd'},
+ {"namespace", required_argument, NULL, 'N'},
{"config_file", required_argument, NULL, 'f'},
{"pid_file", required_argument, NULL, 'i'},
{"vty_addr", required_argument, NULL, 'A'},
@@ -86,7 +91,7 @@ struct option longopts[] = {
};
/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR ISISD_DEFAULT_CONFIG;
+char config_default[MAXPATHLEN];
char *config_file = NULL;
/* isisd program name. */
@@ -97,8 +102,11 @@ int daemon_mode = 0;
/* Master of threads. */
struct thread_master *master;
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
+
/* Process ID saved for use by init system */
-const char *pid_file = PATH_ISISD_PID;
+const char *pid_file = pid_file_default;
/* for reload */
char _cwd[MAXPATHLEN];
@@ -128,6 +136,7 @@ usage (int status)
printf ("Usage : %s [OPTION...]\n\n\
Daemon which manages IS-IS routing\n\n\
-d, --daemon Runs in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
-f, --config_file Set configuration file name\n\
-i, --pid_file Set process identifier file name\n\
-A, --vty_addr Set vty's bind address\n\
@@ -246,7 +255,7 @@ main (int argc, char **argv, char **envp)
/* Command line argument treatment. */
while (1)
{
- opt = getopt_long (argc, argv, "df:i:hA:p:P:u:g:vC", longopts, 0);
+ opt = getopt_long (argc, argv, "dN:f:i:hA:p:P:u:g:vC", longopts, 0);
if (opt == EOF)
break;
@@ -258,6 +267,9 @@ main (int argc, char **argv, char **envp)
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'f':
config_file = optarg;
break;
@@ -303,6 +315,9 @@ main (int argc, char **argv, char **envp)
}
}
+ strcpy (config_default, path_config (ISISD_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (ISISD_PID_NAME));
+
/* thread master */
master = thread_master_create ();
@@ -343,7 +358,7 @@ main (int argc, char **argv, char **envp)
pid_output (pid_file);
/* Make isis vty socket. */
- vty_serv_sock (vty_addr, vty_port, ISIS_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (ISISD_VTY_NAME));
/* Print banner. */
zlog_notice ("Quagga-ISISd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c
index a2ab0649..d67df31b 100644
--- a/isisd/isis_pdu.c
+++ b/isisd/isis_pdu.c
@@ -29,10 +29,11 @@
#include "log.h"
#include "stream.h"
#include "vty.h"
-#include "hash.c"
+#include "hash.h"
#include "prefix.h"
#include "if.h"
#include "checksum.h"
+#include "md5.h"
#include "isisd/dict.h"
#include "isisd/include-netbsd/iso.h"
@@ -168,26 +169,38 @@ accept_level (int level, int circuit_t)
return retval;
}
+
+/*
+ * Verify authentication information
+ * Support cleartext and HMAC MD5 authentication
+ */
int
-authentication_check (struct isis_passwd *one, struct isis_passwd *theother)
+authentication_check (struct isis_passwd *remote, struct isis_passwd *local, struct isis_circuit* c)
{
- if (one->type != theother->type)
+ unsigned char digest[ISIS_AUTH_MD5_SIZE];
+
+ if (c->passwd.type)
{
- zlog_warn ("Unsupported authentication type %d", theother->type);
- return 1; /* Auth fail (different authentication types) */
- }
- switch (one->type)
+ switch (c->passwd.type)
{
+ case ISIS_PASSWD_TYPE_HMAC_MD5:
+ /* HMAC MD5 (RFC 3567) */
+ /* MD5 computation according to RFC 2104 */
+ hmac_md5(c->rcv_stream->data, stream_get_endp(c->rcv_stream), (unsigned char *) &(local->passwd), c->passwd.len, (unsigned char *) &digest);
+ return memcmp (digest, remote->passwd, ISIS_AUTH_MD5_SIZE);
+ break;
case ISIS_PASSWD_TYPE_CLEARTXT:
- if (one->len != theother->len)
+ /* Cleartext (ISO 10589) */
+ if (local->len != remote->len)
return 1; /* Auth fail () - passwd len mismatch */
- return memcmp (one->passwd, theother->passwd, one->len);
+ return memcmp (local->passwd, remote->passwd, local->len);
break;
default:
zlog_warn ("Unsupported authentication type");
break;
}
- return 0; /* Auth pass */
+ }
+ return 0; /* Authentication pass when no authentication is configured */
}
/*
@@ -372,7 +385,7 @@ process_p2p_hello (struct isis_circuit *circuit)
if (circuit->passwd.type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
- authentication_check (&circuit->passwd, &tlvs.auth_info))
+ authentication_check (&tlvs.auth_info, &circuit->passwd, circuit))
{
isis_event_auth_failure (circuit->area->area_tag,
"P2P hello authentication failure",
@@ -744,10 +757,11 @@ process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa)
goto out;
}
+ /* Verify authentication, either cleartext of HMAC MD5 */
if (circuit->passwd.type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
- authentication_check (&circuit->passwd, &tlvs.auth_info))
+ authentication_check (&tlvs.auth_info, &circuit->passwd, circuit))
{
isis_event_auth_failure (circuit->area->area_tag,
"LAN hello authentication failure",
@@ -1187,6 +1201,7 @@ dontcheckadj:
/* 7.3.15.1 e) 1) LSP newer than the one in db or no LSP in db */
if ((!lsp || comp == LSP_NEWER))
{
+ int regenerate = (lsp == NULL);
/* i */
if (lsp)
{
@@ -1221,7 +1236,6 @@ dontcheckadj:
ntohs (hdr->pdu_len), lsp0,
circuit->area);
lsp->level = level;
- lsp->adj = adj;
lsp_insert (lsp, circuit->area->lspdb[level - 1]);
/* ii */
ISIS_FLAGS_SET_ALL (lsp->SRMflags);
@@ -1232,6 +1246,9 @@ dontcheckadj:
if (circuit->circ_type != CIRCUIT_T_BROADCAST)
ISIS_SET_FLAG (lsp->SSNflags, circuit);
/* FIXME: v) */
+ if (regenerate && circuit->u.bc.is_dr[level - 1]) {
+ lsp_l1_pseudo_generate (circuit);
+ }
}
/* 7.3.15.1 e) 2) LSP equal to the one in db */
else if (comp == LSP_EQUAL)
@@ -1250,8 +1267,7 @@ dontcheckadj:
ISIS_CLEAR_FLAG (lsp->SSNflags, circuit);
}
}
- if (lsp)
- lsp->adj = adj;
+
return retval;
}
@@ -1414,7 +1430,7 @@ process_snp (int snp_type, int level, struct isis_circuit *circuit,
if (passwd->type)
{
if (!(found & TLVFLAG_AUTH_INFO) ||
- authentication_check (passwd, &tlvs.auth_info))
+ authentication_check (&tlvs.auth_info, passwd, circuit))
{
isis_event_auth_failure (circuit->area->area_tag,
"SNP authentication" " failure",
@@ -1781,6 +1797,9 @@ isis_receive (struct thread *thread)
circuit = THREAD_ARG (thread);
assert (circuit);
+ if (!circuit->area)
+ return ISIS_OK;
+
if (circuit->rcv_stream == NULL)
circuit->rcv_stream = stream_new (ISO_MTU (circuit));
else
@@ -1908,11 +1927,15 @@ send_hello (struct isis_circuit *circuit, int level)
struct isis_fixed_hdr fixed_hdr;
struct isis_lan_hello_hdr hello_hdr;
struct isis_p2p_hello_hdr p2p_hello_hdr;
+ char hmac_md5_hash[ISIS_AUTH_MD5_SIZE];
u_int32_t interval;
- unsigned long len_pointer, length;
+ unsigned long len_pointer, length, auth_tlv;
int retval;
+ if (circuit->state != C_STATE_UP || circuit->interface == NULL)
+ return ISIS_WARNING;
+
if (circuit->interface->mtu == 0)
{
zlog_warn ("circuit has zero MTU");
@@ -1940,6 +1963,9 @@ send_hello (struct isis_circuit *circuit, int level)
memset (&hello_hdr, 0, sizeof (struct isis_lan_hello_hdr));
interval = circuit->hello_multiplier[level - 1] *
circuit->hello_interval[level - 1];
+ /* If we are the DIS then hello interval is divided by three, as is the hold-timer */
+ if (circuit->u.bc.is_dr[level - 1])
+ interval=interval/3;
if (interval > USHRT_MAX)
interval = USHRT_MAX;
hello_hdr.circuit_t = circuit->circuit_is_type;
@@ -1976,34 +2002,36 @@ send_hello (struct isis_circuit *circuit, int level)
/*
* Then the variable length part
*/
+
/* add circuit password */
- if (circuit->passwd.type)
- if (tlv_add_authinfo (circuit->passwd.type, circuit->passwd.len,
+ /* Cleartext */
+ if (circuit->passwd.type == ISIS_PASSWD_TYPE_CLEARTXT)
+ if (tlv_add_authinfo (ISIS_PASSWD_TYPE_CLEARTXT, circuit->passwd.len,
circuit->passwd.passwd, circuit->snd_stream))
return ISIS_WARNING;
- /* Area Addresses TLV */
- assert (circuit->area);
- if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
- if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
- return ISIS_WARNING;
- /* LAN Neighbors TLV */
- if (circuit->circ_type == CIRCUIT_T_BROADCAST)
+ /* or HMAC MD5 */
+ if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
{
- if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
- if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
- circuit->snd_stream))
- return ISIS_WARNING;
- if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
- if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
- circuit->snd_stream))
- return ISIS_WARNING;
+ /* Remember where TLV is written so we can later overwrite the MD5 hash */
+ auth_tlv = stream_get_endp (circuit->snd_stream);
+ memset(&hmac_md5_hash, 0, ISIS_AUTH_MD5_SIZE);
+ if (tlv_add_authinfo (ISIS_PASSWD_TYPE_HMAC_MD5, ISIS_AUTH_MD5_SIZE,
+ hmac_md5_hash, circuit->snd_stream))
+ return ISIS_WARNING;
}
/* Protocols Supported TLV */
if (circuit->nlpids.count > 0)
if (tlv_add_nlpid (&circuit->nlpids, circuit->snd_stream))
return ISIS_WARNING;
+
+ /* Area Addresses TLV */
+ assert (circuit->area);
+ if (circuit->area->area_addrs && circuit->area->area_addrs->count > 0)
+ if (tlv_add_area_addrs (circuit->area->area_addrs, circuit->snd_stream))
+ return ISIS_WARNING;
+
/* IP interface Address TLV */
if (circuit->ip_router && circuit->ip_addrs && circuit->ip_addrs->count > 0)
if (tlv_add_ip_addrs (circuit->ip_addrs, circuit->snd_stream))
@@ -2017,6 +2045,22 @@ send_hello (struct isis_circuit *circuit, int level)
return ISIS_WARNING;
#endif /* HAVE_IPV6 */
+ /* Restart signaling, vendor C sends it too */
+ retval = add_tlv (211, 3, 0, circuit->snd_stream);
+
+ /* LAN Neighbors TLV */
+ if (circuit->circ_type == CIRCUIT_T_BROADCAST)
+ {
+ if (level == 1 && circuit->u.bc.lan_neighs[0]->count > 0)
+ if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[0],
+ circuit->snd_stream))
+ return ISIS_WARNING;
+ if (level == 2 && circuit->u.bc.lan_neighs[1]->count > 0)
+ if (tlv_add_lan_neighs (circuit->u.bc.lan_neighs[1],
+ circuit->snd_stream))
+ return ISIS_WARNING;
+ }
+
if (circuit->u.bc.pad_hellos)
if (tlv_add_padding (circuit->snd_stream))
return ISIS_WARNING;
@@ -2025,6 +2069,14 @@ send_hello (struct isis_circuit *circuit, int level)
/* Update PDU length */
stream_putw_at (circuit->snd_stream, len_pointer, (u_int16_t) length);
+ /* For HMAC MD5 we need to compute the md5 hash and store it */
+ if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5)
+ {
+ hmac_md5(circuit->snd_stream->data, stream_get_endp(circuit->snd_stream), (unsigned char *) &circuit->passwd.passwd, circuit->passwd.len, (unsigned char *) &hmac_md5_hash);
+ /* Copy the hash into the stream */
+ memcpy(circuit->snd_stream->data+auth_tlv+3,hmac_md5_hash,ISIS_AUTH_MD5_SIZE);
+ }
+
retval = circuit->tx (circuit, level);
if (retval)
zlog_warn ("sending of LAN Level %d Hello failed", level);
@@ -2062,9 +2114,21 @@ send_lan_l1_hello (struct thread *thread)
{
struct isis_circuit *circuit;
int retval;
+ unsigned long next_hello;
circuit = THREAD_ARG (thread);
assert (circuit);
+
+ if (!circuit->area) {
+ return ISIS_OK;
+ }
+
+ /* Pseudonode sends hellos three times more than the other nodes */
+ if (circuit->u.bc.is_dr[0])
+ next_hello=circuit->hello_interval[0]/3+1;
+ else
+ next_hello=circuit->hello_interval[0];
+
circuit->u.bc.t_send_lan_hello[0] = NULL;
if (circuit->u.bc.run_dr_elect[0])
@@ -2075,7 +2139,7 @@ send_lan_l1_hello (struct thread *thread)
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[0],
send_lan_l1_hello, circuit,
- isis_jitter (circuit->hello_interval[0], IIH_JITTER));
+ isis_jitter (next_hello, IIH_JITTER));
return retval;
}
@@ -2085,9 +2149,21 @@ send_lan_l2_hello (struct thread *thread)
{
struct isis_circuit *circuit;
int retval;
+ unsigned long next_hello;
circuit = THREAD_ARG (thread);
assert (circuit);
+
+ if (!circuit->area) {
+ return ISIS_OK;
+ }
+
+ /* Pseudonode sends hellos three times more than the other nodes */
+ if (circuit->u.bc.is_dr[1])
+ next_hello=circuit->hello_interval[1]/3+1;
+ else
+ next_hello=circuit->hello_interval[1];
+
circuit->u.bc.t_send_lan_hello[1] = NULL;
if (circuit->u.bc.run_dr_elect[1])
@@ -2098,7 +2174,7 @@ send_lan_l2_hello (struct thread *thread)
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->u.bc.t_send_lan_hello[1],
send_lan_l2_hello, circuit,
- isis_jitter (circuit->hello_interval[1], IIH_JITTER));
+ isis_jitter (next_hello, IIH_JITTER));
return retval;
}
@@ -2192,6 +2268,9 @@ send_csnp (struct isis_circuit *circuit, int level)
struct listnode *node;
struct isis_lsp *lsp;
+ if (circuit->state != C_STATE_UP || circuit->interface == NULL)
+ return ISIS_WARNING;
+
memset (start, 0x00, ISIS_SYS_ID_LEN + 2);
memset (stop, 0xff, ISIS_SYS_ID_LEN + 2);
@@ -2246,9 +2325,7 @@ send_l1_csnp (struct thread *thread)
circuit->t_send_csnp[0] = NULL;
if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[0])
- {
send_csnp (circuit, 1);
- }
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->t_send_csnp[0], send_l1_csnp, circuit,
isis_jitter (circuit->csnp_interval[0], CSNP_JITTER));
@@ -2268,9 +2345,7 @@ send_l2_csnp (struct thread *thread)
circuit->t_send_csnp[1] = NULL;
if (circuit->circ_type == CIRCUIT_T_BROADCAST && circuit->u.bc.is_dr[1])
- {
send_csnp (circuit, 2);
- }
/* set next timer thread */
THREAD_TIMER_ON (master, circuit->t_send_csnp[1], send_l2_csnp, circuit,
isis_jitter (circuit->csnp_interval[1], CSNP_JITTER));
@@ -2357,6 +2432,9 @@ send_psnp (int level, struct isis_circuit *circuit)
struct list *list = NULL;
struct listnode *node;
+ if (circuit->state != C_STATE_UP || circuit->interface == NULL)
+ return ISIS_WARNING;
+
if ((circuit->circ_type == CIRCUIT_T_BROADCAST &&
!circuit->u.bc.is_dr[level - 1]) ||
circuit->circ_type != CIRCUIT_T_BROADCAST)
@@ -2463,85 +2541,85 @@ send_lsp (struct thread *thread)
circuit = THREAD_ARG (thread);
assert (circuit);
- if (circuit->state == C_STATE_UP)
+ if (circuit->state != C_STATE_UP || circuit->interface == NULL)
+ return ISIS_WARNING;
+
+ lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
+
+ /*
+ * Do not send if levels do not match
+ */
+ if (!(lsp->level & circuit->circuit_is_type))
+ goto dontsend;
+
+ /*
+ * Do not send if we do not have adjacencies in state up on the circuit
+ */
+ if (circuit->upadjcount[lsp->level - 1] == 0)
+ goto dontsend;
+ /* only send if it needs sending */
+ if ((time (NULL) - lsp->last_sent) >=
+ circuit->area->lsp_gen_interval[lsp->level - 1])
{
- lsp = listgetdata ((node = listhead (circuit->lsp_queue)));
- /*
- * Do not send if levels do not match
- */
- if (!(lsp->level & circuit->circuit_is_type))
- goto dontsend;
+ if (isis->debugs & DEBUG_UPDATE_PACKETS)
+ {
+ zlog_debug
+ ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
+ " lifetime %us on %s", circuit->area->area_tag, lsp->level,
+ rawlspid_print (lsp->lsp_header->lsp_id),
+ ntohl (lsp->lsp_header->seq_num),
+ ntohs (lsp->lsp_header->checksum),
+ ntohs (lsp->lsp_header->rem_lifetime),
+ circuit->interface->name);
+ }
+ /* copy our lsp to the send buffer */
+ stream_copy (circuit->snd_stream, lsp->pdu);
+
+ retval = circuit->tx (circuit, lsp->level);
/*
- * Do not send if we do not have adjacencies in state up on the circuit
+ * If the sending succeeded, we can del the lsp from circuits
+ * lsp_queue
*/
- if (circuit->upadjcount[lsp->level - 1] == 0)
- goto dontsend;
- /* only send if it needs sending */
- if ((time (NULL) - lsp->last_sent) >=
- circuit->area->lsp_gen_interval[lsp->level - 1])
+ if (retval == ISIS_OK)
{
-
- if (isis->debugs & DEBUG_UPDATE_PACKETS)
- {
- zlog_debug
- ("ISIS-Upd (%s): Sent L%d LSP %s, seq 0x%08x, cksum 0x%04x,"
- " lifetime %us on %s", circuit->area->area_tag, lsp->level,
- rawlspid_print (lsp->lsp_header->lsp_id),
- ntohl (lsp->lsp_header->seq_num),
- ntohs (lsp->lsp_header->checksum),
- ntohs (lsp->lsp_header->rem_lifetime),
- circuit->interface->name);
- }
- /* copy our lsp to the send buffer */
- stream_copy (circuit->snd_stream, lsp->pdu);
-
- retval = circuit->tx (circuit, lsp->level);
+ list_delete_node (circuit->lsp_queue, node);
/*
- * If the sending succeeded, we can del the lsp from circuits
- * lsp_queue
+ * On broadcast circuits also the SRMflag can be cleared
*/
- if (retval == ISIS_OK)
- {
- list_delete_node (circuit->lsp_queue, node);
+ if (circuit->circ_type == CIRCUIT_T_BROADCAST)
+ ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
+ if (flags_any_set (lsp->SRMflags) == 0)
+ {
/*
- * On broadcast circuits also the SRMflag can be cleared
+ * need to remember when we were last sent
*/
- if (circuit->circ_type == CIRCUIT_T_BROADCAST)
- ISIS_CLEAR_FLAG (lsp->SRMflags, circuit);
-
- if (flags_any_set (lsp->SRMflags) == 0)
- {
- /*
- * need to remember when we were last sent
- */
- lsp->last_sent = time (NULL);
- }
- }
- else
- {
- zlog_debug ("sending of level %d link state failed", lsp->level);
+ lsp->last_sent = time (NULL);
}
}
else
{
- /* my belief is that if it wasn't his time, the lsp can be removed
- * from the queue
- */
- dontsend:
- list_delete_node (circuit->lsp_queue, node);
+ zlog_debug ("sending of level %d link state failed", lsp->level);
}
-#if 0
- /*
- * If there are still LSPs send next one after lsp-interval (33 msecs)
+ }
+ else
+ {
+ /* my belief is that if it wasn't his time, the lsp can be removed
+ * from the queue
*/
- if (listcount (circuit->lsp_queue) > 0)
- thread_add_timer (master, send_lsp, circuit, 1);
-#endif
+ dontsend:
+ list_delete_node (circuit->lsp_queue, node);
}
+#if 0
+ /*
+ * If there are still LSPs send next one after lsp-interval (33 msecs)
+ */
+ if (listcount (circuit->lsp_queue) > 0)
+ thread_add_timer (master, send_lsp, circuit, 1);
+#endif
return retval;
}
diff --git a/isisd/isis_pdu.h b/isisd/isis_pdu.h
index 95c1ee4f..c4c38e22 100644
--- a/isisd/isis_pdu.h
+++ b/isisd/isis_pdu.h
@@ -258,8 +258,7 @@ int ack_lsp (struct isis_link_state_hdr *hdr,
void fill_fixed_hdr (struct isis_fixed_hdr *hdr, u_char pdu_type);
int send_hello (struct isis_circuit *circuit, int level);
-
-int authentication_check (struct isis_passwd *one,
- struct isis_passwd *theother);
+#define ISIS_AUTH_MD5_SIZE 16U
+int authentication_check (struct isis_passwd *remote, struct isis_passwd *local, struct isis_circuit *c);
#endif /* _ZEBRA_ISIS_PDU_H */
diff --git a/isisd/isis_pfpacket.c b/isisd/isis_pfpacket.c
index 8752dba5..8a5c3ed0 100644
--- a/isisd/isis_pfpacket.c
+++ b/isisd/isis_pfpacket.c
@@ -21,6 +21,7 @@
*/
#include <zebra.h>
+#if ISIS_METHOD == ISIS_METHOD_PFPACKET
#include <net/ethernet.h> /* the L2 protocols */
#include <netpacket/packet.h>
@@ -231,6 +232,10 @@ isis_recv_pdu_bcast (struct isis_circuit *circuit, u_char * ssnpa)
LLC_LEN, MSG_PEEK,
(struct sockaddr *) &s_addr, (socklen_t *) &addr_len);
+ if (!circuit->area) {
+ return ISIS_OK;
+ }
+
if (bytesread < 0)
{
zlog_warn ("isis_recv_packet_bcast(): fd %d, recvfrom (): %s",
@@ -371,3 +376,5 @@ isis_send_pdu_p2p (struct isis_circuit *circuit, int level)
return ISIS_OK;
}
+
+#endif /* ISIS_METHOD == ISIS_METHOD_PFPACKET */
diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c
index 5d7e9da4..5d0b161f 100644
--- a/isisd/isis_spf.c
+++ b/isisd/isis_spf.c
@@ -405,12 +405,13 @@ isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype,
if (adj)
listnode_add (vertex->Adj_N, adj);
+
#ifdef EXTREME_DEBUG
zlog_debug ("ISIS-Spf: add to TENT %s %s depth %d dist %d",
vtype2string (vertex->type), vid2string (vertex, buff),
vertex->depth, vertex->d_N);
#endif /* EXTREME_DEBUG */
- listnode_add (spftree->tents, vertex);
+
if (list_isempty (spftree->tents))
{
listnode_add (spftree->tents, vertex);
@@ -549,7 +550,8 @@ process_N (struct isis_spftree *spftree, enum vertextype vtype, void *id,
*/
static int
isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp,
- uint32_t cost, uint16_t depth, int family)
+ uint32_t cost, uint16_t depth, int family,
+ struct isis_adjacency *adj)
{
struct listnode *node, *fragnode = NULL;
u_int16_t dist;
@@ -563,9 +565,6 @@ isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp,
struct ipv6_reachability *ip6reach;
#endif /* HAVE_IPV6 */
-
- if (!lsp->adj)
- return ISIS_WARNING;
if (lsp->tlv_data.nlpids == NULL || !speaks (lsp->tlv_data.nlpids, family))
return ISIS_OK;
@@ -591,7 +590,7 @@ lspfragloop:
vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS
: VTYPE_NONPSEUDO_IS;
process_N (spftree, vtype, (void *) is_neigh->neigh_id, dist,
- depth + 1, lsp->adj, family);
+ depth + 1, adj, family);
}
}
if (lsp->tlv_data.te_is_neighs)
@@ -607,7 +606,7 @@ lspfragloop:
vtype = LSP_PSEUDO_ID (te_is_neigh->neigh_id) ? VTYPE_PSEUDO_TE_IS
: VTYPE_NONPSEUDO_TE_IS;
process_N (spftree, vtype, (void *) te_is_neigh->neigh_id, dist,
- depth + 1, lsp->adj, family);
+ depth + 1, adj, family);
}
}
if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs)
@@ -621,7 +620,7 @@ lspfragloop:
prefix.u.prefix4 = ipreach->prefix;
prefix.prefixlen = ip_masklen (ipreach->mask);
process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
- lsp->adj, family);
+ adj, family);
}
}
@@ -636,7 +635,7 @@ lspfragloop:
prefix.u.prefix4 = ipreach->prefix;
prefix.prefixlen = ip_masklen (ipreach->mask);
process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
- lsp->adj, family);
+ adj, family);
}
}
if (family == AF_INET && lsp->tlv_data.te_ipv4_reachs)
@@ -651,7 +650,7 @@ lspfragloop:
te_ipv4_reach->control);
prefix.prefixlen = (te_ipv4_reach->control & 0x3F);
process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
- lsp->adj, family);
+ adj, family);
}
}
#ifdef HAVE_IPV6
@@ -668,7 +667,7 @@ lspfragloop:
memcpy (&prefix.u.prefix6.s6_addr, ip6reach->prefix,
PSIZE (ip6reach->prefix_len));
process_N (spftree, vtype, (void *) &prefix, dist, depth + 1,
- lsp->adj, family);
+ adj, family);
}
}
#endif /* HAVE_IPV6 */
@@ -691,7 +690,8 @@ lspfragloop:
static int
isis_spf_process_pseudo_lsp (struct isis_spftree *spftree,
struct isis_lsp *lsp, uint16_t cost,
- uint16_t depth, int family)
+ uint16_t depth, int family,
+ struct isis_adjacency *adj)
{
struct listnode *node, *fragnode = NULL;
struct is_neigh *is_neigh;
@@ -715,13 +715,13 @@ pseudofragloop:
/* Two way connectivity */
if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN))
continue;
- if (isis_find_vertex
- (spftree->tents, (void *) is_neigh->neigh_id, vtype) == NULL
+ if ((depth > 0 || isis_find_vertex
+ (spftree->tents, (void *) is_neigh->neigh_id, vtype) == NULL)
&& isis_find_vertex (spftree->paths, (void *) is_neigh->neigh_id,
vtype) == NULL)
{
/* C.2.5 i) */
- isis_spf_add2tent (spftree, vtype, is_neigh->neigh_id, lsp->adj,
+ isis_spf_add2tent (spftree, vtype, is_neigh->neigh_id, adj,
cost, depth, family);
}
}
@@ -733,13 +733,13 @@ pseudofragloop:
/* Two way connectivity */
if (!memcmp (te_is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN))
continue;
- if (isis_find_vertex
- (spftree->tents, (void *) te_is_neigh->neigh_id, vtype) == NULL
+ if ((depth > 0 || isis_find_vertex
+ (spftree->tents, (void *) te_is_neigh->neigh_id, vtype) == NULL)
&& isis_find_vertex (spftree->paths, (void *) te_is_neigh->neigh_id,
vtype) == NULL)
{
/* C.2.5 i) */
- isis_spf_add2tent (spftree, vtype, te_is_neigh->neigh_id, lsp->adj,
+ isis_spf_add2tent (spftree, vtype, te_is_neigh->neigh_id, adj,
cost, depth, family);
}
}
@@ -860,9 +860,6 @@ isis_spf_preload_tent (struct isis_spftree *spftree,
lsp = lsp_search (lsp_id, area->lspdb[level - 1]);
if (!lsp)
zlog_warn ("No lsp found for IS adjacency");
- /* else {
- isis_spf_process_lsp (spftree, lsp, vertex->d_N, 1, family);
- } */
break;
case ISIS_SYSTYPE_UNKNOWN:
default:
@@ -885,14 +882,14 @@ isis_spf_preload_tent (struct isis_spftree *spftree,
{
zlog_warn ("ISIS-Spf: No adjacency found for DR");
}
- if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0)
+ else if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0)
{
zlog_warn ("ISIS-Spf: No lsp found for DR");
}
else
{
isis_spf_process_pseudo_lsp (spftree, lsp,
- circuit->te_metric[level - 1], 0, family);
+ circuit->te_metric[level - 1], 0, family, adj);
}
}
@@ -982,6 +979,7 @@ isis_run_spf (struct isis_area *area, int level, int family)
struct isis_spftree *spftree = NULL;
u_char lsp_id[ISIS_SYS_ID_LEN + 2];
struct isis_lsp *lsp;
+ struct isis_adjacency *adj = NULL;
struct route_table *table = NULL;
struct route_node *rode;
struct isis_route_info *rinfo;
@@ -1032,16 +1030,28 @@ isis_run_spf (struct isis_area *area, int level, int family)
while (listcount (spftree->tents) > 0)
{
+ /* C.2.7 a) 1) */
node = listhead (spftree->tents);
vertex = listgetdata (node);
- /* Remove from tent list */
+
+ /* C.2.7 a) 2) */
list_delete_node (spftree->tents, node);
+
+ /* C.2.7 a) 3) */
if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type))
continue;
add_to_paths (spftree, vertex, area, level);
+
if (vertex->type == VTYPE_PSEUDO_IS ||
- vertex->type == VTYPE_NONPSEUDO_IS)
+ vertex->type == VTYPE_NONPSEUDO_IS ||
+ vertex->type == VTYPE_PSEUDO_TE_IS ||
+ vertex->type == VTYPE_NONPSEUDO_TE_IS )
{
+ if (listcount(vertex->Adj_N) == 0) {
+ continue;
+ }
+ adj = listgetdata(vertex->Adj_N->head);
+
memcpy (lsp_id, vertex->N.id, ISIS_SYS_ID_LEN + 1);
LSP_FRAGMENT (lsp_id) = 0;
lsp = lsp_search (lsp_id, area->lspdb[level - 1]);
@@ -1050,13 +1060,12 @@ isis_run_spf (struct isis_area *area, int level, int family)
if (LSP_PSEUDO_ID (lsp_id))
{
isis_spf_process_pseudo_lsp (spftree, lsp, vertex->d_N,
- vertex->depth, family);
-
+ vertex->depth, family, adj);
}
else
{
isis_spf_process_lsp (spftree, lsp, vertex->d_N,
- vertex->depth, family);
+ vertex->depth, family, adj);
}
}
else
diff --git a/isisd/isis_tlv.c b/isisd/isis_tlv.c
index 94fa65ed..3fc717e3 100644
--- a/isisd/isis_tlv.c
+++ b/isisd/isis_tlv.c
@@ -446,6 +446,10 @@ parse_tlvs (char *areatag, u_char * stream, int size, u_int32_t * expected,
tlvs->auth_info.len = length-1;
pnt++;
memcpy (tlvs->auth_info.passwd, pnt, length - 1);
+ /* Fill authentication with 0 for later computation
+ * of MD5 (RFC 5304, 2)
+ */
+ memset (pnt, 0, length - 1);
pnt += length - 1;
}
else
@@ -741,7 +745,7 @@ add_tlv (u_char tag, u_char len, u_char * value, struct stream *stream)
stream_putc (stream, len); /* LENGTH */
stream_put (stream, value, (int) len); /* VALUE */
-#ifdef EXTREME_DEBUG
+#ifdef EXTREME_TLV_DEBUG
zlog_debug ("Added TLV %d len %d", tag, len);
#endif /* EXTREME DEBUG */
return ISIS_OK;
@@ -878,7 +882,7 @@ tlv_add_authinfo (char auth_type, char auth_len, u_char *auth_value,
{
u_char value[255];
u_char *pos = value;
- *pos++ = ISIS_PASSWD_TYPE_CLEARTXT;
+ *pos++ = auth_type;
memcpy (pos, auth_value, auth_len);
return add_tlv (AUTH_INFO, auth_len + 1, value, stream);
diff --git a/isisd/isisd.c b/isisd/isisd.c
index 1e84a1ce..20a32809 100644
--- a/isisd/isisd.c
+++ b/isisd/isisd.c
@@ -52,6 +52,7 @@
#include "isisd/isis_route.h"
#include "isisd/isis_zebra.h"
#include "isisd/isis_events.h"
+#include "isisd/isis_csm.h"
#ifdef TOPOLOGY_GENERATE
#include "spgrid.h"
@@ -217,21 +218,31 @@ isis_area_destroy (struct vty *vty, const char *area_tag)
for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit))
{
/* The fact that it's in circuit_list means that it was configured */
+ isis_csm_state_change (ISIS_DISABLE, circuit, area);
+ isis_circuit_down (circuit);
isis_circuit_deconfigure (circuit, area);
- isis_circuit_del (circuit);
}
list_delete (area->circuit_list);
}
listnode_delete (isis->area_list, area);
+
THREAD_TIMER_OFF (area->t_tick);
if (area->t_remove_aged)
thread_cancel (area->t_remove_aged);
THREAD_TIMER_OFF (area->t_lsp_refresh[0]);
THREAD_TIMER_OFF (area->t_lsp_refresh[1]);
+ THREAD_TIMER_OFF (area->spftree[0]->t_spf);
+ THREAD_TIMER_OFF (area->spftree[1]->t_spf);
+
+ THREAD_TIMER_OFF (area->t_lsp_l1_regenerate);
+ THREAD_TIMER_OFF (area->t_lsp_l2_regenerate);
+
XFREE (MTYPE_ISIS_AREA, area);
+ isis->sysid_set=0;
+
return CMD_SUCCESS;
}
diff --git a/isisd/isisd.h b/isisd/isisd.h
index 2277f27c..b17982e2 100644
--- a/isisd/isisd.h
+++ b/isisd/isisd.h
@@ -93,6 +93,8 @@ struct isis_area
struct flags flags;
struct thread *t_tick; /* LSP walker */
struct thread *t_remove_aged;
+ struct thread *t_lsp_l1_regenerate;
+ struct thread *t_lsp_l2_regenerate;
int lsp_regenerate_pending[ISIS_LEVELS];
struct thread *t_lsp_refresh[ISIS_LEVELS];
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 315e919b..1b4134dc 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
+DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DPATH_CONFIG=\"$(sysconfdir)\"
lib_LTLIBRARIES = libzebra.la
libzebra_la_LDFLAGS = -version-info 0:0:0
@@ -12,13 +12,13 @@ libzebra_la_SOURCES = \
sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \
filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c privs.c \
- sigevent.c pqueue.c jhash.c memtypes.c workqueue.c
+ sigevent.c pqueue.c jhash.c memtypes.c workqueue.c paths.c
BUILT_SOURCES = memtypes.h route_types.h
libzebra_la_DEPENDENCIES = @LIB_REGEX@
-libzebra_la_LIBADD = @LIB_REGEX@
+libzebra_la_LIBADD = @LIB_REGEX@ @LIBCAP@
pkginclude_HEADERS = \
buffer.h checksum.h command.h filter.h getopt.h hash.h \
@@ -27,12 +27,12 @@ pkginclude_HEADERS = \
str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
plist.h zclient.h sockopt.h smux.h md5.h if_rmap.h keychain.h \
privs.h sigevent.h pqueue.h jhash.h zassert.h memtypes.h \
- workqueue.h route_types.h
+ workqueue.h route_types.h paths.h
-EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.awk route_types.txt
+EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.pl route_types.txt
memtypes.h: $(srcdir)/memtypes.c $(srcdir)/memtypes.awk
($(GAWK) -f $(srcdir)/memtypes.awk $(srcdir)/memtypes.c > $@)
-route_types.h: $(srcdir)/route_types.txt $(srcdir)/route_types.awk
- ($(GAWK) -f $(srcdir)/route_types.awk $(srcdir)/route_types.txt > $@)
+route_types.h: $(srcdir)/route_types.txt $(srcdir)/route_types.pl
+ @PERL@ $(srcdir)/route_types.pl < $(srcdir)/route_types.txt > $@
diff --git a/lib/checksum.c b/lib/checksum.c
index 3ddde815..af4f2550 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -14,27 +14,20 @@ in_cksum(void *parg, int nbytes)
{
u_short *ptr = parg;
register long sum; /* assumes long == 32 bits */
- u_short oddbyte;
register u_short answer; /* assumes u_short == 16 bits */
-
+ register int count;
/*
* Our algorithm is simple, using a 32-bit accumulator (sum),
* we add sequential 16-bit words to it, and at the end, fold back
* all the carry bits from the top 16 bits into the lower 16 bits.
*/
-
sum = 0;
- while (nbytes > 1) {
- sum += *ptr++;
- nbytes -= 2;
- }
-
- /* mop up an odd byte, if necessary */
- if (nbytes == 1) {
- oddbyte = 0; /* make sure top half is zero */
- *((u_char *) &oddbyte) = *(u_char *)ptr; /* one byte only */
- sum += oddbyte;
- }
+ count = nbytes >> 1; /* div by 2 */
+ for(ptr--; count; --count)
+ sum += *++ptr;
+
+ if (nbytes & 1) /* Odd */
+ sum += *(u_char *)(++ptr); /* one byte only */
/*
* Add back carry outs from top 16 bits to low 16 bits.
@@ -56,11 +49,8 @@ fletcher_checksum(u_char * buffer, const size_t len, const uint16_t offset)
{
u_int8_t *p;
int x, y, c0, c1;
- u_int16_t checksum;
u_int16_t *csum;
size_t partial_len, i, left = len;
-
- checksum = 0;
assert (offset < len);
@@ -68,47 +58,42 @@ fletcher_checksum(u_char * buffer, const size_t len, const uint16_t offset)
* Zero the csum in the packet.
*/
csum = (u_int16_t *) (buffer + offset);
- *(csum) = 0;
+ *csum = 0;
- p = buffer;
+ p = buffer - 1;
c0 = 0;
c1 = 0;
while (left != 0)
{
partial_len = MIN(left, MODX);
+ left -= partial_len;
- for (i = 0; i < partial_len; i++)
+ do
{
- c0 = c0 + *(p++);
+ c0 = c0 + *(++p);
c1 += c0;
- }
+ } while (--partial_len);
c0 = c0 % 255;
c1 = c1 % 255;
-
- left -= partial_len;
}
-
+
/* The cast is important, to ensure the mod is taken as a signed value. */
x = (int)((len - offset - 1) * c0 - c1) % 255;
if (x <= 0)
x += 255;
y = 510 - c0 - x;
- if (y > 255)
+ if (y > 255)
y -= 255;
-
+
/*
* Now we write this to the packet.
* We could skip this step too, since the checksum returned would
* be stored into the checksum field by the caller.
+ * Checksum is always big endian.
*/
- buffer[offset] = x;
- buffer[offset + 1] = y;
-
- /* Take care of the endian issue */
- checksum = htons((x << 8) | (y & 0xFF));
-
- return checksum;
+ *csum = htons((x << 8) | (y & 0xFF));
+ return *csum;
}
diff --git a/lib/command.c b/lib/command.c
index 478125f2..19fc192a 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */
#include "vty.h"
#include "command.h"
#include "workqueue.h"
+#include <stdbool.h>
/* Command vector which includes some level of command lists. Normally
each daemon maintains each own cmdvec. */
@@ -84,9 +85,9 @@ static struct cmd_node config_node =
/* Default motd string. */
static const char *default_motd =
"\r\n\
-Hello, this is " QUAGGA_PROGNAME " (version " QUAGGA_VERSION ").\r\n\
-" QUAGGA_COPYRIGHT "\r\n\
-\r\n";
+This is " QUAGGA_PROGNAME " " QUAGGA_VERSION "\r\n\r\n\
+You're using the dn42 branch. Send bug reports to equinox@diac24.net\r\n\
+The 1.1.0 version number is for package management purposes only.\r\n";
static const struct facility_map {
@@ -686,7 +687,8 @@ cmd_filter_by_symbol (char *command, char *symbol)
/* Completion match types. */
enum match_type
{
- no_match,
+ no_match = 0,
+ any_match,
extend_match,
ipv4_prefix_match,
ipv4_match,
@@ -695,7 +697,7 @@ enum match_type
range_match,
vararg_match,
partly_match,
- exact_match
+ exact_match,
};
static enum match_type
@@ -1132,12 +1134,100 @@ cmd_range_match (const char *range, const char *str)
return 1;
}
-/* Make completion match and return match type flag. */
+/* helper to retrieve the 'real' argument string from an optional argument */
+static char *
+cmd_deopt (const char *str)
+{
+ /* we've got "[blah]". We want to strip off the []s and redo the
+ * match check for "blah"
+ */
+ size_t len = strlen (str);
+ char *tmp;
+
+ if (len < 3)
+ return NULL;
+
+ /* tmp will hold a string of len-2 chars, so 'len' size is fine */
+ tmp = XMALLOC(MTYPE_TMP, len);
+
+ memcpy (tmp, (str + 1), len - 2);
+ tmp[len - 2] = '\0';
+
+ return tmp;
+}
+
+static enum match_type
+cmd_match (const char *str, const char *command,
+ enum match_type min, bool recur)
+{
+
+ if (recur && CMD_OPTION(str))
+ {
+ enum match_type ret;
+ char *tmp = cmd_deopt (str);
+
+ /* this would be a bug in a command, however handle it gracefully
+ * as it we only discover it if a user tries to run it
+ */
+ if (tmp == NULL)
+ return no_match;
+
+ ret = cmd_match (tmp, command, min, false);
+
+ XFREE (MTYPE_TMP, tmp);
+
+ return ret;
+ }
+ else if (CMD_VARARG (str))
+ return vararg_match;
+ else if (CMD_RANGE (str))
+ {
+ if (cmd_range_match (str, command))
+ return range_match;
+ }
+#ifdef HAVE_IPV6
+ else if (CMD_IPV6 (str))
+ {
+ if (cmd_ipv6_match (command) >= min)
+ return ipv6_match;
+ }
+ else if (CMD_IPV6_PREFIX (str))
+ {
+ if (cmd_ipv6_prefix_match (command) >= min)
+ return ipv6_prefix_match;
+ }
+#endif /* HAVE_IPV6 */
+ else if (CMD_IPV4 (str))
+ {
+ if (cmd_ipv4_match (command) >= min)
+ return ipv4_match;
+ }
+ else if (CMD_IPV4_PREFIX (str))
+ {
+ if (cmd_ipv4_prefix_match (command) >= min)
+ return ipv4_prefix_match;
+ }
+ else if (CMD_VARIABLE (str))
+ return extend_match;
+ else if (strncmp (command, str, strlen (command)) == 0)
+ {
+ if (strcmp (command, str) == 0)
+ return exact_match;
+ else if (partly_match >= min)
+ return partly_match;
+ }
+
+ return no_match;
+}
+
+/* Filter vector at the specified index and by the given command string, to
+ * the desired matching level (thus allowing part matches), and return match
+ * type flag.
+ */
static enum match_type
-cmd_filter_by_completion (char *command, vector v, unsigned int index)
+cmd_filter (char *command, vector v, unsigned int index, enum match_type level)
{
unsigned int i;
- const char *str;
struct cmd_element *cmd_element;
enum match_type match_type;
vector descvec;
@@ -1160,112 +1250,42 @@ cmd_filter_by_completion (char *command, vector v, unsigned int index)
for (j = 0; j < vector_active (descvec); j++)
if ((desc = vector_slot (descvec, j)))
- {
- str = desc->cmd;
-
- if (CMD_VARARG (str))
- {
- if (match_type < vararg_match)
- match_type = vararg_match;
- matched++;
- }
- else if (CMD_RANGE (str))
- {
- if (cmd_range_match (str, command))
- {
- if (match_type < range_match)
- match_type = range_match;
+ {
+ enum match_type ret;
- matched++;
- }
- }
-#ifdef HAVE_IPV6
- else if (CMD_IPV6 (str))
- {
- if (cmd_ipv6_match (command))
- {
- if (match_type < ipv6_match)
- match_type = ipv6_match;
-
- matched++;
- }
- }
- else if (CMD_IPV6_PREFIX (str))
- {
- if (cmd_ipv6_prefix_match (command))
- {
- if (match_type < ipv6_prefix_match)
- match_type = ipv6_prefix_match;
-
- matched++;
- }
- }
-#endif /* HAVE_IPV6 */
- else if (CMD_IPV4 (str))
- {
- if (cmd_ipv4_match (command))
- {
- if (match_type < ipv4_match)
- match_type = ipv4_match;
+ ret = cmd_match (desc->cmd, command, level, true);
+
+ if (ret != no_match)
+ matched++;
- matched++;
- }
- }
- else if (CMD_IPV4_PREFIX (str))
- {
- if (cmd_ipv4_prefix_match (command))
- {
- if (match_type < ipv4_prefix_match)
- match_type = ipv4_prefix_match;
- matched++;
- }
- }
- else
- /* Check is this point's argument optional ? */
- if (CMD_OPTION (str) || CMD_VARIABLE (str))
- {
- if (match_type < extend_match)
- match_type = extend_match;
- matched++;
- }
- else if (strncmp (command, str, strlen (command)) == 0)
- {
- if (strcmp (command, str) == 0)
- match_type = exact_match;
- else
- {
- if (match_type < partly_match)
- match_type = partly_match;
- }
- matched++;
- }
+ if (match_type < ret)
+ match_type = ret;
}
if (!matched)
vector_slot (v, i) = NULL;
}
}
- return match_type;
-}
-/* Filter vector by command character with index. */
-static enum match_type
-cmd_filter_by_string (char *command, vector v, unsigned int index)
-{
- unsigned int i;
- const char *str;
- struct cmd_element *cmd_element;
- enum match_type match_type;
- vector descvec;
- struct desc *desc;
-
- match_type = no_match;
+ if (match_type == no_match)
+ return no_match;
- /* If command and cmd_element string does not match set NULL to vector */
+ /* 2nd pass: We now know the 'strongest' match type for the index, so we
+ * go again and filter out commands whose argument (at this index) is
+ * 'weaker'. E.g., if we have 2 commands:
+ *
+ * foo bar <1-255>
+ * foo bar BLAH
+ *
+ * and the command string is 'foo bar 10', then we will get here with with
+ * 'range_match' being the strongest match. However, if 'BLAH' came
+ * earlier, it won't have been filtered out (as a CMD_VARIABLE allows "10").
+ *
+ * If we don't do a 2nd pass and filter it out, the higher-layers will
+ * consider this to be ambiguous.
+ */
for (i = 0; i < vector_active (v); i++)
if ((cmd_element = vector_slot (v, i)) != NULL)
{
- /* If given index is bigger than max string vector of command,
- set NULL */
if (index >= vector_active (cmd_element->strvec))
vector_slot (v, i) = NULL;
else
@@ -1277,81 +1297,19 @@ cmd_filter_by_string (char *command, vector v, unsigned int index)
for (j = 0; j < vector_active (descvec); j++)
if ((desc = vector_slot (descvec, j)))
- {
- str = desc->cmd;
+ {
+ enum match_type ret;
- if (CMD_VARARG (str))
- {
- if (match_type < vararg_match)
- match_type = vararg_match;
- matched++;
- }
- else if (CMD_RANGE (str))
- {
- if (cmd_range_match (str, command))
- {
- if (match_type < range_match)
- match_type = range_match;
- matched++;
- }
- }
-#ifdef HAVE_IPV6
- else if (CMD_IPV6 (str))
- {
- if (cmd_ipv6_match (command) == exact_match)
- {
- if (match_type < ipv6_match)
- match_type = ipv6_match;
- matched++;
- }
- }
- else if (CMD_IPV6_PREFIX (str))
- {
- if (cmd_ipv6_prefix_match (command) == exact_match)
- {
- if (match_type < ipv6_prefix_match)
- match_type = ipv6_prefix_match;
- matched++;
- }
- }
-#endif /* HAVE_IPV6 */
- else if (CMD_IPV4 (str))
- {
- if (cmd_ipv4_match (command) == exact_match)
- {
- if (match_type < ipv4_match)
- match_type = ipv4_match;
- matched++;
- }
- }
- else if (CMD_IPV4_PREFIX (str))
- {
- if (cmd_ipv4_prefix_match (command) == exact_match)
- {
- if (match_type < ipv4_prefix_match)
- match_type = ipv4_prefix_match;
- matched++;
- }
- }
- else if (CMD_OPTION (str) || CMD_VARIABLE (str))
- {
- if (match_type < extend_match)
- match_type = extend_match;
- matched++;
- }
- else
- {
- if (strcmp (command, str) == 0)
- {
- match_type = exact_match;
- matched++;
- }
- }
+ ret = cmd_match (desc->cmd, command, any_match, true);
+
+ if (ret >= match_type)
+ matched++;
}
if (!matched)
vector_slot (v, i) = NULL;
}
}
+
return match_type;
}
@@ -1361,7 +1319,6 @@ is_cmd_ambiguous (char *command, vector v, int index, enum match_type type)
{
unsigned int i;
unsigned int j;
- const char *str = NULL;
struct cmd_element *cmd_element;
const char *matched = NULL;
vector descvec;
@@ -1378,18 +1335,21 @@ is_cmd_ambiguous (char *command, vector v, int index, enum match_type type)
if ((desc = vector_slot (descvec, j)))
{
enum match_type ret;
-
- str = desc->cmd;
+ char *str = desc->cmd;
+ if (CMD_OPTION(str))
+ if ((str = cmd_deopt (str)) == NULL)
+ continue;
+
switch (type)
{
case exact_match:
- if (!(CMD_OPTION (str) || CMD_VARIABLE (str))
+ if (!(CMD_VARIABLE (str))
&& strcmp (command, str) == 0)
match++;
break;
case partly_match:
- if (!(CMD_OPTION (str) || CMD_VARIABLE (str))
+ if (!(CMD_VARIABLE (str))
&& strncmp (command, str, strlen (command)) == 0)
{
if (matched && strcmp (matched, str) != 0)
@@ -1438,13 +1398,16 @@ is_cmd_ambiguous (char *command, vector v, int index, enum match_type type)
}
break;
case extend_match:
- if (CMD_OPTION (str) || CMD_VARIABLE (str))
+ if (CMD_VARIABLE (str))
match++;
break;
case no_match:
default:
break;
}
+
+ if (CMD_OPTION(desc->cmd))
+ XFREE (MTYPE_TMP, str);
}
if (!match)
vector_slot (v, i) = NULL;
@@ -1614,7 +1577,7 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status)
for (i = 0; i < index; i++)
if ((command = vector_slot (vline, i)))
{
- match = cmd_filter_by_completion (command, cmd_vector, i);
+ match = cmd_filter (command, cmd_vector, i, any_match);
if (match == vararg_match)
{
@@ -1663,7 +1626,7 @@ cmd_describe_command_real (vector vline, struct vty *vty, int *status)
/* Make sure that cmd_vector is filtered based on current word */
command = vector_slot (vline, index);
if (command)
- match = cmd_filter_by_completion (command, cmd_vector, index);
+ match = cmd_filter (command, cmd_vector, index, any_match);
/* Make description vector. */
for (i = 0; i < vector_active (cmd_vector); i++)
@@ -1817,7 +1780,7 @@ cmd_complete_command_real (vector vline, struct vty *vty, int *status)
int ret;
/* First try completion match, if there is exactly match return 1 */
- match = cmd_filter_by_completion (command, cmd_vector, i);
+ match = cmd_filter (command, cmd_vector, i, any_match);
/* If there is exact match then filter ambiguous match else check
ambiguousness. */
@@ -2026,7 +1989,7 @@ cmd_execute_command_real (vector vline, struct vty *vty,
{
int ret;
- match = cmd_filter_by_completion (command, cmd_vector, index);
+ match = cmd_filter (command, cmd_vector, index, any_match);
if (match == vararg_match)
break;
@@ -2205,8 +2168,8 @@ cmd_execute_command_strict (vector vline, struct vty *vty,
{
int ret;
- match = cmd_filter_by_string (vector_slot (vline, index),
- cmd_vector, index);
+ match = cmd_filter (vector_slot (vline, index), cmd_vector,
+ index, exact_match);
/* If command meets '.VARARG' then finish matching. */
if (match == vararg_match)
@@ -2301,13 +2264,15 @@ cmd_execute_command_strict (vector vline, struct vty *vty,
/* Configration make from file. */
int
-config_from_file (struct vty *vty, FILE *fp)
+config_from_file (struct vty *vty, FILE *fp, unsigned int *line_num)
{
int ret;
+ *line_num = 0;
vector vline;
while (fgets (vty->buf, VTY_BUFSIZ, fp))
{
+ ++(*line_num);
vline = cmd_make_strvec (vty->buf);
/* In case of comment line */
@@ -2408,6 +2373,7 @@ DEFUN (config_exit,
case KEYCHAIN_NODE:
case MASC_NODE:
case RMAP_NODE:
+ case PIM_NODE:
case VTY_NODE:
vty->node = CONFIG_NODE;
break;
@@ -2464,6 +2430,7 @@ DEFUN (config_end,
case KEYCHAIN_NODE:
case KEYCHAIN_KEY_NODE:
case MASC_NODE:
+ case PIM_NODE:
case VTY_NODE:
vty_config_unlock (vty);
vty->node = ENABLE_NODE;
@@ -3056,7 +3023,8 @@ DEFUN (config_logmsg,
if ((level = level_match(argv[0])) == ZLOG_DISABLED)
return CMD_ERR_NO_MATCH;
- zlog(NULL, level, ((message = argv_concat(argv, argc, 1)) ? message : ""));
+ message = argv_concat(argv, argc, 1);
+ zlog(NULL, level, "%s", message ? message : "");
if (message)
XFREE(MTYPE_TMP, message);
return CMD_SUCCESS;
@@ -3650,6 +3618,8 @@ cmd_init (int terminal)
install_element (VIEW_NODE, &show_thread_cpu_cmd);
install_element (ENABLE_NODE, &show_thread_cpu_cmd);
install_element (RESTRICTED_NODE, &show_thread_cpu_cmd);
+
+ install_element (ENABLE_NODE, &clear_thread_cpu_cmd);
install_element (VIEW_NODE, &show_work_queues_cmd);
install_element (ENABLE_NODE, &show_work_queues_cmd);
}
diff --git a/lib/command.h b/lib/command.h
index 1275efee..a2f5eab8 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -1,6 +1,7 @@
/*
* Zebra configuration command interface routine
* Copyright (C) 1997, 98 Kunihiro Ishiguro
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
*
* This file is part of GNU Zebra.
*
@@ -87,6 +88,7 @@ enum node_type
OSPF_NODE, /* OSPF protocol mode */
OSPF6_NODE, /* OSPF protocol for IPv6 mode */
ISIS_NODE, /* ISIS protocol mode */
+ PIM_NODE, /* PIM protocol mode */
MASC_NODE, /* MASC for multicast. */
IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
IP_NODE, /* Static ip route node. */
@@ -341,7 +343,7 @@ extern void cmd_free_strvec (vector);
extern vector cmd_describe_command (vector, struct vty *, int *status);
extern char **cmd_complete_command (vector, struct vty *, int *status);
extern const char *cmd_prompt (enum node_type);
-extern int config_from_file (struct vty *, FILE *);
+extern int config_from_file (struct vty *, FILE *, unsigned int *line_num);
extern enum node_type node_parent (enum node_type);
extern int cmd_execute_command (vector, struct vty *, struct cmd_element **, int);
extern int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **);
diff --git a/lib/if.c b/lib/if.c
index e3107116..d14cfb93 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -664,7 +664,7 @@ connected_log (struct connected *connected, char *str)
strncat (logbuf, inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
BUFSIZ - strlen(logbuf));
}
- zlog (NULL, LOG_INFO, logbuf);
+ zlog (NULL, LOG_INFO, "%s", logbuf);
}
/* If two connected address has same prefix return 1. */
diff --git a/lib/if.h b/lib/if.h
index c99ab81b..b28f32b5 100644
--- a/lib/if.h
+++ b/lib/if.h
@@ -90,6 +90,7 @@ struct interface
#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
#define ZEBRA_INTERFACE_SUB (1 << 1)
#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
+#define ZEBRA_INTERFACE_UNNUMBERED (1 << 3)
/* Interface flags. */
uint64_t flags;
@@ -172,6 +173,12 @@ struct connected
/* Label for Linux 2.2.X and upper. */
char *label;
+
+ /* scope value, Linux only */
+ unsigned scope;
+
+ /* address preference, NetBSD >=4.0 with option IPSRCSEL, in_getifa(9) */
+ int preference;
};
/* Does the destination field contain a peer address? */
diff --git a/lib/log.c b/lib/log.c
index 0c2f655b..cfac61b1 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -3,6 +3,7 @@
*
* Logging of zebra
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
*
* This file is part of GNU Zebra.
*
@@ -22,6 +23,8 @@
* 02111-1307, USA.
*/
+#define QUAGGA_DEFINE_DESC_TABLE
+
#include <zebra.h>
#include "log.h"
@@ -50,6 +53,7 @@ const char *zlog_proto_names[] =
"RIPNG",
"OSPF6",
"ISIS",
+ "PIM",
"MASC",
NULL,
};
@@ -759,7 +763,7 @@ lookup (const struct message *mes, int key)
{
const struct message *pnt;
- for (pnt = mes; pnt->key != 0; pnt++)
+ for (pnt = mes; pnt->str; pnt++)
if (pnt->key == key)
return pnt->str;
@@ -815,29 +819,6 @@ safe_strerror(int errnum)
return (s != NULL) ? s : "Unknown error";
}
-struct zebra_desc_table
-{
- unsigned int type;
- const char *string;
- char chr;
-};
-
-#define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
-static const struct zebra_desc_table route_types[] = {
- DESC_ENTRY (ZEBRA_ROUTE_SYSTEM, "system", 'X' ),
- DESC_ENTRY (ZEBRA_ROUTE_KERNEL, "kernel", 'K' ),
- DESC_ENTRY (ZEBRA_ROUTE_CONNECT, "connected", 'C' ),
- DESC_ENTRY (ZEBRA_ROUTE_STATIC, "static", 'S' ),
- DESC_ENTRY (ZEBRA_ROUTE_RIP, "rip", 'R' ),
- DESC_ENTRY (ZEBRA_ROUTE_RIPNG, "ripng", 'R' ),
- DESC_ENTRY (ZEBRA_ROUTE_OSPF, "ospf", 'O' ),
- DESC_ENTRY (ZEBRA_ROUTE_OSPF6, "ospf6", 'O' ),
- DESC_ENTRY (ZEBRA_ROUTE_ISIS, "isis", 'I' ),
- DESC_ENTRY (ZEBRA_ROUTE_BGP, "bgp", 'B' ),
- DESC_ENTRY (ZEBRA_ROUTE_HSLS, "hsls", 'H' ),
-};
-#undef DESC_ENTRY
-
#define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
static const struct zebra_desc_table command_types[] = {
DESC_ENTRY (ZEBRA_INTERFACE_ADD),
@@ -927,4 +908,58 @@ proto_name2num(const char *s)
return route_types[i].type;
return -1;
}
+
#undef RTSIZE
+
+int
+proto_redistnum(int afi, const char *s)
+{
+ if (! s)
+ return -1;
+
+ if (afi == AFI_IP)
+ {
+ if (strncmp (s, "k", 1) == 0)
+ return ZEBRA_ROUTE_KERNEL;
+ else if (strncmp (s, "c", 1) == 0)
+ return ZEBRA_ROUTE_CONNECT;
+ else if (strncmp (s, "s", 1) == 0)
+ return ZEBRA_ROUTE_STATIC;
+ else if (strncmp (s, "r", 1) == 0)
+ return ZEBRA_ROUTE_RIP;
+ else if (strncmp (s, "os", 2) == 0)
+ return ZEBRA_ROUTE_OSPF;
+ else if (strncmp (s, "i", 1) == 0)
+ return ZEBRA_ROUTE_ISIS;
+ else if (strncmp (s, "bg", 2) == 0)
+ return ZEBRA_ROUTE_BGP;
+ else if (strncmp (s, "ol", 2) == 0)
+ return ZEBRA_ROUTE_OLSR;
+ else if (strncmp (s, "ba", 2) == 0)
+ return ZEBRA_ROUTE_BATMAN;
+ else if (strncmp (s, "d", 1) == 0)
+ return ZEBRA_ROUTE_DHCP;
+ }
+ if (afi == AFI_IP6)
+ {
+ if (strncmp (s, "k", 1) == 0)
+ return ZEBRA_ROUTE_KERNEL;
+ else if (strncmp (s, "c", 1) == 0)
+ return ZEBRA_ROUTE_CONNECT;
+ else if (strncmp (s, "s", 1) == 0)
+ return ZEBRA_ROUTE_STATIC;
+ else if (strncmp (s, "r", 1) == 0)
+ return ZEBRA_ROUTE_RIPNG;
+ else if (strncmp (s, "os", 2) == 0)
+ return ZEBRA_ROUTE_OSPF6;
+ else if (strncmp (s, "i", 1) == 0)
+ return ZEBRA_ROUTE_ISIS;
+ else if (strncmp (s, "bg", 2) == 0)
+ return ZEBRA_ROUTE_BGP;
+ else if (strncmp (s, "ol", 2) == 0)
+ return ZEBRA_ROUTE_OLSR;
+ else if (strncmp (s, "ba", 2) == 0)
+ return ZEBRA_ROUTE_BATMAN;
+ }
+ return -1;
+}
diff --git a/lib/log.h b/lib/log.h
index 2dd1d313..185bcee8 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -3,6 +3,7 @@
*
* Zebra logging funcions.
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
*
* This file is part of GNU Zebra.
*
@@ -54,6 +55,7 @@ typedef enum
ZLOG_RIPNG,
ZLOG_OSPF6,
ZLOG_ISIS,
+ ZLOG_PIM,
ZLOG_MASC
} zlog_proto_t;
diff --git a/lib/md5.c b/lib/md5.c
index 894de648..2fc36e17 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -298,3 +298,76 @@ static void md5_calc(const uint8_t *b64, md5_ctxt * ctxt)
ctxt->md5_stc += C;
ctxt->md5_std += D;
}
+
+/* From RFC 2104 */
+void
+hmac_md5(text, text_len, key, key_len, digest)
+unsigned char* text; /* pointer to data stream */
+int text_len; /* length of data stream */
+unsigned char* key; /* pointer to authentication key */
+int key_len; /* length of authentication key */
+caddr_t digest; /* caller digest to be filled in */
+
+{
+ MD5_CTX context;
+ unsigned char k_ipad[65]; /* inner padding -
+ * key XORd with ipad
+ */
+ unsigned char k_opad[65]; /* outer padding -
+ * key XORd with opad
+ */
+ unsigned char tk[16];
+ int i;
+ /* if key is longer than 64 bytes reset it to key=MD5(key) */
+ if (key_len > 64) {
+
+ MD5_CTX tctx;
+
+ MD5Init(&tctx);
+ MD5Update(&tctx, key, key_len);
+ MD5Final(tk, &tctx);
+
+ key = tk;
+ key_len = 16;
+ }
+
+ /*
+ * the HMAC_MD5 transform looks like:
+ *
+ * MD5(K XOR opad, MD5(K XOR ipad, text))
+ *
+ * where K is an n byte key
+ * ipad is the byte 0x36 repeated 64 times
+ * opad is the byte 0x5c repeated 64 times
+ * and text is the data being protected
+ */
+
+ /* start out by storing key in pads */
+ bzero( k_ipad, sizeof k_ipad);
+ bzero( k_opad, sizeof k_opad);
+ bcopy( key, k_ipad, key_len);
+ bcopy( key, k_opad, key_len);
+
+ /* XOR key with ipad and opad values */
+ for (i=0; i<64; i++) {
+ k_ipad[i] ^= 0x36;
+ k_opad[i] ^= 0x5c;
+ }
+ /*
+ * perform inner MD5
+ */
+ MD5Init(&context); /* init context for 1st
+ * pass */
+ MD5Update(&context, k_ipad, 64); /* start with inner pad */
+ MD5Update(&context, text, text_len); /* then text of datagram */
+ MD5Final(digest, &context); /* finish up 1st pass */
+ /*
+ * perform outer MD5
+ */
+ MD5Init(&context); /* init context for 2nd
+ * pass */
+ MD5Update(&context, k_opad, 64); /* start with outer pad */
+ MD5Update(&context, digest, 16); /* then results of 1st
+ * hash */
+ MD5Final(digest, &context); /* finish up 2nd pass */
+}
diff --git a/lib/md5.h b/lib/md5.h
index 89b9a320..3ce83a63 100644
--- a/lib/md5.h
+++ b/lib/md5.h
@@ -82,4 +82,7 @@ do { \
md5_result((x), (y)); \
} while (0)
+/* From RFC 2104 */
+void hmac_md5(unsigned char* text, int text_len, unsigned char* key, int key_len, caddr_t digest);
+
#endif /* ! _LIBZEBRA_MD5_H_*/
diff --git a/lib/memory.c b/lib/memory.c
index dc09d8a6..6291bf0d 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -1,6 +1,7 @@
/*
* Memory management routine
* Copyright (C) 1998 Kunihiro Ishiguro
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
*
* This file is part of GNU Zebra.
*
@@ -482,6 +483,17 @@ DEFUN (show_memory_isis,
return CMD_SUCCESS;
}
+DEFUN (show_memory_pim,
+ show_memory_pim_cmd,
+ "show memory pim",
+ SHOW_STR
+ "Memory statistics\n"
+ "PIM memory\n")
+{
+ show_memory_vty (vty, memory_list_pim);
+ return CMD_SUCCESS;
+}
+
void
memory_init (void)
{
@@ -504,6 +516,7 @@ memory_init (void)
install_element (VIEW_NODE, &show_memory_ospf_cmd);
install_element (VIEW_NODE, &show_memory_ospf6_cmd);
install_element (VIEW_NODE, &show_memory_isis_cmd);
+ install_element (VIEW_NODE, &show_memory_pim_cmd);
install_element (ENABLE_NODE, &show_memory_cmd);
install_element (ENABLE_NODE, &show_memory_all_cmd);
@@ -514,7 +527,7 @@ memory_init (void)
install_element (ENABLE_NODE, &show_memory_bgp_cmd);
install_element (ENABLE_NODE, &show_memory_ospf_cmd);
install_element (ENABLE_NODE, &show_memory_ospf6_cmd);
- install_element (ENABLE_NODE, &show_memory_isis_cmd);
+ install_element (ENABLE_NODE, &show_memory_pim_cmd);
}
/* Stats querying from users */
diff --git a/lib/memtypes.c b/lib/memtypes.c
index 05d93225..fd99136c 100644
--- a/lib/memtypes.c
+++ b/lib/memtypes.c
@@ -1,4 +1,6 @@
/*
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
+ *
* Memory type definitions. This file is parsed by memtypes.awk to extract
* MTYPE_ and memory_list_.. information in order to autogenerate
* memtypes.h.
@@ -244,6 +246,21 @@ struct memory_list memory_list_isis[] =
{ -1, NULL },
};
+struct memory_list memory_list_pim[] =
+{
+ { MTYPE_PIM_CHANNEL_OIL, "PIM SSM (S,G) channel OIL" },
+ { MTYPE_PIM_INTERFACE, "PIM interface" },
+ { MTYPE_PIM_IGMP_JOIN, "PIM interface IGMP static join" },
+ { MTYPE_PIM_IGMP_SOCKET, "PIM interface IGMP socket" },
+ { MTYPE_PIM_IGMP_GROUP, "PIM interface IGMP group" },
+ { MTYPE_PIM_IGMP_GROUP_SOURCE, "PIM interface IGMP source" },
+ { MTYPE_PIM_NEIGHBOR, "PIM interface neighbor" },
+ { MTYPE_PIM_IFCHANNEL, "PIM interface (S,G) state" },
+ { MTYPE_PIM_UPSTREAM, "PIM upstream (S,G) state" },
+ { MTYPE_PIM_SSMPINGD, "PIM sspimgd socket" },
+ { -1, NULL },
+};
+
struct memory_list memory_list_vtysh[] =
{
{ MTYPE_VTYSH_CONFIG, "Vtysh configuration", },
@@ -260,5 +277,6 @@ struct mlist mlists[] __attribute__ ((unused)) = {
{ memory_list_ospf6, "OSPF6" },
{ memory_list_isis, "ISIS" },
{ memory_list_bgp, "BGP" },
+ { memory_list_pim, "PIM" },
{ NULL, NULL},
};
diff --git a/lib/paths.c b/lib/paths.c
new file mode 100644
index 00000000..5678b873
--- /dev/null
+++ b/lib/paths.c
@@ -0,0 +1,65 @@
+/*
+ * Path helper functions (for namespaces)
+ * Copyright (C) 2009 David Lamparter
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <zebra.h>
+#include <log.h>
+#include <paths.h>
+
+static char *namespace = "";
+
+void path_set_namespace(const char *ns)
+{
+ size_t len;
+
+ if (*namespace)
+ free(namespace);
+ if (!ns || !*ns) {
+ namespace = "";
+ return;
+ }
+
+ len = strlen(ns);
+ namespace = malloc(len + 2);
+ if (!namespace) { /* ugh... */
+ namespace = "";
+ return;
+ };
+ namespace[0] = '/';
+ memcpy(namespace + 1, ns, len + 1);
+}
+
+const char *path_state(const char *filename)
+{
+ static char buf[MAXPATHLEN];
+ snprintf(buf, sizeof(buf), "%s%s/%s",
+ PATH_STATE, namespace, filename);
+ return buf;
+}
+
+const char *path_config(const char *filename)
+{
+ static char buf[MAXPATHLEN];
+ snprintf(buf, sizeof(buf), "%s%s/%s",
+ PATH_CONFIG, namespace, filename);
+ return buf;
+}
+
diff --git a/lib/paths.h b/lib/paths.h
new file mode 100644
index 00000000..1f697855
--- /dev/null
+++ b/lib/paths.h
@@ -0,0 +1,34 @@
+/*
+ * Path helper functions (for namespaces)
+ * Copyright (C) 2009 David Lamparter
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _ZEBRA_PATHS_H
+#define _ZEBRA_PATHS_H
+
+extern void path_set_namespace(const char *ns);
+
+/* the following two functions return pointers to a _static_ buffer!
+ * if you need to keep a reference to the values, do a strdup
+ */
+extern const char *path_state(const char *filename);
+extern const char *path_config(const char *filename);
+
+#endif /* _ZEBRA_PATHS_H */
diff --git a/lib/prefix.c b/lib/prefix.c
index c85e6594..f5de4bde 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -180,6 +180,46 @@ prefix_cmp (const struct prefix *p1, const struct prefix *p2)
return 0;
}
+/*
+ * Count the number of common bits in 2 prefixes. The prefix length is
+ * ignored for this function; the whole prefix is compared. If the prefix
+ * address families don't match, return -1; otherwise the return value is
+ * in range 0 ... maximum prefix length for the address family.
+ */
+int
+prefix_common_bits (const struct prefix *p1, const struct prefix *p2)
+{
+ int pos, bit;
+ int length = 0;
+ u_char xor;
+
+ /* Set both prefix's head pointer. */
+ const u_char *pp1 = (const u_char *)&p1->u.prefix;
+ const u_char *pp2 = (const u_char *)&p2->u.prefix;
+
+ if (p1->family == AF_INET)
+ length = IPV4_MAX_BYTELEN;
+#ifdef HAVE_IPV6
+ if (p1->family == AF_INET6)
+ length = IPV6_MAX_BYTELEN;
+#endif
+ if (p1->family != p2->family || !length)
+ return -1;
+
+ for (pos = 0; pos < length; pos++)
+ if (pp1[pos] != pp2[pos])
+ break;
+ if (pos == length)
+ return pos * 8;
+
+ xor = pp1[pos] ^ pp2[pos];
+ for (bit = 0; bit < 8; bit++)
+ if (xor & (1 << (7 - bit)))
+ break;
+
+ return pos * 8 + bit;
+}
+
/* Return prefix family type string. */
const char *
prefix_family_str (const struct prefix *p)
@@ -569,6 +609,20 @@ sockunion2hostprefix (const union sockunion *su)
return NULL;
}
+void
+prefix2sockunion (const struct prefix *p, union sockunion *su)
+{
+ memset (su, 0, sizeof (*su));
+
+ su->sa.sa_family = p->family;
+ if (p->family == AF_INET)
+ su->sin.sin_addr = p->u.prefix4;
+#ifdef HAVE_IPV6
+ if (p->family == AF_INET6)
+ memcpy (&su->sin6.sin6_addr, &p->u.prefix6, sizeof (struct in6_addr));
+#endif /* HAVE_IPV6 */
+}
+
int
prefix_blen (const struct prefix *p)
{
diff --git a/lib/prefix.h b/lib/prefix.h
index a7598b7e..f6259dee 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -156,12 +156,14 @@ extern int prefix2str (const struct prefix *, char *, int);
extern int prefix_match (const struct prefix *, const struct prefix *);
extern int prefix_same (const struct prefix *, const struct prefix *);
extern int prefix_cmp (const struct prefix *, const struct prefix *);
+extern int prefix_common_bits (const struct prefix *, const struct prefix *);
extern void prefix_copy (struct prefix *dest, const struct prefix *src);
extern void apply_mask (struct prefix *);
extern struct prefix *sockunion2prefix (const union sockunion *dest,
const union sockunion *mask);
extern struct prefix *sockunion2hostprefix (const union sockunion *);
+extern void prefix2sockunion (const struct prefix *, union sockunion *);
extern struct prefix_ipv4 *prefix_ipv4_new (void);
extern void prefix_ipv4_free (struct prefix_ipv4 *);
diff --git a/lib/route_types.awk b/lib/route_types.awk
deleted file mode 100644
index eb3d382a..00000000
--- a/lib/route_types.awk
+++ /dev/null
@@ -1,187 +0,0 @@
-# $Id$
-#
-# Scan a file of route-type definitions (see eg route_types.txt) and
-# generate a corresponding header file with:
-#
-# - enum of Zserv route-types
-# - redistribute strings for the various Quagga daemons
-#
-# See route_types.txt for the format.
-#
-#
-
-BEGIN {
- FS="[,]";
-
- # globals
- exitret = 0;
- tcount = 0;
-
- # formats for output
- ## the define format
- redist_def_fmt = "#define QUAGGA_REDIST_STR_%s \\\n";
- ## DEFUN/vty route-type argument
- redist_str_fmt = "\"(%s)\"\n";
- redist_help_def_fmt = "#define QUAGGA_REDIST_HELP_STR_%s";
- redist_help_str_fmt = " \\\n \"%s\\n\"";
-
- # header
- header = "/* Auto-generated from route_types.txt by " ARGV[0] ". */\n";
- header = header "/* Do not edit! */\n";
- header = header "\n#ifndef _QUAGGA_ROUTE_TYPES_H\n";
- header = header "#define _QUAGGA_ROUTE_TYPES_H\n";
- footer = "#endif /* _QUAGGA_ROUTE_TYPES_H */\n";
- printf ("%s\n", header);
-}
-
-# Chomp comment lines
-($0 ~ /^#/) {
- next;
-}
-
-# get rid of the commas, leading/trailling whitespace and
-# quotes
-{
- for (i = 1; i <= NF; i++) {
- #print "before:" $i;
- $i = gensub(/^[[:blank:]]*(.*)[,]*.*/, "\\1", "g",$i);
- $i = gensub(/^["](.*)["]$/, "\\1", "g", $i);
- #print "after :" $i;
- }
-}
-
-# 7 field format:
-# type cname daemon C 4 6 short help
-(NF >= 7) {
- #print "7", $1, $0;
-
- if ($1 in types) {
- print "error: attempt to redefine", $1;
- exitret = 1;
- exit exitret;
- }
-
- typesbynum[tcount] = $1;
- types[$1,"num"] = tcount++;
- types[$1,"cname"] = $2;
- types[$1,"daemon"] = $3;
- types[$1,"C"] = $4;
- types[$1,"4"] = strtonum($5);
- types[$1,"6"] = strtonum($6);
- types[$1,"shelp"] = $7;
-
- #print "num :", types[$1,"num"]
- #print "cname :", types[$1,"cname"]
- #print "daemon:", types[$1,"daemon"];
- #print "char :", types[$1,"C"];
-};
-
-# 2 field: type "long description"
-(NF == 2) {
- #print "2", $1, $2;
-
- if (!(($1 SUBSEP "num") in types)) {
- print "error: type", $1, "must be defined before help str";
- exitret = 2;
- exit exitret;
- }
-
- types[$1,"lhelp"] = $2;
-}
-
-END {
- if (exitret)
- exit exitret;
-
- # The enums
- # not yet...
- #printf("enum\n{\n");
- #for (i = 0; i < tcount; i++) {
- # type = typesbynum[i];
- # if (type != "" && types[type,"num"] == i)
- # printf (" %s,\n", type);
- #}
- #printf (" ZEBRA_ROUTE_MAX,\n};\n\n");
-
- # the redistribute defines
- for (i = 0; i < tcount; i++) {
- type = typesbynum[i];
-
- # must be a type, and must cross-check against recorded type
- if (type == "" || types[type,"num"] != i)
- continue;
-
- # ignore route types that can't be redistributed
- if (!(types[type,"4"] || types[type,"6"]))
- continue;
-
- # must have a daemon name
- if (!((type SUBSEP "daemon") in types))
- continue;
- if (!(daemon = types[type,"daemon"]))
- continue;
-
- # might have done this daemon already?
- if (daemon in seen_daemons)
- continue;
-
- cname = types[type,"cname"];
- all = all "|" cname;
- rstr = "";
- hstr = "";
-
- # add it to the others
- for (j = 0; j < tcount; j++) {
- # ignore self
- if (i == j)
- continue;
-
- type2 = typesbynum[j];
-
- # type2 must be valid, and self-check.
- if (type2 == "" || types[type2,"num"] != j)
- continue;
-
- # ignore different route types for the same daemon
- # (eg system/kernel/connected)
- if (types[type2,"daemon"] == daemon)
- continue;
-
- if ((types[type2,"4"] && types[type,"4"]) \
- || (types[type2,"6"] && types[type,"6"])) {
-
- if (rstr == "")
- rstr = types[type2,"cname"];
- else
- rstr = rstr "|" types[type2,"cname"];
-
- if ((type2 SUBSEP "lhelp") in types)
- hstr2 = types[type2,"lhelp"];
- else if ((type2 SUBSEP "shelp") in types)
- hstr2 = types[type2,"shelp"];
- else
- hstr2 = types[type2,"cname"];
-
- hstr = hstr sprintf(redist_help_str_fmt, hstr2);
- }
- }
-
- # dont double-process daemons.
- seen_daemons[daemon] = 1;
-
- printf("/* %s */\n", daemon);
- printf(redist_def_fmt, toupper(daemon));
- printf(redist_str_fmt, rstr);
- printf(redist_help_def_fmt, toupper(daemon));
- printf("%s", hstr);
- printf("\n\n");
- }
-
- #printf("#define QUAGGA_REDIST_STR_ALL %s\n",all);
-
-# for (i = 0; i < lcount; i++) {
-# if (mlists[i] != "")
-# printf (mlistformat "\n", mlists[i]);
-# }
- printf (footer);
-}
diff --git a/lib/route_types.pl b/lib/route_types.pl
new file mode 100755
index 00000000..e1595afc
--- /dev/null
+++ b/lib/route_types.pl
@@ -0,0 +1,199 @@
+#!/usr/bin/perl
+##
+## Scan a file of route-type definitions (see eg route_types.txt) and
+## generate a corresponding header file with:
+##
+## - enum of Zserv route-types
+## - redistribute strings for the various Quagga daemons
+##
+## See route_types.txt for the format.
+##
+##
+## Copyright (C) 2009 David Lamparter.
+## This file is part of GNU Zebra.
+##
+## GNU Zebra is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by the
+## Free Software Foundation; either version 2, or (at your option) any
+## later version.
+##
+## GNU Zebra is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with GNU Zebra; see the file COPYING. If not, write to the Free
+## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+##
+
+use strict;
+
+# input processing
+#
+my @protos;
+my %protodetail;
+
+my %daemons;
+
+while (<STDIN>) {
+ # skip comments and empty lines
+ next if (/^\s*(#|$)/);
+
+ # strip whitespace
+ chomp;
+ $_ =~ s/^\s*//;
+ $_ =~ s/\s*$//;
+
+ # match help strings
+ if (/^(ZEBRA_ROUTE_[^\s]+)\s*,\s*"(.*)"$/) {
+ $protodetail{$1}->{'longhelp'} = $2;
+ next;
+ }
+
+ $_ =~ s/\s*,\s*/,/g;
+
+ # else: 7-field line
+ my @f = split(/,/, $_);
+ unless (@f == 7) {
+ die "invalid input on route_types line $.\n";
+ }
+
+ my $proto = $f[0];
+ $f[3] = $1 if ($f[3] =~ /^'(.*)'$/);
+ $f[6] = $1 if ($f[6] =~ /^"(.*)"$/);
+
+ $protodetail{$proto} = {
+ "number" => scalar @protos,
+ "type" => $f[0],
+ "cname" => $f[1],
+ "daemon" => $f[2],
+ "char" => $f[3],
+ "ipv4" => int($f[4]),
+ "ipv6" => int($f[5]),
+ "shorthelp" => $f[6],
+ };
+ push @protos, $proto;
+ $daemons{$f[2]} = {
+ "ipv4" => int($f[4]),
+ "ipv6" => int($f[5])
+ } unless ($f[2] eq "NULL");
+}
+
+# output
+printf <<EOF, $ARGV[0];
+/* Auto-generated from route_types.txt by %s. */
+/* Do not edit! */
+
+#ifndef _QUAGGA_ROUTE_TYPES_H
+#define _QUAGGA_ROUTE_TYPES_H
+
+/* Zebra route's types. */
+EOF
+
+push @protos, "ZEBRA_ROUTE_MAX";
+my (@protosv4, @protosv6) = ((), ());
+for (my $c = 0; $c < @protos; $c++) {
+ my $p = $protos[$c];
+ printf "#define %-32s %d\n", $p, $c;
+ push @protosv4, $p if ($protodetail{$p}->{"ipv4"});
+ push @protosv6, $p if ($protodetail{$p}->{"ipv6"});
+}
+pop @protos;
+
+sub codelist {
+ my (@protos) = @_;
+ my (@lines) = ();
+ my $str = " \"Codes: ";
+ for my $p (@protos) {
+ my $s = sprintf("%s - %s, ",
+ $protodetail{$p}->{"char"},
+ $protodetail{$p}->{"shorthelp"});
+ if (length($str . $s) > 70) {
+ $str =~ s/ $//;
+ push @lines, $str . "%s\" \\\n";
+ $str = " \" ";
+ }
+ $str .= $s;
+ }
+ $str =~ s/ $//;
+ push @lines, $str . "%s\" \\\n";
+ push @lines, " \" > - selected route, * - FIB route%s%s\", \\\n";
+ my @nl = ();
+ for (my $c = 0; $c < @lines + 1; $c++) {
+ push @nl, "VTY_NEWLINE"
+ }
+ return join("", @lines) ." ". join(", ", @nl);
+}
+
+print "\n";
+printf "#define SHOW_ROUTE_V4_HEADER \\\n%s\n", codelist(@protosv4);
+printf "#define SHOW_ROUTE_V6_HEADER \\\n%s\n", codelist(@protosv6);
+print "\n";
+
+sub collect {
+ my ($daemon, $ipv4, $ipv6) = @_;
+ my (@names, @help) = ((), ());
+ for my $p (@protos) {
+ next if ($protodetail{$p}->{"daemon"} eq $daemon && $daemon ne "zebra");
+ next unless (($ipv4 && $protodetail{$p}->{"ipv4"})
+ || ($ipv6 && $protodetail{$p}->{"ipv6"}));
+ push @names, $protodetail{$p}->{"cname"};
+ push @help, " \"".$protodetail{$p}->{"longhelp"}."\\n\"";
+ }
+ return ("\"(" . join("|", @names) . ")\"", join(" \\\n", @help));
+}
+
+for my $daemon (sort keys %daemons) {
+ next unless ($daemons{$daemon}->{"ipv4"} || $daemons{$daemon}->{"ipv6"});
+ printf "/* %s */\n", $daemon;
+ if ($daemons{$daemon}->{"ipv4"} && $daemons{$daemon}->{"ipv6"}) {
+ my ($names, $help) = collect($daemon, 1, 1);
+ printf "#define QUAGGA_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
+ printf "#define QUAGGA_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+ ($names, $help) = collect($daemon, 1, 0);
+ printf "#define QUAGGA_IP_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
+ printf "#define QUAGGA_IP_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+ ($names, $help) = collect($daemon, 0, 1);
+ printf "#define QUAGGA_IP6_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
+ printf "#define QUAGGA_IP6_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+ } else {
+ my ($names, $help) = collect($daemon,
+ $daemons{$daemon}->{"ipv4"}, $daemons{$daemon}->{"ipv6"});
+ printf "#define QUAGGA_REDIST_STR_%s \\\n %s\n", uc $daemon, $names;
+ printf "#define QUAGGA_REDIST_HELP_STR_%s \\\n%s\n", uc $daemon, $help;
+ }
+ print "\n";
+}
+
+print <<EOF;
+
+#ifdef QUAGGA_DEFINE_DESC_TABLE
+
+struct zebra_desc_table
+{
+ unsigned int type;
+ const char *string;
+ char chr;
+};
+
+#define DESC_ENTRY(T,S,C) [(T)] = { (T), (S), (C) }
+static const struct zebra_desc_table route_types[] = {
+EOF
+
+for (my $c = 0; $c < @protos; $c++) {
+ my $p = $protos[$c];
+ printf " DESC_ENTRY\t(%s\t \"%s\",\t'%s' ),\n",
+ $p.",", $protodetail{$p}->{"cname"}, $protodetail{$p}->{"char"};
+}
+
+print <<EOF;
+};
+#undef DESC_ENTRY
+
+#endif /* QUAGGA_DEFINE_DESC_TABLE */
+
+#endif /* _QUAGGA_ROUTE_TYPES_H */
+EOF
+
diff --git a/lib/route_types.txt b/lib/route_types.txt
index e99cacde..dfa34d74 100644
--- a/lib/route_types.txt
+++ b/lib/route_types.txt
@@ -42,13 +42,13 @@
## type cname daemon C 4 6 short help
ZEBRA_ROUTE_SYSTEM, system, NULL, 'X', 0, 0, "Reserved"
-ZEBRA_ROUTE_KERNEL, kernel, zebra, 'K', 1, 1, NULL
-ZEBRA_ROUTE_CONNECT, connected, zebra, 'C', 1, 1, NULL
-ZEBRA_ROUTE_STATIC, static, zebra, 'S', 1, 1, NULL
+ZEBRA_ROUTE_KERNEL, kernel, zebra, 'K', 1, 1, "kernel route"
+ZEBRA_ROUTE_CONNECT, connected, zebra, 'C', 1, 1, "connected"
+ZEBRA_ROUTE_STATIC, static, zebra, 'S', 1, 1, "static"
ZEBRA_ROUTE_RIP, rip, ripd, 'R', 1, 0, "RIP"
ZEBRA_ROUTE_RIPNG, ripng, ripngd, 'R', 0, 1, "RIPng"
ZEBRA_ROUTE_OSPF, ospf, ospfd, 'O', 1, 0, "OSPF"
-ZEBRA_ROUTE_OSPF6, ospf6, ospf6d, 'O', 0, 1, "OSPF"
+ZEBRA_ROUTE_OSPF6, ospf6, ospf6d, 'O', 0, 1, "OSPFv6"
ZEBRA_ROUTE_ISIS, isis, isisd, 'I', 1, 1, "IS-IS"
ZEBRA_ROUTE_BGP, bgp, bgpd, 'B', 1, 1, "BGP"
# HSLS and OLSR both are AFI independent (so: 1, 1), however
@@ -56,8 +56,11 @@ ZEBRA_ROUTE_BGP, bgp, bgpd, 'B', 1, 1, "BGP"
# This at least makes it trivial for users of these protocols
# to 'switch on' redist support (direct numeric entry remaining
# possible).
-ZEBRA_ROUTE_HSLS, hsls, hslsd, 'H', 0, 0, "HSLS"
-ZEBRA_ROUTE_OLSR, olsr, oslrd, 'o', 0, 0, "OLSR"
+ZEBRA_ROUTE_HSLS, hsls, hslsd, 'h', 1, 1, "HSLS"
+ZEBRA_ROUTE_OLSR, olsr, olsrd, 'o', 1, 1, "OLSR"
+ZEBRA_ROUTE_BATMAN, batman, batman, 'b', 1, 1, "BATMAN"
+ZEBRA_ROUTE_DHCP, dhcp, dhcpc, 'D', 1, 0, "DHCP"
+ZEBRA_ROUTE_PIM, pim, pimd, 'P', 0, 0, "PIM-SSM"
## help strings
ZEBRA_ROUTE_SYSTEM, "Reserved route type, for internal use only"
@@ -72,3 +75,7 @@ ZEBRA_ROUTE_ISIS, "Intermediate System to Intermediate System (IS-IS)"
ZEBRA_ROUTE_BGP, "Border Gateway Protocol (BGP)"
ZEBRA_ROUTE_HSLS, "Hazy-Sighted Link State Protocol (HSLS)"
ZEBRA_ROUTE_OLSR, "Optimised Link State Routing (OLSR)"
+ZEBRA_ROUTE_BATMAN, "Better Approach To Mobile Ad-hoc Networking (BATMAN)"
+ZEBRA_ROUTE_DHCP, "Dynamic Host Configuration Protocol (DHCP)"
+ZEBRA_ROUTE_PIM, "Protocol Independent Multicast, Source Specific Mode (PIM-SSM)"
+
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 6a40f332..5de3bcfc 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -527,6 +527,40 @@ sockopt_ttl (int family, int sock, int ttl)
return 0;
}
+int
+sockopt_v6only (int family, int sock)
+{
+ int ret, on = 1;
+
+#ifdef HAVE_IPV6
+#ifdef IPV6_V6ONLY
+ if (family == AF_INET6)
+ {
+ ret = setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY,
+ (void *) &on, sizeof (int));
+ if (ret < 0)
+ {
+ zlog (NULL, LOG_WARNING, "can't set sockopt IPV6_V6ONLY "
+ "to socket %d", sock);
+ return -1;
+ }
+ return 0;
+ }
+#endif /* IPV6_V6ONLY */
+#endif /* HAVE_IPV6 */
+ return 0;
+}
+
+int
+sockopt_cork (int sock, int onoff)
+{
+#ifdef TCP_CORK
+ return setsockopt (sock, IPPROTO_TCP, TCP_CORK, &onoff, sizeof(onoff));
+#else
+ return 0;
+#endif
+}
+
/* If same family and same prefix return 1. */
int
sockunion_same (union sockunion *su1, union sockunion *su2)
diff --git a/lib/sockunion.h b/lib/sockunion.h
index 96b9a0d4..2e8ce2d0 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -99,9 +99,11 @@ extern int sockunion_accept (int sock, union sockunion *);
extern int sockunion_stream_socket (union sockunion *);
extern int sockopt_reuseaddr (int);
extern int sockopt_reuseport (int);
+extern int sockopt_v6only (int family, int sock);
extern int sockunion_bind (int sock, union sockunion *,
unsigned short, union sockunion *);
extern int sockopt_ttl (int family, int sock, int ttl);
+extern int sockopt_cork (int sock, int onoff);
extern int sockunion_socket (union sockunion *su);
extern const char *inet_sutop (union sockunion *su, char *str);
extern enum connect_result sockunion_connect (int fd, union sockunion *su,
diff --git a/lib/stream.c b/lib/stream.c
index 983330ff..bff74d7b 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -711,32 +711,6 @@ stream_read (struct stream *s, int fd, size_t size)
return nbytes;
}
-/* Read size from fd. */
-int
-stream_read_unblock (struct stream *s, int fd, size_t size)
-{
- int nbytes;
- int val;
-
- STREAM_VERIFY_SANE(s);
-
- if (STREAM_WRITEABLE (s) < size)
- {
- STREAM_BOUND_WARN (s, "put");
- return 0;
- }
-
- val = fcntl (fd, F_GETFL, 0);
- fcntl (fd, F_SETFL, val|O_NONBLOCK);
- nbytes = read (fd, s->data + s->endp, size);
- fcntl (fd, F_SETFL, val);
-
- if (nbytes > 0)
- s->endp += nbytes;
-
- return nbytes;
-}
-
ssize_t
stream_read_try(struct stream *s, int fd, size_t size)
{
diff --git a/lib/stream.h b/lib/stream.h
index 3e4ba7b4..486a3f93 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -181,10 +181,6 @@ extern u_int32_t stream_get_ipv4 (struct stream *);
Use stream_read_try instead. */
extern int stream_read (struct stream *, int, size_t);
-/* Deprecated: all file descriptors should already be non-blocking.
- Will be removed. Use stream_read_try instead. */
-extern int stream_read_unblock (struct stream *, int, size_t);
-
/* Read up to size bytes into the stream.
Return code:
>0: number of bytes read
diff --git a/lib/thread.c b/lib/thread.c
index e89af541..e083e8c7 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -20,8 +20,9 @@
*/
/* #define DEBUG */
-
+#include <errno.h>
#include <zebra.h>
+#include <sys/times.h>
#include "thread.h"
#include "memory.h"
@@ -31,8 +32,7 @@
#include "sigevent.h"
/* Recent absolute time of day */
-struct timeval recent_time;
-static struct timeval last_recent_time;
+static struct timeval recent_time;
/* Relative time, since startup */
static struct timeval relative_time;
static struct timeval relative_time_base;
@@ -94,54 +94,98 @@ timeval_elapsed (struct timeval a, struct timeval b)
}
#ifndef HAVE_CLOCK_MONOTONIC
+static unsigned long recent_clock_mark; /* Holds value of last call to times(2) */
+static unsigned long last_clock_mark;
+static unsigned long clocks_per_sec, msec_scale, usec_scale;
+
+static unsigned long quagga_times(void)
+{
+#if defined(GNU_LINUX)
+ unsigned long ret;
+
+ errno = 0;
+ ret = times(NULL); /* Linux can handle NULL */
+ /* Workaround broken syscall impl.
+ * A bugfix exists for the kernel, hopefully
+ * it will make it into 2.6.28
+ */
+ if (errno)
+ ret = (unsigned long) (-errno);
+ return ret;
+#else
+ struct tms dummy; /* Only return value is used */
+
+ return times(&dummy);
+#endif
+}
+
static void
quagga_gettimeofday_relative_adjust (void)
{
- struct timeval diff;
- if (timeval_cmp (recent_time, last_recent_time) < 0)
- {
- relative_time.tv_sec++;
- relative_time.tv_usec = 0;
- }
- else
- {
- diff = timeval_subtract (recent_time, last_recent_time);
- relative_time.tv_sec += diff.tv_sec;
- relative_time.tv_usec += diff.tv_usec;
- relative_time = timeval_adjust (relative_time);
- }
- last_recent_time = recent_time;
+ unsigned long diff;
+
+ diff = recent_clock_mark - last_clock_mark;
+ if (!diff)
+ return;
+ /* save mark for next calculation */
+ last_clock_mark = recent_clock_mark;
+
+ relative_time.tv_sec += diff / clocks_per_sec; /* convert to seconds */
+ relative_time.tv_usec += (diff % clocks_per_sec) * usec_scale; /* convert to useconds */
+ relative_time = timeval_adjust (relative_time);
}
#endif /* !HAVE_CLOCK_MONOTONIC */
+static int init_quagga_timers(void)
+{
+ int ret;
+
+ ret = gettimeofday (&recent_time, NULL);
+ relative_time_base = recent_time;
+#if !defined(HAVE_CLOCK_MONOTONIC)
+ clocks_per_sec = sysconf(_SC_CLK_TCK);
+ assert(clocks_per_sec != 0);
+
+ /* Precondition: 1000 % clocks_per_sec == 0 */
+ assert(1000 % clocks_per_sec == 0);
+ msec_scale = 1000 / clocks_per_sec;
+
+ /* Precondition: TIMER_SECOND_MICRO % clocks_per_sec == 0 */
+ assert(TIMER_SECOND_MICRO % clocks_per_sec == 0);
+ usec_scale = TIMER_SECOND_MICRO / clocks_per_sec;
+ recent_clock_mark = quagga_times();
+ last_clock_mark = recent_clock_mark;
+#endif
+ if (ret)
+ return ret;
+ timers_inited = 1;
+ return 0;
+}
+
/* gettimeofday wrapper, to keep recent_time updated */
static int
quagga_gettimeofday (struct timeval *tv)
{
int ret;
-
- assert (tv);
-
- if (!(ret = gettimeofday (&recent_time, NULL)))
- {
- /* init... */
- if (!timers_inited)
- {
- relative_time_base = last_recent_time = recent_time;
- timers_inited = 1;
- }
- /* avoid copy if user passed recent_time pointer.. */
- if (tv != &recent_time)
- *tv = recent_time;
- return 0;
- }
- return ret;
+
+ /* init... */
+ if (!timers_inited)
+ ret = init_quagga_timers();
+ else
+ ret = gettimeofday (&recent_time, NULL);
+ if (ret)
+ return ret;
+
+ /* avoid copy if user passed recent_time pointer.. */
+ if (tv != &recent_time)
+ *tv = recent_time;
+ return 0;
}
static int
quagga_get_relative (struct timeval *tv)
{
- int ret;
+ int ret = 0;
#ifdef HAVE_CLOCK_MONOTONIC
{
@@ -153,8 +197,12 @@ quagga_get_relative (struct timeval *tv)
}
}
#else /* !HAVE_CLOCK_MONOTONIC */
- if (!(ret = quagga_gettimeofday (&recent_time)))
- quagga_gettimeofday_relative_adjust();
+ /* init... */
+ if (!timers_inited)
+ ret = init_quagga_timers();
+
+ recent_clock_mark = quagga_times();
+ quagga_gettimeofday_relative_adjust();
#endif /* HAVE_CLOCK_MONOTONIC */
if (tv)
@@ -382,6 +430,89 @@ DEFUN(show_thread_cpu,
cpu_record_print(vty, filter);
return CMD_SUCCESS;
}
+
+static void
+cpu_record_hash_clear (struct hash_backet *bucket,
+ void *args)
+{
+ thread_type *filter = args;
+ struct cpu_thread_history *a = bucket->data;
+
+ a = bucket->data;
+ if ( !(a->types & *filter) )
+ return;
+
+ hash_release (cpu_record, bucket->data);
+}
+
+static void
+cpu_record_clear (thread_type filter)
+{
+ thread_type *tmp = &filter;
+ hash_iterate (cpu_record,
+ (void (*) (struct hash_backet*,void*)) cpu_record_hash_clear,
+ tmp);
+}
+
+DEFUN(clear_thread_cpu,
+ clear_thread_cpu_cmd,
+ "clear thread cpu [FILTER]",
+ "Clear stored data\n"
+ "Thread information\n"
+ "Thread CPU usage\n"
+ "Display filter (rwtexb)\n")
+{
+ int i = 0;
+ thread_type filter = (thread_type) -1U;
+
+ if (argc > 0)
+ {
+ filter = 0;
+ while (argv[0][i] != '\0')
+ {
+ switch ( argv[0][i] )
+ {
+ case 'r':
+ case 'R':
+ filter |= (1 << THREAD_READ);
+ break;
+ case 'w':
+ case 'W':
+ filter |= (1 << THREAD_WRITE);
+ break;
+ case 't':
+ case 'T':
+ filter |= (1 << THREAD_TIMER);
+ break;
+ case 'e':
+ case 'E':
+ filter |= (1 << THREAD_EVENT);
+ break;
+ case 'x':
+ case 'X':
+ filter |= (1 << THREAD_EXECUTE);
+ break;
+ case 'b':
+ case 'B':
+ filter |= (1 << THREAD_BACKGROUND);
+ break;
+ default:
+ break;
+ }
+ ++i;
+ }
+ if (filter == 0)
+ {
+ vty_out(vty, "Invalid filter \"%s\" specified,"
+ " must contain at least one of 'RWTEXB'%s",
+ argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ cpu_record_clear (filter);
+ return CMD_SUCCESS;
+}
/* List allocation and head/tail print out. */
static void
@@ -903,6 +1034,24 @@ thread_timer_process (struct thread_list *list, struct timeval *timenow)
return ready;
}
+/* process a list en masse, e.g. for event thread lists */
+static unsigned int
+thread_process (struct thread_list *list)
+{
+ struct thread *thread;
+ unsigned int ready = 0;
+
+ for (thread = list->head; thread; thread = thread->next)
+ {
+ thread_list_delete (list, thread);
+ thread->type = THREAD_READY;
+ thread_list_add (&thread->master->ready, thread);
+ ready++;
+ }
+ return ready;
+}
+
+
/* Fetch next ready thread. */
struct thread *
thread_fetch (struct thread_master *m, struct thread *fetch)
@@ -910,44 +1059,49 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
struct thread *thread;
fd_set readfd;
fd_set writefd;
- fd_set exceptfd;
- struct timeval timer_val;
+ struct timeval timer_val = { .tv_sec = 0, .tv_usec = 0 };
struct timeval timer_val_bg;
- struct timeval *timer_wait;
+ struct timeval *timer_wait = &timer_val;
struct timeval *timer_wait_bg;
while (1)
{
int num = 0;
- /* Signals are highest priority */
+ /* Signals pre-empt everything */
quagga_sigevent_process ();
- /* Normal event are the next highest priority. */
- if ((thread = thread_trim_head (&m->event)) != NULL)
- return thread_run (m, thread, fetch);
-
- /* If there are any ready threads from previous scheduler runs,
- * process top of them.
+ /* Drain the ready queue of already scheduled jobs, before scheduling
+ * more.
*/
if ((thread = thread_trim_head (&m->ready)) != NULL)
return thread_run (m, thread, fetch);
+ /* To be fair to all kinds of threads, and avoid starvation, we
+ * need to be careful to consider all thread types for scheduling
+ * in each quanta. I.e. we should not return early from here on.
+ */
+
+ /* Normal event are the next highest priority. */
+ thread_process (&m->event);
+
/* Structure copy. */
readfd = m->readfd;
writefd = m->writefd;
- exceptfd = m->exceptfd;
/* Calculate select wait timer if nothing else to do */
- quagga_get_relative (NULL);
- timer_wait = thread_timer_wait (&m->timer, &timer_val);
- timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg);
-
- if (timer_wait_bg &&
- (!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0)))
- timer_wait = timer_wait_bg;
+ if (m->ready.count == 0)
+ {
+ quagga_get_relative (NULL);
+ timer_wait = thread_timer_wait (&m->timer, &timer_val);
+ timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg);
+
+ if (timer_wait_bg &&
+ (!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0)))
+ timer_wait = timer_wait_bg;
+ }
- num = select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
+ num = select (FD_SETSIZE, &readfd, &writefd, NULL, timer_wait);
/* Signals should get quick treatment */
if (num < 0)
@@ -1028,14 +1182,6 @@ thread_getrusage (RUSAGE_T *r)
getrusage(RUSAGE_SELF, &(r->cpu));
#endif
r->real = relative_time;
-
-#ifdef HAVE_CLOCK_MONOTONIC
- /* quagga_get_relative() only updates recent_time if gettimeofday
- * based, not when using CLOCK_MONOTONIC. As we export recent_time
- * and guarantee to update it before threads are run...
- */
- quagga_gettimeofday(&recent_time);
-#endif /* HAVE_CLOCK_MONOTONIC */
}
/* We check thread consumed time. If the system has getrusage, we'll
diff --git a/lib/thread.h b/lib/thread.h
index b52bc541..7de679c8 100644
--- a/lib/thread.h
+++ b/lib/thread.h
@@ -1,5 +1,6 @@
/* Thread management routine header.
* Copyright (C) 1998 Kunihiro Ishiguro
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
*
* This file is part of GNU Zebra.
*
@@ -53,7 +54,6 @@ struct thread_master
struct thread_list background;
fd_set readfd;
fd_set writefd;
- fd_set exceptfd;
unsigned long alloc;
};
@@ -137,6 +137,12 @@ enum quagga_clkid {
thread = thread_add_timer (master, func, arg, time); \
} while (0)
+#define THREAD_TIMER_MSEC_ON(master,thread,func,arg,time) \
+ do { \
+ if (! thread) \
+ thread = thread_add_timer_msec (master, func, arg, time); \
+ } while (0)
+
#define THREAD_OFF(thread) \
do { \
if (thread) \
@@ -197,6 +203,7 @@ extern int thread_should_yield (struct thread *);
/* Internal libzebra exports */
extern void thread_getrusage (RUSAGE_T *);
extern struct cmd_element show_thread_cpu_cmd;
+extern struct cmd_element clear_thread_cpu_cmd;
/* replacements for the system gettimeofday(), clock_gettime() and
* time() functions, providing support for non-decrementing clock on
@@ -209,10 +216,6 @@ extern time_t quagga_time (time_t *);
extern unsigned long thread_consumed_time(RUSAGE_T *after, RUSAGE_T *before,
unsigned long *cpu_time_elapsed);
-/* Global variable containing a recent result from gettimeofday. This can
- be used instead of calling gettimeofday if a recent value is sufficient.
- This is guaranteed to be refreshed before a thread is called. */
-extern struct timeval recent_time;
/* Similar to recent_time, but a monotonically increasing time value */
extern struct timeval recent_relative_time (void);
#endif /* _ZEBRA_THREAD_H */
diff --git a/lib/vty.c b/lib/vty.c
index e4818eb6..a76fe2d1 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -250,7 +250,7 @@ vty_hello (struct vty *vty)
vty_out (vty, "MOTD file not found%s", VTY_NEWLINE);
}
else if (host.motd)
- vty_out (vty, host.motd);
+ vty_out (vty, "%s", host.motd);
}
/* Put out prompt and wait input from user. */
@@ -712,6 +712,7 @@ vty_end_config (struct vty *vty)
case KEYCHAIN_NODE:
case KEYCHAIN_KEY_NODE:
case MASC_NODE:
+ case PIM_NODE:
case VTY_NODE:
vty_config_unlock (vty);
vty->node = ENABLE_NODE;
@@ -1115,6 +1116,7 @@ vty_stop_input (struct vty *vty)
case KEYCHAIN_NODE:
case KEYCHAIN_KEY_NODE:
case MASC_NODE:
+ case PIM_NODE:
case VTY_NODE:
vty_config_unlock (vty);
vty->node = ENABLE_NODE;
@@ -1816,6 +1818,7 @@ vty_serv_sock_addrinfo (const char *hostname, unsigned short port)
if (sock < 0)
continue;
+ sockopt_v6only (ainfo->ai_family, sock);
sockopt_reuseaddr (sock);
sockopt_reuseport (sock);
@@ -1839,7 +1842,7 @@ vty_serv_sock_addrinfo (const char *hostname, unsigned short port)
freeaddrinfo (ainfo_save);
}
-#endif /* HAVE_IPV6 && ! NRL */
+#else /* HAVE_IPV6 && ! NRL */
/* Make vty server socket. */
static void
@@ -1905,6 +1908,7 @@ vty_serv_sock_family (const char* addr, unsigned short port, int family)
/* Add vty server event. */
vty_event (VTY_SERV, accept_sock, NULL);
}
+#endif /* HAVE_IPV6 && ! NRL */
#ifdef VTYSH
/* For sockaddr_un. */
@@ -2229,28 +2233,37 @@ vty_read_file (FILE *confp)
{
int ret;
struct vty *vty;
+ unsigned int line_num = 15;
vty = vty_new ();
- vty->fd = 0; /* stdout */
- vty->type = VTY_TERM;
+ vty->fd = dup(STDERR_FILENO); /* vty_close() will close this */
+ if (vty->fd < 0)
+ {
+ /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */
+ vty->fd = STDOUT_FILENO;
+ }
+ vty->type = VTY_FILE;
vty->node = CONFIG_NODE;
/* Execute configuration file */
- ret = config_from_file (vty, confp);
+ ret = config_from_file (vty, confp, &line_num);
+
+ /* Flush any previous errors before printing messages below */
+ buffer_flush_all (vty->obuf, vty->fd);
if ( !((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO)) )
{
switch (ret)
{
case CMD_ERR_AMBIGUOUS:
- fprintf (stderr, "Ambiguous command.\n");
+ fprintf (stderr, "*** Error reading config: Ambiguous command.\n");
break;
case CMD_ERR_NO_MATCH:
- fprintf (stderr, "There is no such command.\n");
+ fprintf (stderr, "*** Error reading config: There is no such command.\n");
break;
}
- fprintf (stderr, "Error occured during reading below line.\n%s\n",
- vty->buf);
+ fprintf (stderr, "*** Error occured processing line %u, below:\n%s\n",
+ line_num, vty->buf);
vty_close (vty);
exit (1);
}
diff --git a/lib/workqueue.c b/lib/workqueue.c
index 7c811edd..52b5f41c 100644
--- a/lib/workqueue.c
+++ b/lib/workqueue.c
@@ -341,7 +341,7 @@ work_queue_run (struct thread *thread)
stats:
-#define WQ_HYSTERIS_FACTOR 2
+#define WQ_HYSTERESIS_FACTOR 4
/* we yielded, check whether granularity should be reduced */
if (yielded && (cycles < wq->cycles.granularity))
@@ -349,17 +349,18 @@ stats:
wq->cycles.granularity = ((cycles > 0) ? cycles
: WORK_QUEUE_MIN_GRANULARITY);
}
-
- if (cycles >= (wq->cycles.granularity))
+ /* otherwise, should granularity increase? */
+ else if (cycles >= (wq->cycles.granularity))
{
if (cycles > wq->cycles.best)
wq->cycles.best = cycles;
- /* along with yielded check, provides hysteris for granularity */
- if (cycles > (wq->cycles.granularity * WQ_HYSTERIS_FACTOR * 2))
- wq->cycles.granularity *= WQ_HYSTERIS_FACTOR; /* quick ramp-up */
- else if (cycles > (wq->cycles.granularity * WQ_HYSTERIS_FACTOR))
- wq->cycles.granularity += WQ_HYSTERIS_FACTOR;
+ /* along with yielded check, provides hysteresis for granularity */
+ if (cycles > (wq->cycles.granularity * WQ_HYSTERESIS_FACTOR
+ * WQ_HYSTERESIS_FACTOR))
+ wq->cycles.granularity *= WQ_HYSTERESIS_FACTOR; /* quick ramp-up */
+ else if (cycles > (wq->cycles.granularity * WQ_HYSTERESIS_FACTOR))
+ wq->cycles.granularity += WQ_HYSTERESIS_FACTOR;
}
#undef WQ_HYSTERIS_FACTOR
diff --git a/lib/zclient.c b/lib/zclient.c
index d3d53227..8be9d040 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -32,6 +32,7 @@
#include "zclient.h"
#include "memory.h"
#include "table.h"
+#include "paths.h"
/* Zebra client events. */
enum event {ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT};
@@ -317,7 +318,7 @@ zclient_start (struct zclient *zclient)
#ifdef HAVE_TCP_ZEBRA
zclient->sock = zclient_socket ();
#else
- zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH);
+ zclient->sock = zclient_socket_un (path_state (ZEBRA_SERV_NAME));
#endif /* HAVE_TCP_ZEBRA */
if (zclient->sock < 0)
{
@@ -404,10 +405,10 @@ zclient_connect (struct thread *t)
* | IPv4 Nexthop address or Interface Index number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
- * Alternatively, if the flags field has ZEBRA_FLAG_BLACKHOLE or
- * ZEBRA_FLAG_REJECT is set then Nexthop count is set to 1, then _no_
+ * Alternatively, if the route is a blackhole route (indicated to zapi
+ * by ZAPI_MESSAGE_BLACKHOLE), then Nexthop count is set to 1 and _no_
* nexthop information is provided, and the message describes a prefix
- * to blackhole or reject route.
+ * to blackhole route.
*
* If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1
* byte value.
@@ -423,8 +424,18 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p,
{
int i;
int psize;
+ int blackhole = 0;
struct stream *s;
+ /* blackhole routes are sent as containing a single nexthop
+ * of type blackhole. */
+ if (CHECK_FLAG (api->message, ZAPI_MESSAGE_BLACKHOLE))
+ {
+ blackhole = 1;
+ UNSET_FLAG (api->message, ZAPI_MESSAGE_BLACKHOLE);
+ SET_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP);
+ }
+
/* Reset stream. */
s = zclient->obuf;
stream_reset (s);
@@ -442,17 +453,14 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p,
stream_write (s, (u_char *) & p->prefix, psize);
/* Nexthop, ifindex, distance and metric information. */
- if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
+ if (blackhole)
{
- if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
- {
- stream_putc (s, 1);
- stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
- /* XXX assert(api->nexthop_num == 0); */
- /* XXX assert(api->ifindex_num == 0); */
- }
- else
- stream_putc (s, api->nexthop_num + api->ifindex_num);
+ stream_putc (s, 1);
+ stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
+ }
+ else if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
+ {
+ stream_putc (s, api->nexthop_num + api->ifindex_num);
for (i = 0; i < api->nexthop_num; i++)
{
diff --git a/lib/zclient.h b/lib/zclient.h
index 21786ab8..7cce73f5 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -28,6 +28,9 @@
/* For input/output buffer to zebra. */
#define ZEBRA_MAX_PACKET_SIZ 4096
+/* Name of the zebra API socket */
+#define ZEBRA_SERV_NAME "zserv.api"
+
/* Zebra header size. */
#define ZEBRA_HEADER_SIZE 6
@@ -82,10 +85,11 @@ struct zclient
};
/* Zebra API message flag. */
-#define ZAPI_MESSAGE_NEXTHOP 0x01
-#define ZAPI_MESSAGE_IFINDEX 0x02
-#define ZAPI_MESSAGE_DISTANCE 0x04
-#define ZAPI_MESSAGE_METRIC 0x08
+#define ZAPI_MESSAGE_NEXTHOP 0x01
+#define ZAPI_MESSAGE_IFINDEX 0x02
+#define ZAPI_MESSAGE_DISTANCE 0x04
+#define ZAPI_MESSAGE_METRIC 0x08
+#define ZAPI_MESSAGE_BLACKHOLE 0x10 /* only for zapi_ipv4_route */
/* Zserv protocol message header */
struct zserv_header
diff --git a/lib/zebra.h b/lib/zebra.h
index 2dc84514..63eb373a 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -1,5 +1,6 @@
/* Zebra common header.
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
+ Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
This file is part of GNU Zebra.
@@ -421,7 +422,8 @@ struct in_pktinfo
#define ZEBRA_ROUTER_ID_ADD 20
#define ZEBRA_ROUTER_ID_DELETE 21
#define ZEBRA_ROUTER_ID_UPDATE 22
-#define ZEBRA_MESSAGE_MAX 23
+#define ZEBRA_IPV4_NEXTHOP_LOOKUP_V2 23
+#define ZEBRA_MESSAGE_MAX 24
/* Marker value used in new Zserv, in the byte location corresponding
* the command value in the old zserv header. To allow old and new
@@ -429,19 +431,8 @@ struct in_pktinfo
*/
#define ZEBRA_HEADER_MARKER 255
-/* Zebra route's types. */
-#define ZEBRA_ROUTE_SYSTEM 0
-#define ZEBRA_ROUTE_KERNEL 1
-#define ZEBRA_ROUTE_CONNECT 2
-#define ZEBRA_ROUTE_STATIC 3
-#define ZEBRA_ROUTE_RIP 4
-#define ZEBRA_ROUTE_RIPNG 5
-#define ZEBRA_ROUTE_OSPF 6
-#define ZEBRA_ROUTE_OSPF6 7
-#define ZEBRA_ROUTE_ISIS 8
-#define ZEBRA_ROUTE_BGP 9
-#define ZEBRA_ROUTE_HSLS 10
-#define ZEBRA_ROUTE_MAX 11
+/* Zebra route's types are defined in route_types.h */
+#include "route_types.h"
/* Note: whenever a new route-type or zserv-command is added the
* corresponding {command,route}_types[] table in lib/log.c MUST be
@@ -455,6 +446,10 @@ extern char zebra_route_char(unsigned int route_type);
* e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
/* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
extern int proto_name2num(const char *s);
+/* Map redistribute X argument to protocol number.
+ * unlike proto_name2num, this accepts shorthands and takes
+ * an AFI value to restrict input */
+extern int proto_redistnum(int afi, const char *s);
extern const char *zserv_command_string (unsigned int command);
@@ -474,12 +469,12 @@ extern const char *zserv_command_string (unsigned int command);
/* Zebra message flags */
#define ZEBRA_FLAG_INTERNAL 0x01
#define ZEBRA_FLAG_SELFROUTE 0x02
-#define ZEBRA_FLAG_BLACKHOLE 0x04
+/* 0x04 was: FLAG_BLACKHOLE */
#define ZEBRA_FLAG_IBGP 0x08
#define ZEBRA_FLAG_SELECTED 0x10
#define ZEBRA_FLAG_CHANGED 0x20
#define ZEBRA_FLAG_STATIC 0x40
-#define ZEBRA_FLAG_REJECT 0x80
+/* 0x80 was: FLAG_REJECT */
/* Zebra nexthop flags. */
#define ZEBRA_NEXTHOP_IFINDEX 1
@@ -538,43 +533,4 @@ typedef u_int8_t safi_t;
typedef u_int16_t zebra_size_t;
typedef u_int16_t zebra_command_t;
-/* FIFO -- first in first out structure and macros. */
-struct fifo
-{
- struct fifo *next;
- struct fifo *prev;
-};
-
-#define FIFO_INIT(F) \
- do { \
- struct fifo *Xfifo = (struct fifo *)(F); \
- Xfifo->next = Xfifo->prev = Xfifo; \
- } while (0)
-
-#define FIFO_ADD(F,N) \
- do { \
- struct fifo *Xfifo = (struct fifo *)(F); \
- struct fifo *Xnode = (struct fifo *)(N); \
- Xnode->next = Xfifo; \
- Xnode->prev = Xfifo->prev; \
- Xfifo->prev = Xfifo->prev->next = Xnode; \
- } while (0)
-
-#define FIFO_DEL(N) \
- do { \
- struct fifo *Xnode = (struct fifo *)(N); \
- Xnode->prev->next = Xnode->next; \
- Xnode->next->prev = Xnode->prev; \
- } while (0)
-
-#define FIFO_HEAD(F) \
- ((((struct fifo *)(F))->next == (struct fifo *)(F)) \
- ? NULL : (F)->next)
-
-#define FIFO_EMPTY(F) \
- (((struct fifo *)(F))->next == (struct fifo *)(F))
-
-#define FIFO_TOP(F) \
- (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next)
-
#endif /* _ZEBRA_H */
diff --git a/m4/.gitignore b/m4/.gitignore
index 3f3bd0a7..69a70a54 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -4,4 +4,5 @@ Makefile.in
.arch-ids
*~
*.loT
+*.m4
diff --git a/mkinstalldirs b/mkinstalldirs
deleted file mode 100755
index 86e2b5ed..00000000
--- a/mkinstalldirs
+++ /dev/null
@@ -1,101 +0,0 @@
-#! /bin/sh
-# mkinstalldirs --- make directory hierarchy
-# Author: Noah Friedman <friedman@prep.ai.mit.edu>
-# Created: 1993-05-16
-# Public domain
-
-# $Id: mkinstalldirs,v 1.2 2003/02/17 23:54:05 paul Exp $
-
-errstatus=0
-dirmode=""
-
-usage="\
-Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..."
-
-# process command line arguments
-while test $# -gt 0 ; do
- case "${1}" in
- -h | --help | --h* ) # -h for help
- echo "${usage}" 1>&2; exit 0 ;;
- -m ) # -m PERM arg
- shift
- test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
- dirmode="${1}"
- shift ;;
- -- ) shift; break ;; # stop option processing
- -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option
- * ) break ;; # first non-opt arg
- esac
-done
-
-for file
-do
- if test -d "$file"; then
- shift
- else
- break
- fi
-done
-
-case $# in
-0) exit 0 ;;
-esac
-
-case $dirmode in
-'')
- if mkdir -p -- . 2>/dev/null; then
- echo "mkdir -p -- $*"
- exec mkdir -p -- "$@"
- fi ;;
-*)
- if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
- echo "mkdir -m $dirmode -p -- $*"
- exec mkdir -m "$dirmode" -p -- "$@"
- fi ;;
-esac
-
-for file
-do
- set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
- shift
-
- pathcomp=
- for d
- do
- pathcomp="$pathcomp$d"
- case "$pathcomp" in
- -* ) pathcomp=./$pathcomp ;;
- esac
-
- if test ! -d "$pathcomp"; then
- echo "mkdir $pathcomp"
-
- mkdir "$pathcomp" || lasterr=$?
-
- if test ! -d "$pathcomp"; then
- errstatus=$lasterr
- else
- if test ! -z "$dirmode"; then
- echo "chmod $dirmode $pathcomp"
-
- lasterr=""
- chmod "$dirmode" "$pathcomp" || lasterr=$?
-
- if test ! -z "$lasterr"; then
- errstatus=$lasterr
- fi
- fi
- fi
- fi
-
- pathcomp="$pathcomp/"
- done
-done
-
-exit $errstatus
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 3
-# End:
-# mkinstalldirs ends here
diff --git a/ospf6d/Makefile.am b/ospf6d/Makefile.am
index 01bc6fe0..eeed1652 100644
--- a/ospf6d/Makefile.am
+++ b/ospf6d/Makefile.am
@@ -1,7 +1,6 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
INSTALL_SDATA=@INSTALL@ -m 600
AM_CFLAGS = $(PICFLAGS)
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index 685b147c..d6c1517e 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -616,27 +616,16 @@ ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix)
DEFUN (ospf6_redistribute,
ospf6_redistribute_cmd,
- "redistribute (static|kernel|connected|ripng|bgp)",
+ "redistribute " QUAGGA_REDIST_STR_OSPF6D,
"Redistribute\n"
- "Static route\n"
- "Kernel route\n"
- "Connected route\n"
- "RIPng route\n"
- "BGP route\n"
+ QUAGGA_REDIST_HELP_STR_OSPF6D
)
{
- int type = 0;
-
- if (strncmp (argv[0], "sta", 3) == 0)
- type = ZEBRA_ROUTE_STATIC;
- else if (strncmp (argv[0], "ker", 3) == 0)
- type = ZEBRA_ROUTE_KERNEL;
- else if (strncmp (argv[0], "con", 3) == 0)
- type = ZEBRA_ROUTE_CONNECT;
- else if (strncmp (argv[0], "rip", 3) == 0)
- type = ZEBRA_ROUTE_RIPNG;
- else if (strncmp (argv[0], "bgp", 3) == 0)
- type = ZEBRA_ROUTE_BGP;
+ int type;
+
+ type = proto_redistnum(AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
+ return CMD_WARNING;
ospf6_asbr_redistribute_unset (type);
ospf6_asbr_routemap_unset (type);
@@ -646,29 +635,18 @@ DEFUN (ospf6_redistribute,
DEFUN (ospf6_redistribute_routemap,
ospf6_redistribute_routemap_cmd,
- "redistribute (static|kernel|connected|ripng|bgp) route-map WORD",
+ "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
"Redistribute\n"
- "Static routes\n"
- "Kernel route\n"
- "Connected route\n"
- "RIPng route\n"
- "BGP route\n"
+ QUAGGA_REDIST_HELP_STR_OSPF6D
"Route map reference\n"
"Route map name\n"
)
{
- int type = 0;
-
- if (strncmp (argv[0], "sta", 3) == 0)
- type = ZEBRA_ROUTE_STATIC;
- else if (strncmp (argv[0], "ker", 3) == 0)
- type = ZEBRA_ROUTE_KERNEL;
- else if (strncmp (argv[0], "con", 3) == 0)
- type = ZEBRA_ROUTE_CONNECT;
- else if (strncmp (argv[0], "rip", 3) == 0)
- type = ZEBRA_ROUTE_RIPNG;
- else if (strncmp (argv[0], "bgp", 3) == 0)
- type = ZEBRA_ROUTE_BGP;
+ int type;
+
+ type = proto_redistnum(AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
+ return CMD_WARNING;
ospf6_asbr_redistribute_unset (type);
ospf6_asbr_routemap_set (type, argv[1]);
@@ -678,28 +656,17 @@ DEFUN (ospf6_redistribute_routemap,
DEFUN (no_ospf6_redistribute,
no_ospf6_redistribute_cmd,
- "no redistribute (static|kernel|connected|ripng|bgp)",
+ "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
NO_STR
"Redistribute\n"
- "Static route\n"
- "Kernel route\n"
- "Connected route\n"
- "RIPng route\n"
- "BGP route\n"
+ QUAGGA_REDIST_HELP_STR_OSPF6D
)
{
- int type = 0;
-
- if (strncmp (argv[0], "sta", 3) == 0)
- type = ZEBRA_ROUTE_STATIC;
- else if (strncmp (argv[0], "ker", 3) == 0)
- type = ZEBRA_ROUTE_KERNEL;
- else if (strncmp (argv[0], "con", 3) == 0)
- type = ZEBRA_ROUTE_CONNECT;
- else if (strncmp (argv[0], "rip", 3) == 0)
- type = ZEBRA_ROUTE_RIPNG;
- else if (strncmp (argv[0], "bgp", 3) == 0)
- type = ZEBRA_ROUTE_BGP;
+ int type;
+
+ type = proto_redistnum(AFI_IP6, argv[0]);
+ if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
+ return CMD_WARNING;
ospf6_asbr_redistribute_unset (type);
ospf6_asbr_routemap_unset (type);
diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c
index 777bc7c9..cb347451 100644
--- a/ospf6d/ospf6_interface.c
+++ b/ospf6d/ospf6_interface.c
@@ -1394,13 +1394,17 @@ DEFUN (ipv6_ospf6_advertise_prefix_list,
oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
ospf6_interface_connected_route_update (oi->interface);
- OSPF6_LINK_LSA_SCHEDULE (oi);
- if (oi->state == OSPF6_INTERFACE_DR)
+
+ if (oi->area)
{
- OSPF6_NETWORK_LSA_SCHEDULE (oi);
- OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
+ OSPF6_LINK_LSA_SCHEDULE (oi);
+ if (oi->state == OSPF6_INTERFACE_DR)
+ {
+ OSPF6_NETWORK_LSA_SCHEDULE (oi);
+ OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
+ }
+ OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
}
- OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
return CMD_SUCCESS;
}
@@ -1433,13 +1437,17 @@ DEFUN (no_ipv6_ospf6_advertise_prefix_list,
}
ospf6_interface_connected_route_update (oi->interface);
- OSPF6_LINK_LSA_SCHEDULE (oi);
- if (oi->state == OSPF6_INTERFACE_DR)
+
+ if (oi->area)
{
- OSPF6_NETWORK_LSA_SCHEDULE (oi);
- OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
+ OSPF6_LINK_LSA_SCHEDULE (oi);
+ if (oi->state == OSPF6_INTERFACE_DR)
+ {
+ OSPF6_NETWORK_LSA_SCHEDULE (oi);
+ OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
+ }
+ OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
}
- OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
return CMD_SUCCESS;
}
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index a7a96a1f..c33fe9f2 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -34,11 +34,14 @@
#include "plist.h"
#include "privs.h"
#include "sigevent.h"
+#include "paths.h"
#include "ospf6d.h"
/* Default configuration file name for ospf6d. */
-#define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
+#define OSPF6_CONFIG_NAME "ospf6d.conf"
+#define OSPF6_PID_NAME "ospf6d.pid"
+#define OSPF6_VTY_NAME "ospf6d.vty"
/* Default port values. */
#define OSPF6_VTY_PORT 2606
@@ -70,6 +73,7 @@ struct zebra_privs_t ospf6d_privs =
struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
{ "config_file", required_argument, NULL, 'f'},
{ "pid_file", required_argument, NULL, 'i'},
{ "vty_addr", required_argument, NULL, 'A'},
@@ -83,7 +87,7 @@ struct option longopts[] =
};
/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR OSPF6_DEFAULT_CONFIG;
+char config_default[MAXPATHLEN];
/* ospf6d program name. */
char *progname;
@@ -94,8 +98,11 @@ int daemon_mode = 0;
/* Master of threads. */
struct thread_master *master;
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
+
/* Process ID saved for use by init system */
-const char *pid_file = PATH_OSPF6D_PID;
+const char *pid_file = pid_file_default;
/* Help information display. */
static void
@@ -108,6 +115,7 @@ usage (char *progname, int status)
printf ("Usage : %s [OPTION...]\n\n\
Daemon which manages OSPF version 3.\n\n\
-d, --daemon Runs in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
-f, --config_file Set configuration file name\n\
-i, --pid_file Set process identifier file name\n\
-A, --vty_addr Set vty's bind address\n\
@@ -197,7 +205,7 @@ main (int argc, char *argv[], char *envp[])
/* Command line argument treatment. */
while (1)
{
- opt = getopt_long (argc, argv, "df:i:hp:A:P:u:g:vC", longopts, 0);
+ opt = getopt_long (argc, argv, "dN:f:i:hp:A:P:u:g:vC", longopts, 0);
if (opt == EOF)
break;
@@ -209,6 +217,9 @@ main (int argc, char *argv[], char *envp[])
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'f':
config_file = optarg;
break;
@@ -252,6 +263,9 @@ main (int argc, char *argv[], char *envp[])
}
}
+ strcpy (config_default, path_config (OSPF6_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (OSPF6_PID_NAME));
+
/* thread master */
master = thread_master_create ();
@@ -294,7 +308,7 @@ main (int argc, char *argv[], char *envp[])
/* Make ospf6 vty socket. */
if (!vty_port)
vty_port = OSPF6_VTY_PORT;
- vty_serv_sock (vty_addr, vty_port, OSPF6_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (OSPF6_VTY_NAME));
/* Print start message */
zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d",
diff --git a/ospfd/Makefile.am b/ospfd/Makefile.am
index 2e4d5c8e..bed90d7b 100644
--- a/ospfd/Makefile.am
+++ b/ospfd/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\"
+DEFS = @DEFS@ $(LOCAL_OPTS)
INSTALL_SDATA=@INSTALL@ -m 600
lib_LTLIBRARIES = libospf.la
diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c
index 7e32195b..def55f10 100644
--- a/ospfd/ospf_abr.c
+++ b/ospfd/ospf_abr.c
@@ -614,15 +614,6 @@ set_metric (struct ospf_lsa *lsa, u_int32_t metric)
memcpy(header->metric, mp, 3);
}
-static int
-ospf_abr_check_nssa_range (struct prefix_ipv4 *p, u_int32_t cost,
- struct ospf_area *area)
-{
- /* The Type-7 is tested against the aggregated prefix and forwarded
- for lsa installation and flooding */
- return 0;
-}
-
/* ospf_abr_translate_nssa */
static int
ospf_abr_translate_nssa (struct ospf_area *area, struct ospf_lsa *lsa)
@@ -1578,42 +1569,6 @@ ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */
}
static void
-ospf_abr_announce_nssa_defaults (struct ospf *ospf) /* By ABR-Translator */
-{
- struct listnode *node;
- struct ospf_area *area;
-
- if (! IS_OSPF_ABR (ospf))
- return;
-
- if (IS_DEBUG_OSPF_NSSA)
- zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
-
- for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
- {
- if (IS_DEBUG_OSPF_NSSA)
- zlog_debug ("ospf_abr_announce_nssa_defaults(): looking at area %s",
- inet_ntoa (area->area_id));
-
- if (area->external_routing != OSPF_AREA_NSSA)
- continue;
-
- if (OSPF_IS_AREA_BACKBONE (area))
- continue; /* Sanity Check */
-
- /* if (!TranslatorRole continue V 1.0 look for "always" conf */
- if (area->NSSATranslatorState)
- {
- if (IS_DEBUG_OSPF_NSSA)
- zlog_debug ("ospf_abr_announce_nssa_defaults(): "
- "announcing 0.0.0.0/0 to this nssa");
- /* ospf_abr_announce_nssa_asbr_to_as (&p, area->default_cost, area); */
- /*ospf_abr_announce_network_to_area (&p, area->default_cost, area);*/
- }
- }
-}
-
-static void
ospf_abr_announce_stub_defaults (struct ospf *ospf)
{
struct listnode *node;
diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c
index 5d0cae42..c06f0178 100644
--- a/ospfd/ospf_ase.c
+++ b/ospfd/ospf_ase.c
@@ -31,6 +31,7 @@
#include "table.h"
#include "vty.h"
#include "log.h"
+#include "workqueue.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
@@ -130,18 +131,6 @@ ospf_find_asbr_route_through_area (struct route_table *rtrs,
return NULL;
}
-static void
-ospf_ase_complete_direct_routes (struct ospf_route *ro, struct in_addr nexthop)
-{
- struct listnode *node;
- struct ospf_path *op;
- struct interface *ifp;
-
- for (ALL_LIST_ELEMENTS_RO (ro->paths, node, op))
- if (op->nexthop.s_addr == 0)
- op->nexthop.s_addr = nexthop.s_addr;
-}
-
static int
ospf_ase_forward_address_check (struct ospf *ospf, struct in_addr fwd_addr)
{
@@ -284,8 +273,8 @@ ospf_ase_calculate_new_route (struct ospf_lsa *lsa,
#define OSPF_ASE_CALC_INTERVAL 1
-int
-ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa)
+static int
+ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa *lsa)
{
u_int32_t metric;
struct as_external_lsa *al;
@@ -451,8 +440,8 @@ ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa)
/* if there is a Intra/Inter area route to the N
do not install external route */
- if (rn = route_node_lookup (ospf->new_table,
- (struct prefix *) &p))
+ if ((rn = route_node_lookup (ospf->new_table,
+ (struct prefix *) &p)))
{
route_unlock_node(rn);
if (rn->info == NULL)
@@ -463,8 +452,8 @@ ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa)
}
/* Find a route to the same dest */
/* If there is no route, create new one. */
- if (rn = route_node_lookup (ospf->new_external_route,
- (struct prefix *) &p))
+ if ((rn = route_node_lookup (ospf->new_external_route,
+ (struct prefix *) &p)))
route_unlock_node(rn);
if (!rn || (or = rn->info) == NULL)
@@ -475,8 +464,6 @@ ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa)
ospf_route_add (ospf->new_external_route, &p, new, asbr_route);
- if (al->e[0].fwd_addr.s_addr)
- ospf_ase_complete_direct_routes (new, al->e[0].fwd_addr);
return 0;
}
else
@@ -513,8 +500,7 @@ ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa)
if (IS_DEBUG_OSPF (lsa, LSA))
zlog_debug ("Route[External]: New route is better");
ospf_route_subst (rn, new, asbr_route);
- if (al->e[0].fwd_addr.s_addr)
- ospf_ase_complete_direct_routes (new, al->e[0].fwd_addr);
+
or = new;
new = NULL;
}
@@ -531,8 +517,6 @@ ospf_ase_calculate_route (struct ospf *ospf, struct ospf_lsa * lsa)
if (IS_DEBUG_OSPF (lsa, LSA))
zlog_debug ("Route[External]: Routes are equal");
ospf_route_copy_nexthops (or, asbr_route->paths);
- if (al->e[0].fwd_addr.s_addr)
- ospf_ase_complete_direct_routes (or, al->e[0].fwd_addr);
}
}
/* Make sure setting newly calculated ASBR route.*/
@@ -629,6 +613,50 @@ ospf_ase_compare_tables (struct route_table *new_external_route,
return 0;
}
+static int ospf_ase_calculate_timer (struct thread *);
+
+static void ospf_ase_calc_completion (struct work_queue *wq)
+{
+ struct ospf *ospf = wq->spec.data;
+
+ /* Compare old and new external routing table and install the
+ difference info zebra/kernel */
+ ospf_ase_compare_tables (ospf->new_external_route,
+ ospf->old_external_route);
+
+ /* Delete old external routing table */
+ ospf_route_table_free (ospf->old_external_route);
+ ospf->old_external_route = ospf->new_external_route;
+ ospf->new_external_route = route_table_init ();
+
+ /* another timer fired since, so another run might be needed */
+ if (ospf->ase_calc && !ospf->t_ase_calc)
+ ospf->t_ase_calc = thread_add_timer (master, ospf_ase_calculate_timer,
+ ospf, 0);
+}
+
+static wq_item_status
+ospf_ase_calc_process (struct work_queue *wq, void *data)
+{
+ struct ospf_lsa *lsa = data;
+ ospf_ase_calculate_route (wq->spec.data, lsa);
+ ospf_lsa_unlock (&lsa);
+ return WQ_SUCCESS;
+}
+
+static void
+ospf_ase_calc_queue_init (struct ospf *ospf)
+{
+ ospf->ase_calc_queue = work_queue_new (master, "ase_calc_queue");
+
+ ospf->ase_calc_queue->spec.workfunc = &ospf_ase_calc_process;
+ ospf->ase_calc_queue->spec.completion_func = &ospf_ase_calc_completion;
+
+ ospf->ase_calc_queue->spec.data = ospf;
+ ospf->ase_calc_queue->spec.max_retries = 0;
+ ospf->ase_calc_queue->spec.hold = 0;
+}
+
static int
ospf_ase_calculate_timer (struct thread *t)
{
@@ -645,9 +673,12 @@ ospf_ase_calculate_timer (struct thread *t)
{
ospf->ase_calc = 0;
+ if (!ospf->ase_calc_queue)
+ ospf_ase_calc_queue_init (ospf);
+
/* Calculate external route for each AS-external-LSA */
LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
- ospf_ase_calculate_route (ospf, lsa);
+ work_queue_add (ospf->ase_calc_queue, ospf_lsa_lock (lsa));
/* This version simple adds to the table all NSSA areas */
if (ospf->anyNSSA)
@@ -659,39 +690,22 @@ ospf_ase_calculate_timer (struct thread *t)
if (area->external_routing == OSPF_AREA_NSSA)
LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
- ospf_ase_calculate_route (ospf, lsa);
+ work_queue_add (ospf->ase_calc_queue, ospf_lsa_lock (lsa));
}
/* kevinm: And add the NSSA routes in ospf_top */
LSDB_LOOP (NSSA_LSDB (ospf),rn,lsa)
- ospf_ase_calculate_route(ospf,lsa);
-
- /* Compare old and new external routing table and install the
- difference info zebra/kernel */
- ospf_ase_compare_tables (ospf->new_external_route,
- ospf->old_external_route);
-
- /* Delete old external routing table */
- ospf_route_table_free (ospf->old_external_route);
- ospf->old_external_route = ospf->new_external_route;
- ospf->new_external_route = route_table_init ();
+ work_queue_add (ospf->ase_calc_queue, ospf_lsa_lock (lsa));
}
return 0;
}
void
-ospf_ase_calculate_schedule (struct ospf *ospf)
+ospf_ase_calculate_timer_add (struct ospf *ospf)
{
if (ospf == NULL)
return;
ospf->ase_calc = 1;
-}
-
-void
-ospf_ase_calculate_timer_add (struct ospf *ospf)
-{
- if (ospf == NULL)
- return;
if (! ospf->t_ase_calc)
ospf->t_ase_calc = thread_add_timer (master, ospf_ase_calculate_timer,
diff --git a/ospfd/ospf_ase.h b/ospfd/ospf_ase.h
index e6a1b2fb..646a38c0 100644
--- a/ospfd/ospf_ase.h
+++ b/ospfd/ospf_ase.h
@@ -34,8 +34,6 @@ extern struct ospf_route *ospf_find_asbr_route_through_area (struct
struct ospf_area
*);
-extern int ospf_ase_calculate_route (struct ospf *, struct ospf_lsa *);
-extern void ospf_ase_calculate_schedule (struct ospf *);
extern void ospf_ase_calculate_timer_add (struct ospf *);
extern void ospf_ase_external_lsas_finish (struct route_table *);
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 5c64ba29..33a83b4d 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -211,7 +211,9 @@ ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
}
else
return oi;
-
+
+ ospf_lsa_pos_set(-1,-1, oi); /* delete position in router LSA */
+
/* Set zebra interface pointer. */
oi->ifp = ifp;
oi->address = p;
@@ -395,6 +397,29 @@ ospf_if_exists (struct ospf_interface *oic)
return NULL;
}
+/* Lookup OSPF interface by router LSA posistion */
+struct ospf_interface *
+ospf_if_lookup_by_lsa_pos (struct ospf_area *area, int lsa_pos)
+{
+ struct listnode *node;
+ struct ospf_interface *oi;
+
+ for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
+ {
+ if (lsa_pos >= oi->lsa_pos_beg && lsa_pos < oi->lsa_pos_end)
+ return oi;
+ }
+ return NULL;
+}
+
+/* Set OSPF interface position in router LSA */
+void
+ospf_lsa_pos_set(int pos_beg, int pos_end, struct ospf_interface *oi)
+{
+ oi->lsa_pos_beg = pos_beg;
+ oi->lsa_pos_end = pos_end;
+}
+
struct ospf_interface *
ospf_if_lookup_by_local_addr (struct ospf *ospf,
struct interface *ifp, struct in_addr address)
@@ -477,6 +502,20 @@ ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src,
return match;
}
+
+struct ospf_interface *
+ospf_if_lookup_by_ifindex(struct ospf_area *area, unsigned int ifindex)
+{
+ struct listnode *node;
+ struct ospf_interface *oi;
+
+ for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
+ {
+ if (oi->ifp->ifindex == ifindex)
+ return oi;
+ }
+ return NULL;
+}
void
ospf_if_stream_set (struct ospf_interface *oi)
@@ -801,6 +840,7 @@ ospf_if_down (struct ospf_interface *oi)
return 0;
OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
+ ospf_lsa_pos_set(-1, -1, oi); /* delete position in router LSA */
/* Shutdown packet reception and sending */
ospf_if_stream_unset (oi);
diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h
index 18b98cd0..82bf31a5 100644
--- a/ospfd/ospf_interface.h
+++ b/ospfd/ospf_interface.h
@@ -47,6 +47,7 @@ struct ospf_if_params
DECLARE_IF_PARAM (u_int32_t, retransmit_interval); /* Retransmission Interval */
DECLARE_IF_PARAM (u_char, passive_interface); /* OSPF Interface is passive: no sending or receiving (no need to join multicast groups) */
DECLARE_IF_PARAM (u_char, priority); /* OSPF Interface priority */
+ DECLARE_IF_PARAM (struct in_addr, if_area); /* Enable OSPF on this interface with area if_area */
DECLARE_IF_PARAM (u_char, type); /* type of interface */
#define OSPF_IF_ACTIVE 0
#define OSPF_IF_PASSIVE 1
@@ -124,6 +125,10 @@ struct ospf_interface
/* OSPF Area. */
struct ospf_area *area;
+/* Position range in Router LSA */
+ int lsa_pos_beg; /* inclusive, >= */
+ int lsa_pos_end; /* exclusive, < */
+
/* Interface data from zebra. */
struct interface *ifp;
struct ospf_vl_data *vl_data; /* Data for Virtual Link */
@@ -242,6 +247,9 @@ extern int ospf_if_down (struct ospf_interface *);
extern int ospf_if_is_up (struct ospf_interface *);
extern struct ospf_interface *ospf_if_exists (struct ospf_interface *);
+extern struct ospf_interface *ospf_if_lookup_by_lsa_pos (struct ospf_area *,
+ int);
+extern void ospf_lsa_pos_set(int, int, struct ospf_interface *);
extern struct ospf_interface *ospf_if_lookup_by_local_addr (struct ospf *,
struct interface
*,
@@ -256,7 +264,8 @@ extern struct ospf_interface *ospf_if_lookup_recv_if (struct ospf *,
struct interface *);
extern struct ospf_interface *ospf_if_is_configured (struct ospf *,
struct in_addr *);
-
+extern struct ospf_interface *ospf_if_lookup_by_ifindex(struct ospf_area *,
+ unsigned int);
extern struct ospf_if_params *ospf_lookup_if_params (struct interface *,
struct in_addr);
extern struct ospf_if_params *ospf_get_if_params (struct interface *,
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 70504692..25bd754d 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -527,9 +527,16 @@ lsa_link_ptop_set (struct stream *s, struct ospf_interface *oi)
{
/* For unnumbered point-to-point networks, the Link Data field
should specify the interface's MIB-II ifIndex value. */
- links += link_info_set (s, nbr->router_id, oi->address->u.prefix4,
+ if (CHECK_FLAG(oi->ifp->status, ZEBRA_INTERFACE_UNNUMBERED))
+ id.s_addr = htonl(oi->ifp->ifindex);
+ else
+ id = oi->address->u.prefix4;
+
+ links += link_info_set (s, nbr->router_id, id,
LSA_LINK_TYPE_POINTOPOINT, 0, cost);
}
+ if (CHECK_FLAG(oi->ifp->status, ZEBRA_INTERFACE_UNNUMBERED))
+ return links;
/* Regardless of the state of the neighboring router, we must
add a Type 3 link (stub network).
@@ -651,9 +658,11 @@ lsa_link_ptomp_set (struct stream *s, struct ospf_interface *oi)
static int
router_lsa_link_set (struct stream *s, struct ospf_area *area)
{
+ struct ospf_host_route *host;
+ struct in_addr host_mask = {~0}; /* All ones */
struct listnode *node;
struct ospf_interface *oi;
- int links = 0;
+ int links = 0, old_links;
for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
{
@@ -664,6 +673,7 @@ router_lsa_link_set (struct stream *s, struct ospf_area *area)
{
if (oi->state != ISM_Down)
{
+ old_links = links;
/* Describe each link. */
switch (oi->type)
{
@@ -685,10 +695,14 @@ router_lsa_link_set (struct stream *s, struct ospf_area *area)
case OSPF_IFTYPE_LOOPBACK:
links += lsa_link_loopback_set (s, oi);
}
+ ospf_lsa_pos_set(old_links, links, oi);
}
}
}
-
+ for (ALL_LIST_ELEMENTS_RO (area->ospf->hostlist, node, host))
+ if (host->area == NULL || host->area == area)
+ links += link_info_set (s, host->host_addr, host_mask,
+ LSA_LINK_TYPE_STUB, 0, host->cost);
return links;
}
@@ -2900,6 +2914,10 @@ ospf_maxage_lsa_remover (struct thread *thread)
continue;
}
+ /* TODO: maybe convert this function to a work-queue */
+ if (thread_should_yield (thread))
+ OSPF_TIMER_ON (ospf->t_maxage, ospf_maxage_lsa_remover, 0);
+
/* Remove LSA from the LSDB */
if (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF))
if (IS_DEBUG_OSPF (lsa, LSA_FLOODING))
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 8b9a3458..0e9e182a 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -38,6 +38,7 @@
#include "memory.h"
#include "privs.h"
#include "sigevent.h"
+#include "paths.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
@@ -72,12 +73,13 @@ struct zebra_privs_t ospfd_privs =
};
/* Configuration filename and directory. */
-char config_default[] = SYSCONFDIR OSPF_DEFAULT_CONFIG;
+char config_default[MAXPATHLEN];
/* OSPFd options. */
struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
{ "config_file", required_argument, NULL, 'f'},
{ "pid_file", required_argument, NULL, 'i'},
{ "dryrun", no_argument, NULL, 'C'},
@@ -96,8 +98,11 @@ struct option longopts[] =
/* Master of threads. */
struct thread_master *master;
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
+
/* Process ID saved for use by init system */
-const char *pid_file = PATH_OSPFD_PID;
+const char *pid_file = pid_file_default;
#ifdef SUPPORT_OSPF_API
extern int ospf_apiserver_enable;
@@ -114,6 +119,7 @@ usage (char *progname, int status)
printf ("Usage : %s [OPTION...]\n\
Daemon which manages OSPF.\n\n\
-d, --daemon Runs in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
-f, --config_file Set configuration file name\n\
-i, --pid_file Set process identifier file name\n\
-A, --vty_addr Set vty's bind address\n\
@@ -214,7 +220,7 @@ main (int argc, char **argv)
{
int opt;
- opt = getopt_long (argc, argv, "df:i:hA:P:u:g:avC", longopts, 0);
+ opt = getopt_long (argc, argv, "dN:f:i:hA:P:u:g:avC", longopts, 0);
if (opt == EOF)
break;
@@ -226,6 +232,9 @@ main (int argc, char **argv)
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'f':
config_file = optarg;
break;
@@ -274,6 +283,9 @@ main (int argc, char **argv)
}
}
+ strcpy (config_default, path_config (OSPF_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (OSPF_PID_NAME));
+
/* Initializations. */
master = om->master;
@@ -324,7 +336,7 @@ main (int argc, char **argv)
pid_output (pid_file);
/* Create VTY socket */
- vty_serv_sock (vty_addr, vty_port, OSPF_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (OSPF_VTY_NAME));
/* Print banner. */
zlog_notice ("OSPFd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c
index b15efbd6..26e32d9b 100644
--- a/ospfd/ospf_nsm.c
+++ b/ospfd/ospf_nsm.c
@@ -162,7 +162,7 @@ nsm_should_adj (struct ospf_neighbor *nbr)
/* OSPF NSM functions. */
static int
-nsm_hello_received (struct ospf_neighbor *nbr)
+nsm_packet_received (struct ospf_neighbor *nbr)
{
/* Start or Restart Inactivity Timer. */
OSPF_NSM_TIMER_OFF (nbr->t_inactivity);
@@ -408,7 +408,7 @@ struct {
{
/* DependUpon: dummy state. */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { NULL, NSM_DependUpon }, /* HelloReceived */
+ { NULL, NSM_DependUpon }, /* PacketReceived */
{ NULL, NSM_DependUpon }, /* Start */
{ NULL, NSM_DependUpon }, /* 2-WayReceived */
{ NULL, NSM_DependUpon }, /* NegotiationDone */
@@ -425,7 +425,7 @@ struct {
{
/* Deleted: dummy state. */
{ NULL, NSM_Deleted }, /* NoEvent */
- { NULL, NSM_Deleted }, /* HelloReceived */
+ { NULL, NSM_Deleted }, /* PacketReceived */
{ NULL, NSM_Deleted }, /* Start */
{ NULL, NSM_Deleted }, /* 2-WayReceived */
{ NULL, NSM_Deleted }, /* NegotiationDone */
@@ -442,7 +442,7 @@ struct {
{
/* Down: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_Init }, /* HelloReceived */
+ { nsm_packet_received, NSM_Init }, /* PacketReceived */
{ nsm_start, NSM_Attempt }, /* Start */
{ NULL, NSM_Down }, /* 2-WayReceived */
{ NULL, NSM_Down }, /* NegotiationDone */
@@ -459,7 +459,7 @@ struct {
{
/* Attempt: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_Init }, /* HelloReceived */
+ { nsm_packet_received, NSM_Init }, /* PacketReceived */
{ NULL, NSM_Attempt }, /* Start */
{ NULL, NSM_Attempt }, /* 2-WayReceived */
{ NULL, NSM_Attempt }, /* NegotiationDone */
@@ -476,7 +476,7 @@ struct {
{
/* Init: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_Init }, /* HelloReceived */
+ { nsm_packet_received, NSM_Init }, /* PacketReceived */
{ NULL, NSM_Init }, /* Start */
{ nsm_twoway_received, NSM_DependUpon }, /* 2-WayReceived */
{ NULL, NSM_Init }, /* NegotiationDone */
@@ -493,7 +493,7 @@ struct {
{
/* 2-Way: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_TwoWay }, /* HelloReceived */
+ { nsm_packet_received, NSM_TwoWay }, /* HelloReceived */
{ NULL, NSM_TwoWay }, /* Start */
{ NULL, NSM_TwoWay }, /* 2-WayReceived */
{ NULL, NSM_TwoWay }, /* NegotiationDone */
@@ -510,7 +510,7 @@ struct {
{
/* ExStart: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_ExStart }, /* HelloReceived */
+ { nsm_packet_received, NSM_ExStart }, /* PacaketReceived */
{ NULL, NSM_ExStart }, /* Start */
{ NULL, NSM_ExStart }, /* 2-WayReceived */
{ nsm_negotiation_done, NSM_Exchange }, /* NegotiationDone */
@@ -527,7 +527,7 @@ struct {
{
/* Exchange: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_Exchange }, /* HelloReceived */
+ { nsm_packet_received, NSM_Exchange }, /* PacketReceived */
{ NULL, NSM_Exchange }, /* Start */
{ NULL, NSM_Exchange }, /* 2-WayReceived */
{ NULL, NSM_Exchange }, /* NegotiationDone */
@@ -544,7 +544,7 @@ struct {
{
/* Loading: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_Loading }, /* HelloReceived */
+ { nsm_packet_received, NSM_Loading }, /* PacketReceived */
{ NULL, NSM_Loading }, /* Start */
{ NULL, NSM_Loading }, /* 2-WayReceived */
{ NULL, NSM_Loading }, /* NegotiationDone */
@@ -560,7 +560,7 @@ struct {
},
{ /* Full: */
{ NULL, NSM_DependUpon }, /* NoEvent */
- { nsm_hello_received, NSM_Full }, /* HelloReceived */
+ { nsm_packet_received, NSM_Full }, /* PacketReceived */
{ NULL, NSM_Full }, /* Start */
{ NULL, NSM_Full }, /* 2-WayReceived */
{ NULL, NSM_Full }, /* NegotiationDone */
@@ -579,7 +579,7 @@ struct {
static const char *ospf_nsm_event_str[] =
{
"NoEvent",
- "HelloReceived",
+ "PacketReceived",
"Start",
"2-WayReceived",
"NegotiationDone",
diff --git a/ospfd/ospf_nsm.h b/ospfd/ospf_nsm.h
index 1121dae6..4f2ae808 100644
--- a/ospfd/ospf_nsm.h
+++ b/ospfd/ospf_nsm.h
@@ -39,7 +39,7 @@
/* OSPF Neighbor State Machine Event. */
#define NSM_NoEvent 0
-#define NSM_HelloReceived 1
+#define NSM_PacketReceived 1 /* HelloReceived in the protocol */
#define NSM_Start 2
#define NSM_TwoWayReceived 3
#define NSM_NegotiationDone 4
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index bc00def4..c4a6bf92 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -125,6 +125,20 @@ ospf_fifo_push (struct ospf_fifo *fifo, struct ospf_packet *op)
fifo->count++;
}
+/* Add new packet to head of fifo. */
+static void
+ospf_fifo_push_head (struct ospf_fifo *fifo, struct ospf_packet *op)
+{
+ op->next = fifo->head;
+
+ if (fifo->tail == NULL)
+ fifo->tail = op;
+
+ fifo->head = op;
+
+ fifo->count++;
+}
+
/* Delete first packet from fifo. */
struct ospf_packet *
ospf_fifo_pop (struct ospf_fifo *fifo)
@@ -199,6 +213,27 @@ ospf_packet_add (struct ospf_interface *oi, struct ospf_packet *op)
/* ospf_fifo_debug (oi->obuf); */
}
+static void
+ospf_packet_add_top (struct ospf_interface *oi, struct ospf_packet *op)
+{
+ if (!oi->obuf)
+ {
+ zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
+ "destination %s) called with NULL obuf, ignoring "
+ "(please report this bug)!\n",
+ IF_NAME(oi), oi->state, LOOKUP (ospf_ism_state_msg, oi->state),
+ ospf_packet_type_str[stream_getc_from(op->s, 1)],
+ inet_ntoa (op->dst));
+ return;
+ }
+
+ /* Add packet to head of queue. */
+ ospf_fifo_push_head (oi->obuf, op);
+
+ /* Debug of packet fifo*/
+ /* ospf_fifo_debug (oi->obuf); */
+}
+
void
ospf_packet_delete (struct ospf_interface *oi)
{
@@ -324,7 +359,7 @@ static int
ospf_make_md5_digest (struct ospf_interface *oi, struct ospf_packet *op)
{
struct ospf_header *ospfh;
- unsigned char digest[OSPF_AUTH_MD5_SIZE];
+ unsigned char digest[OSPF_AUTH_MD5_SIZE] = {0};
MD5_CTX ctx;
void *ibuf;
u_int32_t t;
@@ -351,7 +386,7 @@ ospf_make_md5_digest (struct ospf_interface *oi, struct ospf_packet *op)
/* Get MD5 Authentication key from auth_key list. */
if (list_isempty (OSPF_IF_PARAM (oi, auth_crypt)))
- auth_key = (const u_int8_t *) "";
+ auth_key = (const u_int8_t *) digest;
else
{
ck = listgetdata (listtail(OSPF_IF_PARAM (oi, auth_crypt)));
@@ -875,7 +910,7 @@ ospf_hello (struct ip *iph, struct ospf_header *ospfh,
old_state = nbr->state;
/* Add event to thread. */
- OSPF_NSM_EVENT_EXECUTE (nbr, NSM_HelloReceived);
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_PacketReceived);
/* RFC2328 Section 9.5.1
If the router is not eligible to become Designated Router,
@@ -895,19 +930,19 @@ ospf_hello (struct ip *iph, struct ospf_header *ospfh,
if (oi->type == OSPF_IFTYPE_NBMA &&
(old_state == NSM_Down || old_state == NSM_Attempt))
{
- OSPF_NSM_EVENT_EXECUTE (nbr, NSM_OneWayReceived);
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_OneWayReceived);
goto done;
}
if (ospf_nbr_bidirectional (&oi->ospf->router_id, hello->neighbors,
size - OSPF_HELLO_MIN_SIZE))
{
- OSPF_NSM_EVENT_EXECUTE (nbr, NSM_TwoWayReceived);
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_TwoWayReceived);
nbr->options |= hello->options;
}
else
{
- OSPF_NSM_EVENT_EXECUTE (nbr, NSM_OneWayReceived);
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_OneWayReceived);
goto done;
}
@@ -1190,6 +1225,9 @@ ospf_db_desc (struct ip *iph, struct ospf_header *ospfh,
}
#endif /* HAVE_OPAQUE_LSA */
+ /* Add event to thread. */
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_PacketReceived);
+
/* Process DD packet by neighbor status. */
switch (nbr->state)
{
@@ -1411,6 +1449,9 @@ ospf_ls_req (struct ip *iph, struct ospf_header *ospfh,
return;
}
+ /* Add event to thread. */
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_PacketReceived);
+
/* Neighbor State should be Exchange or later. */
if (nbr->state != NSM_Exchange &&
nbr->state != NSM_Loading &&
@@ -1643,6 +1684,9 @@ ospf_ls_upd (struct ip *iph, struct ospf_header *ospfh,
return;
}
+ /* Add event to thread. */
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_PacketReceived);
+
/* Check neighbor state. */
if (nbr->state < NSM_Exchange)
{
@@ -1976,6 +2020,9 @@ ospf_ls_ack (struct ip *iph, struct ospf_header *ospfh,
return;
}
+ /* Add event to thread. */
+ OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_PacketReceived);
+
if (nbr->state < NSM_Exchange)
{
zlog_warn ("Link State Acknowledgment: "
@@ -2953,8 +3000,8 @@ ospf_make_ls_ack (struct ospf_interface *oi, struct list *ack, struct stream *s)
return length;
}
-void
-ospf_hello_send_sub (struct ospf_interface *oi, struct in_addr *addr)
+static void
+ospf_hello_send_sub (struct ospf_interface *oi, in_addr_t addr)
{
struct ospf_packet *op;
u_int16_t length = OSPF_HEADER_SIZE;
@@ -2973,10 +3020,12 @@ ospf_hello_send_sub (struct ospf_interface *oi, struct in_addr *addr)
/* Set packet length. */
op->length = length;
- op->dst.s_addr = addr->s_addr;
+ op->dst.s_addr = addr;
- /* Add packet to the interface output queue. */
- ospf_packet_add (oi, op);
+ /* Add packet to the top of the interface output queue, so that they
+ * can't get delayed by things like long queues of LS Update packets
+ */
+ ospf_packet_add_top (oi, op);
/* Hook thread to write packet. */
OSPF_ISM_WRITE_ON (oi->ospf);
@@ -3007,7 +3056,7 @@ ospf_poll_send (struct ospf_nbr_nbma *nbr_nbma)
&& oi->state != ISM_DR && oi->state != ISM_Backup)
return;
- ospf_hello_send_sub (oi, &nbr_nbma->addr);
+ ospf_hello_send_sub (oi, nbr_nbma->addr.s_addr);
}
int
@@ -3046,7 +3095,7 @@ ospf_hello_reply_timer (struct thread *thread)
zlog (NULL, LOG_DEBUG, "NSM[%s:%s]: Timer (hello-reply timer expire)",
IF_NAME (nbr->oi), inet_ntoa (nbr->router_id));
- ospf_hello_send_sub (nbr->oi, &nbr->src);
+ ospf_hello_send_sub (nbr->oi, nbr->src.s_addr);
return 0;
}
@@ -3055,27 +3104,10 @@ ospf_hello_reply_timer (struct thread *thread)
void
ospf_hello_send (struct ospf_interface *oi)
{
- struct ospf_packet *op;
- u_int16_t length = OSPF_HEADER_SIZE;
-
/* If this is passive interface, do not send OSPF Hello. */
if (OSPF_IF_PASSIVE_STATUS (oi) == OSPF_IF_PASSIVE)
return;
- op = ospf_packet_new (oi->ifp->mtu);
-
- /* Prepare OSPF common header. */
- ospf_make_header (OSPF_MSG_HELLO, oi, op->s);
-
- /* Prepare OSPF Hello body. */
- length += ospf_make_hello (oi, op->s);
-
- /* Fill OSPF header. */
- ospf_fill_header (oi, op->s, length);
-
- /* Set packet length. */
- op->length = length;
-
if (oi->type == OSPF_IFTYPE_NBMA)
{
struct ospf_neighbor *nbr;
@@ -3104,33 +3136,16 @@ ospf_hello_send (struct ospf_interface *oi)
if (nbr->priority == 0 && oi->state == ISM_DROther)
continue;
/* if oi->state == Waiting, send hello to all neighbors */
- {
- struct ospf_packet *op_dup;
-
- op_dup = ospf_packet_dup(op);
- op_dup->dst = nbr->src;
-
- /* Add packet to the interface output queue. */
- ospf_packet_add (oi, op_dup);
-
- OSPF_ISM_WRITE_ON (oi->ospf);
- }
+ ospf_hello_send_sub (oi, nbr->src.s_addr);
}
- ospf_packet_free (op);
}
else
{
/* Decide destination address. */
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- op->dst.s_addr = oi->vl_data->peer_addr.s_addr;
- else
- op->dst.s_addr = htonl (OSPF_ALLSPFROUTERS);
-
- /* Add packet to the interface output queue. */
- ospf_packet_add (oi, op);
-
- /* Hook thread to write packet. */
- OSPF_ISM_WRITE_ON (oi->ospf);
+ ospf_hello_send_sub (oi, oi->vl_data->peer_addr.s_addr);
+ else
+ ospf_hello_send_sub (oi, htonl (OSPF_ALLSPFROUTERS));
}
}
diff --git a/ospfd/ospf_packet.h b/ospfd/ospf_packet.h
index 7b3d6866..9a472081 100644
--- a/ospfd/ospf_packet.h
+++ b/ospfd/ospf_packet.h
@@ -162,6 +162,5 @@ extern int ospf_ls_upd_timer (struct thread *);
extern int ospf_ls_ack_timer (struct thread *);
extern int ospf_poll_timer (struct thread *);
extern int ospf_hello_reply_timer (struct thread *);
-extern void ospf_hello_send_sub (struct ospf_interface *, struct in_addr *);
#endif /* _ZEBRA_OSPF_PACKET_H */
diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c
index 267237b8..10608f50 100644
--- a/ospfd/ospf_route.c
+++ b/ospfd/ospf_route.c
@@ -272,61 +272,6 @@ ospf_route_install (struct ospf *ospf, struct route_table *rt)
}
}
-static void
-ospf_intra_route_add (struct route_table *rt, struct vertex *v,
- struct ospf_area *area)
-{
- struct route_node *rn;
- struct ospf_route *or;
- struct prefix_ipv4 p;
- struct ospf_path *path;
- struct vertex_parent *parent;
- struct listnode *node, *nnode;
-
- p.family = AF_INET;
- p.prefix = v->id;
- if (v->type == OSPF_VERTEX_ROUTER)
- p.prefixlen = IPV4_MAX_BITLEN;
- else
- {
- struct network_lsa *lsa = (struct network_lsa *) v->lsa;
- p.prefixlen = ip_masklen (lsa->mask);
- }
- apply_mask_ipv4 (&p);
-
- rn = route_node_get (rt, (struct prefix *) &p);
- if (rn->info)
- {
- zlog_warn ("Same routing information exists for %s", inet_ntoa (v->id));
- route_unlock_node (rn);
- return;
- }
-
- or = ospf_route_new ();
-
- if (v->type == OSPF_VERTEX_NETWORK)
- {
- or->type = OSPF_DESTINATION_NETWORK;
-
- for (ALL_LIST_ELEMENTS (v->parents, node, nnode, parent))
- {
- path = ospf_path_new ();
- path->nexthop = parent->nexthop->router;
- listnode_add (or->paths, path);
- }
- }
- else
- or->type = OSPF_DESTINATION_ROUTER;
-
- or->id = v->id;
- or->u.std.area_id = area->area_id;
- or->u.std.external_routing= area->external_routing;
- or->path_type = OSPF_PATH_INTRA_AREA;
- or->cost = v->distance;
-
- rn->info = or;
-}
-
/* RFC2328 16.1. (4). For "router". */
void
ospf_intra_add_router (struct route_table *rt, struct vertex *v,
@@ -810,12 +755,18 @@ ospf_route_copy_nexthops_from_vertex (struct ospf_route *to,
{
nexthop = vp->nexthop;
- if (nexthop->oi != NULL)
+ if (nexthop->oi != NULL)
{
- if (! ospf_path_exist (to->paths, nexthop->router, nexthop->oi))
+ if (!ospf_path_exist (to->paths, nexthop->router, nexthop->oi))
{
path = ospf_path_new ();
- path->nexthop = nexthop->router;
+
+ /* PtoP I/F's are always directly connected */
+ if (if_is_pointopoint (nexthop->oi->ifp))
+ path->nexthop.s_addr = INADDR_ANY;
+ else
+ path->nexthop = nexthop->router;
+
path->ifindex = nexthop->oi->ifp->ifindex;
listnode_add (to->paths, path);
}
diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h
index 17ab68e5..5483aaf5 100644
--- a/ospfd/ospf_route.h
+++ b/ospfd/ospf_route.h
@@ -121,6 +121,12 @@ struct ospf_route
} u;
};
+struct ospf_host_route {
+ struct in_addr host_addr;
+ u_int32_t cost; /* i.e. metric. */
+ struct ospf_area *area; /* NULL == all areas */
+};
+
extern struct ospf_path *ospf_path_new (void);
extern void ospf_path_free (struct ospf_path *);
extern struct ospf_path *ospf_path_lookup (struct list *, struct ospf_path *);
diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c
index ca200222..b06c7b9e 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -480,13 +480,15 @@ ospf_spf_add_parent (struct vertex *v, struct vertex *w,
static unsigned int
ospf_nexthop_calculation (struct ospf_area *area, struct vertex *v,
struct vertex *w, struct router_lsa_link *l,
- unsigned int distance)
+ unsigned int distance, int lsa_pos)
{
struct listnode *node, *nnode;
struct vertex_nexthop *nh;
struct vertex_parent *vp;
struct ospf_interface *oi = NULL;
unsigned int added = 0;
+ char buf1[BUFSIZ];
+ char buf2[BUFSIZ];
if (IS_DEBUG_OSPF_EVENT)
{
@@ -505,30 +507,38 @@ ospf_nexthop_calculation (struct ospf_area *area, struct vertex *v,
the OSPF interface connecting to the destination network/router.
*/
+ /* we *must* be supplied with the link data */
+ assert (l != NULL);
+ oi = ospf_if_lookup_by_lsa_pos (area, lsa_pos);
+ if (!oi)
+ {
+ zlog_debug("%s: OI not found in LSA: lsa_pos:%d link_id:%s link_data:%s",
+ __func__, lsa_pos,
+ inet_ntop (AF_INET, &l->link_id, buf1, BUFSIZ),
+ inet_ntop (AF_INET, &l->link_data, buf2, BUFSIZ));
+ return 0;
+ }
+
+ if (IS_DEBUG_OSPF_EVENT)
+ {
+ zlog_debug("%s: considering link:%s "
+ "type:%d link_id:%s link_data:%s",
+ __func__, oi->ifp->name, l->m[0].type,
+ inet_ntop (AF_INET, &l->link_id, buf1, BUFSIZ),
+ inet_ntop (AF_INET, &l->link_data, buf2, BUFSIZ));
+ }
+
if (w->type == OSPF_VERTEX_ROUTER)
{
/* l is a link from v to w
* l2 will be link from w to v
*/
struct router_lsa_link *l2 = NULL;
-
- /* we *must* be supplied with the link data */
- assert (l != NULL);
-
- if (IS_DEBUG_OSPF_EVENT)
- {
- char buf1[BUFSIZ];
- char buf2[BUFSIZ];
-
- zlog_debug("ospf_nexthop_calculation(): considering link "
- "type %d link_id %s link_data %s",
- l->m[0].type,
- inet_ntop (AF_INET, &l->link_id, buf1, BUFSIZ),
- inet_ntop (AF_INET, &l->link_data, buf2, BUFSIZ));
- }
if (l->m[0].type == LSA_LINK_TYPE_POINTOPOINT)
{
+ struct in_addr nexthop;
+
/* If the destination is a router which connects to
the calculating router via a Point-to-MultiPoint
network, the destination's next hop IP address(es)
@@ -539,68 +549,53 @@ ospf_nexthop_calculation (struct ospf_area *area, struct vertex *v,
provides an IP address of the next hop router.
At this point l is a link from V to W, and V is the
- root ("us"). Find the local interface associated
- with l (its address is in l->link_data). If it
- is a point-to-multipoint interface, then look through
- the links in the opposite direction (W to V). If
- any of them have an address that lands within the
+ root ("us"). If it is a point-to-multipoint interface,
+ then look through the links in the opposite direction (W to V).
+ If any of them have an address that lands within the
subnet declared by the PtMP link, then that link
- is a constituent of the PtMP link, and its address is
+ is a constituent of the PtMP link, and its address is
a nexthop address for V.
*/
- oi = ospf_if_is_configured (area->ospf, &l->link_data);
- if (oi && oi->type == OSPF_IFTYPE_POINTOMULTIPOINT)
- {
- struct prefix_ipv4 la;
-
- la.family = AF_INET;
- la.prefixlen = oi->address->prefixlen;
-
- /* V links to W on PtMP interface
- - find the interface address on W */
- while ((l2 = ospf_get_next_link (w, v, l2)))
- {
- la.prefix = l2->link_data;
-
- if (prefix_cmp ((struct prefix *) &la,
- oi->address) == 0)
- /* link_data is on our PtMP network */
- break;
- }
- } /* end l is on point-to-multipoint link */
- else
- {
- /* l is a regular point-to-point link.
- Look for a link from W to V.
- */
- while ((l2 = ospf_get_next_link (w, v, l2)))
- {
- oi = ospf_if_is_configured (area->ospf,
- &(l2->link_data));
-
- if (oi == NULL)
- continue;
-
- if (!IPV4_ADDR_SAME (&oi->address->u.prefix4,
- &l->link_data))
- continue;
-
- break;
- }
- }
-
- if (oi && l2)
+ if (oi->type == OSPF_IFTYPE_POINTOPOINT)
+ {
+ added = 1;
+ nexthop.s_addr = 0; /* Nexthop not required */
+ }
+ else if (oi->type == OSPF_IFTYPE_POINTOMULTIPOINT)
+ {
+ struct prefix_ipv4 la;
+
+ la.family = AF_INET;
+ la.prefixlen = oi->address->prefixlen;
+
+ /* V links to W on PtMP interface
+ - find the interface address on W */
+ while ((l2 = ospf_get_next_link (w, v, l2)))
+ {
+ la.prefix = l2->link_data;
+
+ if (prefix_cmp ((struct prefix *) &la,
+ oi->address) != 0)
+ continue;
+ /* link_data is on our PtMP network */
+ added = 1;
+ nexthop = l2->link_data;
+ break;
+ }
+ }
+
+ if (added)
{
/* found all necessary info to build nexthop */
nh = vertex_nexthop_new ();
nh->oi = oi;
- nh->router = l2->link_data;
+ nh->router = nexthop;
ospf_spf_add_parent (v, w, nh, distance);
return 1;
}
else
- zlog_info("ospf_nexthop_calculation(): "
- "could not determine nexthop for link");
+ zlog_info("%s: could not determine nexthop for link %s",
+ __func__, oi->ifp->name);
} /* end point-to-point link from V to W */
else if (l->m[0].type == LSA_LINK_TYPE_VIRTUALLINK)
{
@@ -633,19 +628,13 @@ ospf_nexthop_calculation (struct ospf_area *area, struct vertex *v,
else
{
assert(w->type == OSPF_VERTEX_NETWORK);
- oi = ospf_if_is_configured (area->ospf, &(l->link_data));
- if (oi)
- {
- nh = vertex_nexthop_new ();
- nh->oi = oi;
- nh->router.s_addr = 0;
- ospf_spf_add_parent (v, w, nh, distance);
- return 1;
- }
+
+ nh = vertex_nexthop_new ();
+ nh->oi = oi;
+ nh->router.s_addr = 0; /* Nexthop not required */
+ ospf_spf_add_parent (v, w, nh, distance);
+ return 1;
}
- zlog_info("ospf_nexthop_calculation(): "
- "Unknown attached link");
- return 0;
} /* end V is the root */
/* Check if W's parent is a network connected to root. */
else if (v->type == OSPF_VERTEX_NETWORK)
@@ -726,7 +715,7 @@ ospf_spf_next (struct vertex *v, struct ospf_area *area,
u_char *lim;
struct router_lsa_link *l = NULL;
struct in_addr *r;
- int type = 0;
+ int type = 0, lsa_pos=-1, lsa_pos_next=0;
/* If this is a router-LSA, and bit V of the router-LSA (see Section
A.4.2:RFC2328) is set, set Area A's TransitCapability to TRUE. */
@@ -754,7 +743,8 @@ ospf_spf_next (struct vertex *v, struct ospf_area *area,
if (v->lsa->type == OSPF_ROUTER_LSA)
{
l = (struct router_lsa_link *) p;
-
+ lsa_pos = lsa_pos_next; /* LSA link position */
+ lsa_pos_next++;
p += (ROUTER_LSA_MIN_SIZE +
(l->m[0].tos_count * ROUTER_LSA_TOS_SIZE));
@@ -876,7 +866,7 @@ ospf_spf_next (struct vertex *v, struct ospf_area *area,
w = ospf_vertex_new (w_lsa);
/* Calculate nexthop to W. */
- if (ospf_nexthop_calculation (area, v, w, l, distance))
+ if (ospf_nexthop_calculation (area, v, w, l, distance, lsa_pos))
pqueue_enqueue (w, candidate);
else if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("Nexthop Calc failed");
@@ -896,7 +886,7 @@ ospf_spf_next (struct vertex *v, struct ospf_area *area,
{
/* Found an equal-cost path to W.
* Calculate nexthop of to W from V. */
- ospf_nexthop_calculation (area, v, w, l, distance);
+ ospf_nexthop_calculation (area, v, w, l, distance, lsa_pos);
}
/* less than. */
else
@@ -906,7 +896,7 @@ ospf_spf_next (struct vertex *v, struct ospf_area *area,
* valid nexthop it will call spf_add_parents, which
* will flush the old parents
*/
- if (ospf_nexthop_calculation (area, v, w, l, distance))
+ if (ospf_nexthop_calculation (area, v, w, l, distance, lsa_pos))
/* Decrease the key of the node in the heap.
* trickle-sort it up towards root, just in case this
* node should now be the new root due the cost change.
@@ -1045,6 +1035,7 @@ ospf_rtrs_free (struct route_table *rtrs)
route_table_finish (rtrs);
}
+#if 0
static void
ospf_rtrs_print (struct route_table *rtrs)
{
@@ -1104,6 +1095,7 @@ ospf_rtrs_print (struct route_table *rtrs)
zlog_debug ("ospf_rtrs_print() end");
}
+#endif
/* Calculating the shortest-path tree for an area. */
static void
@@ -1269,9 +1261,6 @@ ospf_spf_calculate_timer (struct thread *thread)
/* If new Router Route is installed,
then schedule re-calculate External routes. */
- if (1)
- ospf_ase_calculate_schedule (ospf);
-
ospf_ase_calculate_timer_add (ospf);
/* Update routing table. */
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index a3c39447..01e85c71 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -93,29 +93,6 @@ ospf_str2area_id (const char *str, struct in_addr *area_id, int *format)
static int
-str2distribute_source (const char *str, int *source)
-{
- /* Sanity check. */
- if (str == NULL)
- return 0;
-
- if (strncmp (str, "k", 1) == 0)
- *source = ZEBRA_ROUTE_KERNEL;
- else if (strncmp (str, "c", 1) == 0)
- *source = ZEBRA_ROUTE_CONNECT;
- else if (strncmp (str, "s", 1) == 0)
- *source = ZEBRA_ROUTE_STATIC;
- else if (strncmp (str, "r", 1) == 0)
- *source = ZEBRA_ROUTE_RIP;
- else if (strncmp (str, "b", 1) == 0)
- *source = ZEBRA_ROUTE_BGP;
- else
- return 0;
-
- return 1;
-}
-
-static int
str2metric (const char *str, int *metric)
{
/* Sanity check. */
@@ -2862,6 +2839,9 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf,
vty_out (vty, " Internet Address %s/%d,",
inet_ntoa (oi->address->u.prefix4), oi->address->prefixlen);
+ vty_out(vty, " Unnumbered: %s,",
+ CHECK_FLAG(oi->ifp->status, ZEBRA_INTERFACE_UNNUMBERED) ? "YES" : "NO");
+
if (oi->connected->destination || oi->type == OSPF_IFTYPE_VIRTUALLINK)
{
struct in_addr *dest;
@@ -3751,7 +3731,7 @@ show_as_external_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
return 0;
}
-/* N.B. This function currently seems to be unused. */
+#if 0
static int
show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
{
@@ -3775,6 +3755,7 @@ show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
return 0;
}
+#endif
/* Show AS-NSSA-LSA detail information. */
static int
@@ -5792,6 +5773,71 @@ ALIAS (no_ip_ospf_transmit_delay,
"OSPF interface commands\n"
"Link state transmit delay\n")
+DEFUN (ip_ospf_area,
+ ip_ospf_area_cmd,
+ "ip ospf area (A.B.C.D|<0-4294967295>)",
+ "IP Information\n"
+ "OSPF interface commands\n"
+ "Enable OSPF on this interface\n"
+ "OSPF area ID in IP address format\n"
+ "OSPF area ID as a decimal value\n")
+{
+ struct interface *ifp = vty->index;
+ int format, ret;
+ struct in_addr area_id;
+ struct ospf *ospf;
+ struct ospf_if_params *params;
+
+ ret = ospf_str2area_id (argv[0], &area_id, &format);
+
+ if (ret < 0)
+ {
+ vty_out (vty, "Please specify area by A.B.C.D|<0-4294967295>%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ params = IF_DEF_PARAMS (ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ {
+ vty_out (vty, "There is already a interface statement.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (memcmp (ifp->name, "VLINK", 5) == 0)
+ {
+ vty_out (vty, "Cannot enable OSPF on a virtual link.%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ SET_IF_PARAM (params, if_area);
+ params->if_area = area_id;
+ ospf_interface_set (ifp);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_ip_ospf_area,
+ no_ip_ospf_area_cmd,
+ "no ip ospf area",
+ NO_STR
+ "IP Information\n"
+ "OSPF interface commands\n"
+ "Disable OSPF on this interface\n")
+{
+ struct interface *ifp = vty->index;
+ struct ospf *ospf;
+ struct ospf_if_params *params;
+
+ params = IF_DEF_PARAMS (ifp);
+ if (!OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ return CMD_SUCCESS;
+
+ UNSET_IF_PARAM (params, if_area);
+
+ ospf_interface_unset (ifp);
+ return CMD_SUCCESS;
+}
+
+
DEFUN (ospf_redistribute_source_metric_type,
ospf_redistribute_source_metric_type_routemap_cmd,
@@ -5813,7 +5859,8 @@ DEFUN (ospf_redistribute_source_metric_type,
int metric = -1;
/* Get distribute source. */
- if (!str2distribute_source (argv[0], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
/* Get metric value. */
@@ -5874,7 +5921,8 @@ DEFUN (ospf_redistribute_source_type_metric,
int metric = -1;
/* Get distribute source. */
- if (!str2distribute_source (argv[0], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
/* Get metric value. */
@@ -5938,7 +5986,8 @@ DEFUN (ospf_redistribute_source_metric_routemap,
int metric = -1;
/* Get distribute source. */
- if (!str2distribute_source (argv[0], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
/* Get metric value. */
@@ -5971,7 +6020,8 @@ DEFUN (ospf_redistribute_source_type_routemap,
int type = -1;
/* Get distribute source. */
- if (!str2distribute_source (argv[0], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
/* Get metric value. */
@@ -5999,7 +6049,8 @@ DEFUN (ospf_redistribute_source_routemap,
int source;
/* Get distribute source. */
- if (!str2distribute_source (argv[0], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
if (argc == 2)
@@ -6020,7 +6071,8 @@ DEFUN (no_ospf_redistribute_source,
struct ospf *ospf = vty->index;
int source;
- if (!str2distribute_source (argv[0], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
ospf_routemap_unset (ospf, source);
@@ -6039,7 +6091,8 @@ DEFUN (ospf_distribute_list_out,
int source;
/* Get distribute source. */
- if (!str2distribute_source (argv[1], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
return ospf_distribute_list_out_set (ospf, source, argv[0]);
@@ -6057,7 +6110,8 @@ DEFUN (no_ospf_distribute_list_out,
struct ospf *ospf = vty->index;
int source;
- if (!str2distribute_source (argv[1], &source))
+ source = proto_redistnum(AFI_IP, argv[0]);
+ if (source < 0 || source == ZEBRA_ROUTE_OSPF)
return CMD_WARNING;
return ospf_distribute_list_out_unset (ospf, source, argv[0]);
@@ -7384,6 +7438,123 @@ DEFUN (show_ip_ospf_route,
return CMD_SUCCESS;
}
+DEFUN (ip_ospf_host,
+ ip_ospf_host_cmd,
+ "ip ospf host A.B.C.D area (A.B.C.D|<0-4294967295>|all) cost <0-65535>",
+ "OSPF specific commands\n"
+ "Add a host route to OPSF\n"
+ "Host route in IP address format\n")
+{
+ struct ospf *ospf;
+ u_int32_t cost;
+ struct ospf_area *area = NULL;
+ struct in_addr host_addr, area_id;
+ struct ospf_host_route *host = NULL;
+ struct listnode *node;
+ int ret, format;
+
+ ospf = ospf_lookup ();
+ if (ospf == NULL)
+ {
+ vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+ return CMD_SUCCESS;
+ }
+ ret = inet_aton (argv[0], &host_addr);
+ if (!ret)
+ {
+ vty_out (vty, "Please specify host route by A.B.C.D%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ cost = strtol (argv[2], NULL, 10);
+ /* cost range is <0-65535>. */
+ if (cost < 0 || cost > 65535)
+ {
+ vty_out (vty, "cost is invalid%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (strcmp(argv[1], "all") != 0)
+ {
+ VTY_GET_OSPF_AREA_ID (area_id, format, argv[1]); /* returns if error */
+ area = ospf_area_get (ospf, area_id, format);
+ }
+
+
+ for (ALL_LIST_ELEMENTS_RO (ospf->hostlist, node, host))
+ if (IPV4_ADDR_SAME (&host_addr, &host->host_addr) &&
+ area == host->area)
+ break;
+
+ if (!node)
+ {
+ host = XCALLOC (MTYPE_OSPF_TOP, sizeof (struct ospf_host_route));
+ listnode_add (ospf->hostlist, host);
+ }
+ host->host_addr = host_addr;
+ host->cost = cost;
+ host->area = area;
+
+ if (!area)
+ for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
+ ospf_router_lsa_timer_add(area);
+ else
+ ospf_router_lsa_timer_add(area);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_ip_ospf_host,
+ no_ip_ospf_host_cmd,
+ "no ip ospf host A.B.C.D area (A.B.C.D|<0-4294967295>|all)",
+ NO_STR
+ "OSPF specific commands\n"
+ "Host route in IP address format\n")
+{
+ struct ospf *ospf;
+ struct ospf_area *area = NULL;
+ struct in_addr host_addr, area_id;
+ struct ospf_host_route *host = NULL;
+ struct listnode *node;
+ int ret, format;
+
+ ospf = ospf_lookup ();
+ if (ospf == NULL)
+ {
+ vty_out (vty, " OSPF Routing Process not enabled%s", VTY_NEWLINE);
+ return CMD_SUCCESS;
+ }
+ ret = inet_aton (argv[0], &host_addr);
+ if (!ret)
+ {
+ vty_out (vty, "Please specify host route by A.B.C.D%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (strcmp(argv[1], "all") != 0)
+ {
+ VTY_GET_OSPF_AREA_ID (area_id, format, argv[1]);
+ area = ospf_area_get (ospf, area_id, format);
+ }
+
+ for (ALL_LIST_ELEMENTS_RO (ospf->hostlist, node, host))
+ if (IPV4_ADDR_SAME (&host_addr, &host->host_addr) &&
+ area == host->area)
+ break;
+
+ if (node)
+ {
+ listnode_delete (ospf->hostlist, host);
+ XFREE (MTYPE_OSPF_TOP, host);
+ if (!area)
+ for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
+ ospf_router_lsa_timer_add(area);
+ else
+ ospf_router_lsa_timer_add(area);
+ }
+ return CMD_SUCCESS;
+}
+
const char *ospf_abr_type_str[] =
{
@@ -7591,6 +7762,14 @@ config_write_interface (struct vty *vty)
vty_out (vty, "%s", VTY_NEWLINE);
}
+ /* Area print. */
+ if (OSPF_IF_PARAM_CONFIGURED (params, if_area))
+ {
+ vty_out (vty, " ip ospf area %s%s",
+ inet_ntoa (params->if_area),
+ VTY_NEWLINE);
+ }
+
/* MTU ignore print. */
if (OSPF_IF_PARAM_CONFIGURED (params, mtu_ignore) &&
params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
@@ -7965,6 +8144,7 @@ ospf_config_write (struct vty *vty)
struct interface *ifp;
struct ospf_interface *oi;
struct listnode *node;
+ struct ospf_host_route *host;
int write = 0;
ospf = ospf_lookup ();
@@ -8032,7 +8212,20 @@ ospf_config_write (struct vty *vty)
/* passive-interface print. */
if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
vty_out (vty, " passive-interface default%s", VTY_NEWLINE);
-
+
+ for (ALL_LIST_ELEMENTS_RO (ospf->hostlist, node, host))
+ {
+ char buf[28];
+
+ if (host->area)
+ area_id2str(buf, sizeof(buf), host->area);
+ else
+ strcpy(buf, "all");
+ vty_out (vty, " ip ospf host %s area %s cost %d%s",
+ inet_ntoa (host->host_addr),
+ buf, host->cost, VTY_NEWLINE);
+ }
+
for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface)
&& IF_DEF_PARAMS (ifp)->passive_interface !=
@@ -8232,6 +8425,10 @@ ospf_vty_if_init (void)
install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_cmd);
+ /* "ip ospf area" commands. */
+ install_element (INTERFACE_NODE, &ip_ospf_area_cmd);
+ install_element (INTERFACE_NODE, &no_ip_ospf_area_cmd);
+
/* These commands are compatibitliy for previous version. */
install_element (INTERFACE_NODE, &ospf_authentication_key_cmd);
install_element (INTERFACE_NODE, &no_ospf_authentication_key_cmd);
@@ -8518,6 +8715,10 @@ ospf_vty_init (void)
install_element (OSPF_NODE, &no_ospf_neighbor_priority_cmd);
install_element (OSPF_NODE, &no_ospf_neighbor_poll_interval_cmd);
+ /* "ip ospf host" commands. */
+ install_element (OSPF_NODE, &ip_ospf_host_cmd);
+ install_element (OSPF_NODE, &no_ip_ospf_host_cmd);
+
/* Init interface related vty commands. */
ospf_vty_if_init ();
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index 6f0a71ff..484aba98 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -133,8 +133,9 @@ ospf_interface_delete (int command, struct zclient *zclient,
if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
zlog_debug
- ("Zebra: interface delete %s index %d flags %lld metric %d mtu %d",
- ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
+ ("Zebra: interface delete %s index %d flags %#llx metric %d mtu %d",
+ ifp->name, ifp->ifindex, (unsigned long long) ifp->flags,
+ ifp->metric, ifp->mtu);
#ifdef HAVE_SNMP
ospf_snmp_if_delete (ifp);
@@ -195,6 +196,17 @@ ospf_interface_state_up (int command, struct zclient *zclient,
ospf_if_recalculate_output_cost (ifp);
}
+ if (CHECK_FLAG(if_tmp.status ^ ifp->status, ZEBRA_INTERFACE_UNNUMBERED))
+ {
+ if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
+ zlog_debug ("Zebra: Interface[%s] Unnumbered state change %d -> %d.",
+ ifp->name,
+ if_tmp.status & ZEBRA_INTERFACE_UNNUMBERED,
+ ifp->status & ZEBRA_INTERFACE_UNNUMBERED);
+
+ ospf_if_reset (ifp);
+ }
+
if (if_tmp.mtu != ifp->mtu)
{
if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE))
@@ -481,9 +493,9 @@ ospf_zebra_add_discard (struct prefix_ipv4 *p)
if (zclient->redist[ZEBRA_ROUTE_OSPF])
{
api.type = ZEBRA_ROUTE_OSPF;
- api.flags = ZEBRA_FLAG_BLACKHOLE;
+ api.flags = 0;
api.message = 0;
- SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
+ SET_FLAG (api.message, ZAPI_MESSAGE_BLACKHOLE);
api.nexthop_num = 0;
api.ifindex_num = 0;
@@ -503,9 +515,9 @@ ospf_zebra_delete_discard (struct prefix_ipv4 *p)
if (zclient->redist[ZEBRA_ROUTE_OSPF])
{
api.type = ZEBRA_ROUTE_OSPF;
- api.flags = ZEBRA_FLAG_BLACKHOLE;
+ api.flags = 0;
api.message = 0;
- SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
+ SET_FLAG (api.message, ZAPI_MESSAGE_BLACKHOLE);
api.nexthop_num = 0;
api.ifindex_num = 0;
@@ -964,7 +976,7 @@ ospf_distribute_list_update_timer (struct thread *thread)
/* Update distribute-list and set timer to apply access-list. */
void
-ospf_distribute_list_update (struct ospf *ospf, int type)
+ospf_distribute_list_update (struct ospf *ospf, unsigned long type)
{
struct route_table *rt;
diff --git a/ospfd/ospf_zebra.h b/ospfd/ospf_zebra.h
index 3efd8958..b6419c8b 100644
--- a/ospfd/ospf_zebra.h
+++ b/ospfd/ospf_zebra.h
@@ -56,7 +56,7 @@ extern int ospf_redistribute_check (struct ospf *, struct external_info *,
int *);
extern int ospf_distribute_check_connected (struct ospf *,
struct external_info *);
-extern void ospf_distribute_list_update (struct ospf *, int);
+extern void ospf_distribute_list_update (struct ospf *, unsigned long);
extern int ospf_is_type_redistributed (int);
extern void ospf_distance_reset (struct ospf *);
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 1f32a484..35c6b02b 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -231,7 +231,7 @@ ospf_new (void)
}
new->t_read = thread_add_read (master, ospf_read, new, new->fd);
new->oi_write_q = list_new ();
-
+ new->hostlist = list_new(); /* host route list */
return new;
}
@@ -401,6 +401,7 @@ ospf_finish_final (struct ospf *ospf)
struct ospf_lsa *lsa;
struct ospf_interface *oi;
struct ospf_area *area;
+ struct ospf_host_route *host;
struct ospf_vl_data *vl_data;
struct listnode *node, *nnode;
int i;
@@ -471,6 +472,12 @@ ospf_finish_final (struct ospf *ospf)
ospf_area_free (area);
}
+ for (ALL_LIST_ELEMENTS (ospf->hostlist, node, nnode, host))
+ {
+ listnode_delete (ospf->hostlist, host);
+ XFREE (MTYPE_OSPF_TOP, host);
+ }
+
/* Cancel all timers. */
OSPF_TIMER_OFF (ospf->t_external_lsa);
OSPF_TIMER_OFF (ospf->t_router_lsa_update);
@@ -646,8 +653,32 @@ ospf_area_free (struct ospf_area *area)
void
ospf_area_check_free (struct ospf *ospf, struct in_addr area_id)
{
+ struct interface *ifp;
+ struct listnode *node;
+ struct ospf_if_params *params;
+ struct route_node *rn;
+ struct ospf_network *network;
+ struct ospf_host_route *host;
struct ospf_area *area;
+ /* Check if any interface is a member of this area */
+ for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
+ {
+ params = IF_DEF_PARAMS (ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
+ && IPV4_ADDR_SAME (&area_id, &params->if_area))
+ return;
+ }
+ /* Check if any network is a member of this area */
+ for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
+ {
+ network = rn->info;
+ if (network && IPV4_ADDR_SAME (&area_id, &network->area_id))
+ {
+ route_unlock_node (rn);
+ return;
+ }
+ }
area = ospf_area_lookup_by_area_id (ospf, area_id);
if (area &&
listcount (area->oiflist) == 0 &&
@@ -660,6 +691,9 @@ ospf_area_check_free (struct ospf *ospf, struct in_addr area_id)
IMPORT_NAME (area) == NULL &&
area->auth_type == OSPF_AUTH_NULL)
{
+ for (ALL_LIST_ELEMENTS_RO (area->ospf->hostlist, node, host))
+ if (!host->area || host->area == area)
+ return;
listnode_delete (ospf->areas, area);
ospf_area_free (area);
}
@@ -701,6 +735,67 @@ ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi)
listnode_add (area->oiflist, oi);
}
+void add_ospf_interface(struct interface *ifp, struct ospf_area *area,
+ struct connected *co)
+{
+ struct ospf_interface *oi;
+
+ oi = ospf_if_new (area->ospf, ifp, co->address);
+ oi->connected = co;
+
+ oi->area = area;
+
+ oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
+ oi->output_cost = ospf_if_get_output_cost (oi);
+
+ /* Add pseudo neighbor. */
+ ospf_nbr_add_self (oi);
+
+ /* Relate ospf interface to ospf instance. */
+ oi->ospf = area->ospf;
+
+ /* update network type as interface flag */
+ /* If network type is specified previously,
+ skip network type setting. */
+ oi->type = IF_DEF_PARAMS (ifp)->type;
+
+ ospf_area_add_if (oi->area, oi);
+
+ /* if router_id is not configured, dont bring up
+ * interfaces.
+ * ospf_router_id_update() will call ospf_if_update
+ * whenever r-id is configured instead.
+ */
+ if ((area->ospf->router_id.s_addr != 0)
+ && if_is_operative (ifp))
+ ospf_if_up (oi);
+}
+
+void update_redistributed(struct ospf *ospf, int add_to_ospf)
+{
+ struct route_node *rn;
+ struct external_info *ei;
+
+ if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
+ if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
+ for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
+ rn; rn = route_next (rn))
+ if ((ei = rn->info) != NULL)
+ if (add_to_ospf)
+ {
+ if (ospf_external_info_find_lsa (ospf, &ei->p))
+ if (!ospf_distribute_check_connected (ospf, ei))
+ ospf_external_lsa_flush (ospf, ei->type, &ei->p,
+ ei->ifindex /*, ei->nexthop */);
+ }
+ else
+ {
+ if (!ospf_external_info_find_lsa (ospf, &ei->p))
+ if (ospf_distribute_check_connected (ospf, ei))
+ ospf_external_lsa_originate (ospf, ei);
+ }
+}
+
void
ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi)
{
@@ -754,16 +849,7 @@ ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
ospf_network_run ((struct prefix *)p, area);
/* Update connected redistribute. */
- if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
- if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
- for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
- rn; rn = route_next (rn))
- if ((ei = rn->info) != NULL)
- if (ospf_external_info_find_lsa (ospf, &ei->p))
- if (!ospf_distribute_check_connected (ospf, ei))
- ospf_external_lsa_flush (ospf, ei->type, &ei->p,
- ei->ifindex /*, ei->nexthop */);
-
+ update_redistributed(ospf, 1); /* interfaces possibly added */
ospf_area_check_free (ospf, area_id);
return 1;
@@ -795,12 +881,17 @@ ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
/* Find interfaces that not configured already. */
for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
{
+ struct ospf_if_params *params;
int found = 0;
struct connected *co = oi->connected;
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- continue;
-
+ continue;
+
+ params = IF_DEF_PARAMS (oi->ifp);
+ if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
+ continue;
+
for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
{
if (rn->info == NULL)
@@ -819,18 +910,103 @@ ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
}
/* Update connected redistribute. */
- if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
- if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
- for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
- rn; rn = route_next (rn))
- if ((ei = rn->info) != NULL)
- if (!ospf_external_info_find_lsa (ospf, &ei->p))
- if (ospf_distribute_check_connected (ospf, ei))
- ospf_external_lsa_originate (ospf, ei);
+ update_redistributed(ospf, 0); /* interfaces possibly removed */
+ return 1;
+}
+
+int
+ospf_interface_set (struct interface *ifp)
+{
+ struct ospf_area *area;
+ struct route_node *rn;
+ struct external_info *ei;
+ struct listnode *cnode;
+ struct connected *co;
+ struct ospf *ospf;
+ struct ospf_if_params *params;
+ struct in_addr area_id;
+ int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
+
+ if ((ospf = ospf_lookup ()) == NULL)
+ return 1; /* Ospf not ready yet */
+
+ params = IF_DEF_PARAMS (ifp);
+ area_id = params->if_area;
+
+ area = ospf_area_get (ospf, area_id, ret);
+
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, co))
+ {
+ struct ospf_interface *oi;
+
+ if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY))
+ continue;
+
+ oi = ospf_if_table_lookup(ifp, co->address);
+ if (oi)
+ { /* Just adjust area for existing interface */
+ ospf_area_del_if (oi->area, oi);
+ oi->area = area;
+ ospf_area_add_if (oi->area, oi);
+ }
+ else
+ {
+ add_ospf_interface(ifp, area, co);
+ }
+ }
+
+ /* Update connected redistribute. */
+ update_redistributed(ospf, 1); /* interface possibly added */
+ ospf_area_check_free (ospf, area_id);
+
+ return 1;
+}
+
+int
+ospf_interface_unset (struct interface *ifp)
+{
+ struct route_node *rn_oi, *rn;
+ struct ospf *ospf;
+
+ if ((ospf = ospf_lookup ()) == NULL)
+ return 1; /* Ospf not ready yet */
+
+ /* Find interfaces that may need to be removed. */
+ for (rn_oi = route_top (IF_OIFS (ifp)); rn_oi; rn_oi = route_next (rn_oi))
+ {
+ struct ospf_interface *oi;
+ struct connected *co;
+ int found = 0;
+
+ if ( (oi = rn_oi->info) == NULL)
+ continue;
+ if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
+ continue;
+ co = oi->connected;
+
+ for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
+ {
+ if (rn->info == NULL)
+ continue;
+
+ if (ospf_network_match_iface(co,&rn->p))
+ {
+ found = 1;
+ route_unlock_node (rn);
+ break;
+ }
+ }
+ if (found == 0)
+ ospf_if_free (oi);
+ }
+
+ /* Update connected redistribute. */
+ update_redistributed(ospf, 0); /* interfaces possibly removed */
return 1;
}
+
/* Check whether interface matches given network
* returns: 1, true. 0, false
*/
@@ -862,39 +1038,9 @@ ospf_network_run_interface (struct prefix *p, struct ospf_area *area,
if (p->family == co->address->family
&& ! ospf_if_table_lookup(ifp, co->address)
&& ospf_network_match_iface(co,p))
- {
- struct ospf_interface *oi;
-
- oi = ospf_if_new (area->ospf, ifp, co->address);
- oi->connected = co;
-
- oi->area = area;
-
- oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
- oi->output_cost = ospf_if_get_output_cost (oi);
-
- /* Add pseudo neighbor. */
- ospf_nbr_add_self (oi);
-
- /* Relate ospf interface to ospf instance. */
- oi->ospf = area->ospf;
-
- /* update network type as interface flag */
- /* If network type is specified previously,
- skip network type setting. */
- oi->type = IF_DEF_PARAMS (ifp)->type;
-
- ospf_area_add_if (oi->area, oi);
-
- /* if router_id is not configured, dont bring up
- * interfaces.
- * ospf_router_id_update() will call ospf_if_update
- * whenever r-id is configured instead.
- */
- if ((area->ospf->router_id.s_addr != 0)
- && if_is_operative (ifp))
- ospf_if_up (oi);
- }
+ {
+ add_ospf_interface(ifp, area, co);
+ }
}
}
@@ -953,15 +1099,22 @@ ospf_if_update (struct ospf *ospf, struct interface *ifp)
/* OSPF must be on and Router-ID must be configured. */
if (!ospf || ospf->router_id.s_addr == 0)
return;
-
- /* Run each netowrk for this interface. */
- for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
- if (rn->info != NULL)
- {
- network = (struct ospf_network *) rn->info;
- area = ospf_area_get (ospf, network->area_id, network->format);
- ospf_network_run_interface (&rn->p, area, ifp);
- }
+
+ if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS (ifp), if_area))
+ {
+ ospf_interface_set (ifp);
+ }
+ else
+ {
+ /* Run each netowrk for this interface. */
+ for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
+ if (rn->info != NULL)
+ {
+ network = (struct ospf_network *) rn->info;
+ area = ospf_area_get (ospf, network->area_id, network->format);
+ ospf_network_run_interface (&rn->p, area, ifp);
+ }
+ }
}
void
@@ -1205,6 +1358,7 @@ ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id,
return 1;
}
+#if 0
/* XXX: unused? Leave for symmetry? */
static int
ospf_area_nssa_translator_role_unset (struct ospf *ospf,
@@ -1222,6 +1376,7 @@ ospf_area_nssa_translator_role_unset (struct ospf *ospf,
return 1;
}
+#endif
int
ospf_area_export_list_set (struct ospf *ospf,
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index b24b3ced..6cde1099 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -48,7 +48,9 @@
#define OSPF_VL_IP_TTL 100
/* Default configuration file name for ospfd. */
-#define OSPF_DEFAULT_CONFIG "ospfd.conf"
+#define OSPF_CONFIG_NAME "ospfd.conf"
+#define OSPF_PID_NAME "ospfd.pid"
+#define OSPF_VTY_NAME "ospfd.vty"
/* Architectual Constants */
#ifdef DEBUG
@@ -272,6 +274,9 @@ struct ospf
struct stream *ibuf;
struct list *oi_write_q;
+ /* queue for AS-External route calculation */
+ struct work_queue *ase_calc_queue;
+
/* Distribute lists out of other route sources. */
struct
{
@@ -327,6 +332,9 @@ struct ospf
u_int32_t rx_lsa_count;
struct route_table *distance_table;
+
+ /* Host route list */
+ struct list *hostlist;
};
/* OSPF area structure. */
@@ -607,6 +615,9 @@ extern struct ospf_area *ospf_area_lookup_by_area_id (struct ospf *,
extern void ospf_area_add_if (struct ospf_area *, struct ospf_interface *);
extern void ospf_area_del_if (struct ospf_area *, struct ospf_interface *);
+extern int ospf_interface_set (struct interface *ifp);
+extern int ospf_interface_unset (struct interface *ifp);
+
extern void ospf_route_map_init (void);
extern void ospf_snmp_init (void);
diff --git a/pimd/.gitignore b/pimd/.gitignore
new file mode 100644
index 00000000..b27998ea
--- /dev/null
+++ b/pimd/.gitignore
@@ -0,0 +1,19 @@
+Makefile
+Makefile.in
+*.o
+pimd
+test_igmpv3_join
+pimd.conf
+libpim.a
+tags
+TAGS
+.deps
+.nfs*
+*.lo
+*.la
+*.libs
+.arch-inventory
+.arch-ids
+*~
+*.loT
+
diff --git a/pimd/AUTHORS b/pimd/AUTHORS
new file mode 100644
index 00000000..f6135a41
--- /dev/null
+++ b/pimd/AUTHORS
@@ -0,0 +1,9 @@
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+# Everton da Silva Marques <everton.marques@gmail.com>
+$ more ~/.gitconfig
+[user]
+ name = Everton Marques
+ email = everton.marques@gmail.com
+
+-x-
diff --git a/pimd/CAVEATS b/pimd/CAVEATS
new file mode 100644
index 00000000..c436d552
--- /dev/null
+++ b/pimd/CAVEATS
@@ -0,0 +1,137 @@
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+C1 IGMPv3 backward compatibility with IGMPv1 and IGMPv2 is not
+ implemented. See RFC 3376, 7.3. Multicast Router Behavior. That's
+ because only Source-Specific Multicast is currently targeted.
+
+C2 IGMPv3 support for forwarding any-source groups is not
+ implemented. Traffic for groups in mode EXCLUDE {empty} won't be
+ forwarded. See RFC 3376, 6.3. Source-Specific Forwarding
+ Rules. That's because only Source-Specific Multicast is currently
+ targeted.
+
+C3 Load Splitting of IP Multicast Traffic over ECMP is not supported.
+ See also: RFC 2991
+ Multipath Issues in Unicast and Multicast Next-Hop Selection
+ http://www.rfc-editor.org/rfc/rfc2991.txt
+
+C4 IPSec AH authentication is not supported (RFC 4601:
+ 6.3. Authentication Using IPsec).
+
+C5 PIM support is limited to SSM mode as defined in section 4.8.2
+ (PIM-SSM-Only Routers) of RFC4601. That's because only
+ Source-Specific Multicast is currently targeted.
+
+C6 PIM implementation currently does not support IPv6. PIM-SSM
+ requires IGMPv3 for IPv4 and MLDv2 for IPv6. MLDv2 is currently
+ missing. See also CAVEAT C9.
+
+C7 FIXED (S,G) Assert state machine (RFC 4601, section 4.6.1) is not
+ implemented. See also TODO T6. See also CAVEAT C10.
+
+C8 It is not possible to disable join suppression in order to
+ explicitly track the join membership of individual downstream
+ routers.
+ - IGMPv3 Explicit Membership Tracking is not supported.
+ When explicit tracking is enabled on a router, the router can
+ individually track the Internet Group Management Protocol (IGMP)
+ membership state of all reporting hosts. This feature allows the
+ router to achieve minimal leave latencies when hosts leave a
+ multicast group or channel. Example:
+ conf t
+ interface eth0
+ ip igmp explicit-tracking
+
+C9 Only IPv4 Address Family (number=1) is supported in the PIM Address
+ Family field.
+ See also RFC 4601: 5.1. PIM Address Family
+ See also CAVEAT C6.
+ See also http://www.iana.org/assignments/address-family-numbers
+
+C10 FIXED Assert metric depends on metric_preference and
+ route_metric. Those parameters should be fetched from RIB
+ (zebra). See also pim_rpf.c, pim_rpf_update().
+
+C11 SSM Mapping is not supported
+
+ SSM Mapping Overview:
+
+ SSM mapping introduces a means for the last hop router to discover
+ sources sending to groups. When SSM mapping is configured, if a
+ router receives an IGMPv1 or IGMPv2 membership report for a
+ particular group G, the router translates this report into one or
+ more (S, G) channel memberships for the well-known sources
+ associated with this group.
+
+ When the router receives an IGMPv1 or IGMPv2 membership report for
+ a group G, the router uses SSM mapping to determine one or more
+ source IP addresses for the group G. SSM mapping then translates
+ the membership report as an IGMPv3 report INCLUDE (G, [S1, G],
+ [S2, G]...[Sn, G] and continues as if it had received an IGMPv3
+ report. The router then sends out PIM joins toward (S1, G) to (Sn,
+ G) and continues to be joined to these groups as long as it
+ continues to receive the IGMPv1 or IGMPv2 membership reports and
+ as long as the SSM mapping for the group remains the same. SSM
+ mapping, thus, enables you to leverage SSM for video delivery to
+ legacy STBs that do not support IGMPv3 or for applications that do
+ not take advantage of the IGMPv3 host stack.
+
+ SSM mapping enables the last hop router to determine the source
+ addresses either by a statically configured table on the router or
+ by consulting a DNS server. When the statically configured table
+ is changed, or when the DNS mapping changes, the router will leave
+ the current sources associated with the joined groups.
+
+C12 MRIB for incongruent unicast/multicast topologies is not supported.
+ RPF mechanism currently just looks up the information in the
+ unicast routing table.
+
+ See also:
+ RFC5110: 2.2.3. Issue: Overlapping Unicast/Multicast Topology
+
+ Sometimes, multicast RPF mechanisms first look up the multicast
+ routing table, or M-RIB ("topology database") with a longest
+ prefix match algorithm, and if they find any entry (including a
+ default route), that is used; if no match is found, the unicast
+ routing table is used instead.
+
+C13 Can't detect change of primary address before the actual change.
+ Possible approach is to craft old interface address into ip source
+ address by using raw ip socket.
+
+ See also:
+
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Before an interface goes down or changes primary IP address, a
+ Hello message with a zero HoldTime should be sent immediately
+ (with the old IP address if the IP address changed).
+
+ See also pim_sock_delete().
+
+C14 Detection of interface primary address changes may fail when there
+ are multiple addresses.
+ See also TODO T32.
+
+C15 Changes in interface secondary address list are not immediately
+ detected.
+ See also TODO T31.
+
+C16 AMT Draft (mboned-auto-multicast) is not supported.
+ AMT = Automatic IP Multicast Without Explicit Tunnels
+
+ See also:
+
+ Draft
+ http://tools.ietf.org/html/draft-ietf-mboned-auto-multicast
+ http://tools.ietf.org/html/draft-ietf-mboned-auto-multicast-09
+
+ AMT gateway implementation for Linux
+ http://cs.utdallas.edu/amt/
+
+ AMT for Streaming (IPTV) on Global IP Multicast by Greg Shepherd (Cisco)
+ http://nznog.miniconf.org/nznog-2008-sysadmin-miniconf-greg-shepherd-iptv.pdf
+
+C17 SNMP / RFC 5060 (PIM MIB) is not supported.
+
+-x-
diff --git a/pimd/COMMANDS b/pimd/COMMANDS
new file mode 100644
index 00000000..8cfa671e
--- /dev/null
+++ b/pimd/COMMANDS
@@ -0,0 +1,66 @@
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+global configuration commands:
+ ip multicast-routing Enable IP multicast forwarding
+ ip ssmpingd Enable ssmpingd operation
+
+interface configuration commands:
+ ip igmp Enable IGMP operation
+ ip igmp join IGMP join multicast group
+ ip igmp query-interval <1-1800> IGMP host query interval
+ ip igmp query-max-response-time <1-25> IGMP max query response (seconds)
+ ip igmp query-max-response-time-dsec <10-250> IGMP max query response (deciseconds)
+ ip pim ssm Enable PIM SSM operation
+
+verification commands:
+ show ip igmp interface IGMP interface information
+ show ip igmp parameters IGMP parameters information
+ show ip igmp groups IGMP groups information
+ show ip igmp groups retransmissions IGMP group retransmission
+ show ip igmp sources IGMP sources information
+ show ip igmp sources retransmissions IGMP source retransmission
+ show ip pim address PIM interface address
+ show ip pim assert PIM interface assert
+ show ip pim assert-internal PIM interface internal assert state
+ show ip pim assert-metric PIM interface assert metric
+ show ip pim assert-winner-metric PIM interface assert winner metric
+ show ip pim designated-router PIM interface designated router
+ show ip pim hello PIM interface hello information
+ show ip pim interface PIM interface information
+ show ip pim lan-prune-delay PIM neighbors LAN prune delay parameters
+ show ip pim local-membership PIM interface local-membership
+ show ip pim jp-override-interval PIM interface J/P override interval
+ show ip pim join PIM interface join information
+ show ip pim neighbor PIM neighbor information
+ show ip pim rpf PIM cached source rpf information
+ show ip pim secondary PIM neighbor addresses
+ show ip pim upstream PIM upstream information
+ show ip pim upstream-join-desired PIM upstream join-desired
+ show ip pim upstream-rpf PIM upstream source rpf
+ show ip multicast Multicast global information
+ show ip mroute IP multicast routing table
+ show ip mroute count Route and packet count data
+ show ip route IP routing table
+ show ip ssmpingd ssmpingd operation
+
+debug commands:
+ clear ip interfaces Reset interfaces
+ clear ip igmp interfaces Reset IGMP interfaces
+ clear ip pim interfaces Reset PIM interfaces
+ debug igmp IGMP protocol activity
+ debug pim PIM protocol activity
+ debug pim zebra ZEBRA protocol activity
+ debug ssmpingd ssmpingd activity
+ show debugging State of each debugging option
+ test igmp receive report Test reception of IGMPv3 report
+ test pim receive assert Test reception of PIM assert
+ test pim receive dump Test reception of PIM packet dump
+ test pim receive hello Test reception of PIM hello
+ test pim receive join Test reception of PIM join
+ test pim receive prune Test reception of PIM prune
+ test pim receive upcall Test reception of kernel upcall
+
+statistics commands:
+ show memory pim PIM memory statistics
+
+-x-
diff --git a/pimd/COPYING b/pimd/COPYING
new file mode 100644
index 00000000..3912109b
--- /dev/null
+++ b/pimd/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/pimd/DEBUG b/pimd/DEBUG
new file mode 100644
index 00000000..119c46f5
--- /dev/null
+++ b/pimd/DEBUG
@@ -0,0 +1,61 @@
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+DEBUG HINTS
+
+ - Check the source is issuing multicast packets with TTL high enough
+ to reach the recipients.
+
+ - Check the multicast packets are not being dropped due to
+ fragmentation problems.
+
+ - Two easy options to test IGMPv3 joins from the receiver host:
+
+ 1) Configure pimd on the receiver host with "ip igmp join":
+
+ interface eth0
+ ip pim ssm
+ ip igmp join 239.1.1.1 1.1.1.1
+
+ 2) Use the test_igmpv3_join command-line utility:
+
+ test_igmpv3_join eth0 239.1.1.1 1.1.1.1
+
+ - The following command generates a 100-kbps multicast stream for
+ channel 1.1.1.1,239.1.1.1 with TTL 10 and 1000-byte payload per UDP
+ packet (to avoid fragmentation):
+
+ nepim -b 1.1.1.1 -c 239.1.1.1 -T 10 -W 1000 -r 100k -a 1d
+
+ - Remotely you can receive that stream by running:
+
+ nepim -j 1.1.1.1+239.1.1.1@eth0
+ (Remember of enabling both "ip pim ssm" and "ip igmp" under eth0.)
+
+
+SAMPLE DEBUG COMMANDS
+
+ conf t
+ int eth0
+ ip pim ssm
+
+ test pim receive hello eth0 192.168.0.2 600 10 111 1000 3000 0
+ test pim receive join eth0 600 192.168.0.1 192.168.0.2 239.1.1.1 1.1.1.1
+
+ show ip pim join
+
+
+INTEROPERABILITY WITH CISCO
+
+ ! Cisco IP Multicast command reference:
+ ! ftp://ftpeng.cisco.com/ipmulticast/Multicast-Commands
+ !
+ ip pim ssm default ! enable SSM mode for groups 232.0.0.0/8
+ ip multicast-routing
+ ip pim state-refresh disable
+ no ip pim dm-fallback
+ !
+ interface FastEthernet0
+ ip pim sparse-mode
+ ip igmp version 3
+
+-x-
diff --git a/pimd/LINUX_KERNEL_MROUTE_MFC b/pimd/LINUX_KERNEL_MROUTE_MFC
new file mode 100644
index 00000000..e87e567f
--- /dev/null
+++ b/pimd/LINUX_KERNEL_MROUTE_MFC
@@ -0,0 +1,26 @@
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+#
+# The Linux Kernel MFC (Multicast Forwarding Cache)
+#
+
+# Check Linux kernel multicast interfaces:
+cat /proc/net/dev_mcast
+
+# Check that interface eth0 is forwarding multicast:
+cat /proc/sys/net/ipv4/conf/eth0/mc_forwarding
+
+# Check Linux kernel multicast VIFs:
+cat /proc/net/ip_mr_vif
+Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote
+
+# Check Linux kernel MFC:
+# Oifs format = vifi:TTL
+cat /proc/net/ip_mr_cache
+Group Origin Iif Pkts Bytes Wrong Oifs
+
+# iproute2 can display the MFC:
+ip mroute show
+(2.2.2.2, 239.2.2.2) Iif: eth1 Oifs: eth0
+
+# -- end-of-file --
diff --git a/pimd/Makefile.am b/pimd/Makefile.am
new file mode 100644
index 00000000..4aae6378
--- /dev/null
+++ b/pimd/Makefile.am
@@ -0,0 +1,76 @@
+## Process this file with automake to produce Makefile.in.
+## $QuaggaId: $Format:%an, %ai, %h$ $
+
+# qpimd - pimd for quagga
+# Copyright (C) 2008 Everton da Silva Marques
+#
+# qpimd is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2,
+# or (at your option) any later version.
+#
+# qpimd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with qpimd; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 59 Temple Place - Suite
+# 330, Boston, MA 02111-1307, USA.
+
+# PIM_DEBUG_BYDEFAULT: Automatically enables all pimd "debug ..." commands
+# PIM_ZCLIENT_DEBUG: Support for internal ZEBRA client debugging
+# PIM_MOTD_VERSION: Includes pimd version in default MOTD
+# PIM_USE_QUAGGA_INET_CHECKSUM: Prefer Quagga inet checksum
+# PIM_CHECK_RECV_IFINDEX_SANITY: Compare socket ifindex with recv ifindex
+# PIM_REPORT_RECV_IFINDEX_MISMATCH: Report sock/recv ifindex mismatch
+# PIM_ENFORCE_LOOPFREE_MFC: Refuse adding looping MFC entries
+# PIM_UNEXPECTED_KERNEL_UPCALL: Report unexpected kernel upcall
+
+PIM_DEFS =
+#PIM_DEFS += -DPIM_DEBUG_BYDEFAULT
+PIM_DEFS += -DPIM_CHECK_RECV_IFINDEX_SANITY
+#PIM_DEFS += -DPIM_REPORT_RECV_IFINDEX_MISMATCH
+PIM_DEFS += -DPIM_ZCLIENT_DEBUG
+PIM_DEFS += -DPIM_MOTD_VERSION
+PIM_DEFS += -DPIM_USE_QUAGGA_INET_CHECKSUM
+PIM_DEFS += -DPIM_ENFORCE_LOOPFREE_MFC
+#PIM_DEFS += -DPIM_UNEXPECTED_KERNEL_UPCALL
+
+INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib
+DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" $(PIM_DEFS)
+INSTALL_SDATA=@INSTALL@ -m 600
+LIBS = @LIBS@
+noinst_LIBRARIES = libpim.a
+sbin_PROGRAMS = pimd
+bin_PROGRAMS = test_igmpv3_join
+
+libpim_a_SOURCES = \
+ pimd.c pim_version.c pim_cmd.c pim_signals.c pim_iface.c \
+ pim_vty.c pim_igmp.c pim_sock.c pim_zebra.c \
+ pim_igmpv3.c pim_str.c pim_mroute.c pim_util.c pim_time.c \
+ pim_oil.c pim_zlookup.c pim_pim.c pim_tlv.c pim_neighbor.c \
+ pim_hello.c pim_ifchannel.c pim_join.c pim_assert.c \
+ pim_msg.c pim_upstream.c pim_rpf.c pim_rand.c pim_macro.c \
+ pim_igmp_join.c pim_ssmpingd.c pim_int.c
+
+noinst_HEADERS = \
+ pimd.h pim_version.h pim_cmd.h pim_signals.h pim_iface.h \
+ pim_vty.h pim_igmp.h pim_sock.h pim_zebra.h \
+ pim_igmpv3.h pim_str.h pim_mroute.h pim_util.h pim_time.h \
+ pim_oil.h pim_zlookup.h pim_pim.h pim_tlv.h pim_neighbor.h \
+ pim_hello.h pim_ifchannel.h pim_join.h pim_assert.h \
+ pim_msg.h pim_upstream.h pim_rpf.h pim_rand.h pim_macro.h \
+ pim_igmp_join.h pim_ssmpingd.h pim_int.h
+
+pimd_SOURCES = \
+ pim_main.c $(libpim_a_SOURCES)
+
+test_igmpv3_join_SOURCES = \
+ test_igmpv3_join.c pim_igmp_join.c
+
+pimd_LDADD = ../lib/libzebra.la @LIBCAP@
+
+examplesdir = $(exampledir)
+dist_examples_DATA = pimd.conf.sample
diff --git a/pimd/README b/pimd/README
new file mode 100644
index 00000000..e42ceda2
--- /dev/null
+++ b/pimd/README
@@ -0,0 +1,157 @@
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+#
+
+INTRODUCTION
+
+ qpimd aims to implement a PIM (Protocol Independent Multicast)
+ daemon for the Quagga Routing Suite.
+
+ Initially qpimd targets only PIM SSM (Source-Specific
+ Multicast) mode as defined in section 4.8.2 (PIM-SSM-Only
+ Routers) of RFC 4601.
+
+ In order to deliver end-to-end multicast routing control
+ plane, qpimd includes the router-side of IGMPv3 (RFC 3376).
+
+LICENSE
+
+ qpimd - pimd for quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ qpimd is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2,
+ or (at your option) any later version.
+
+ qpimd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with qpimd; see the file COPYING. If not, write
+ to the Free Software Foundation, Inc., 59 Temple Place - Suite
+ 330, Boston, MA 02111-1307, USA.
+
+HOME SITE
+
+ qpimd lives at:
+
+ http://savannah.nongnu.org/projects/qpimd
+
+PLATFORMS
+
+ qpimd has been tested with Debian Lenny under Linux 2.6.
+
+REQUIREMENTS
+
+ qpimd requires Quagga (0.99.11 or higher from http://www.quagga.net)
+
+ The GNU Build System (Autotools) is required to build from
+ source code repository.
+
+ gawk is also needed to build with Autotools. Any other awk
+ usually won't work.
+
+BUILDING FROM QUAGGA GIT REPOSITORY
+
+ 1) Get the latest quagga source tree
+
+ # git clone git://code.quagga.net/quagga.git quagga
+
+ 2) Apply qpimd patch into quagga source tree
+
+ # patch -p1 -d quagga < pimd-0.153-quagga-git20090623.patch
+
+ 3) Compile and install quagga
+
+ # cd quagga
+ # ./bootstrap.sh
+ # ./configure --prefix=/usr/local/quagga --enable-pimd
+ # make
+ # make install
+
+BUILDING FROM QUAGGA TARBALL
+
+ 1) Get the latest quagga tarball
+
+ # wget http://www.quagga.net/download/quagga-0.99.13.tar.gz
+
+ 2) Unpack the quagga tarball
+
+ # tar xzf quagga-0.99.13.tar.gz
+
+ 3) Apply qpimd patch into quagga source tree
+
+ # patch -p1 -d quagga-0.99.13 < pimd-0.153-quagga-0.99.13.patch
+
+ 4) Compile and install quagga
+
+ # cd quagga-0.99.13
+ # ./configure --prefix=/usr/local/quagga --enable-pimd
+ # make
+ # make install
+
+USAGE
+
+ 1) Configure and start the zebra daemon
+
+ # cp /usr/local/quagga/etc/zebra.conf.sample /usr/local/quagga/etc/zebra.conf
+ # vi /usr/local/quagga/etc/zebra.conf
+ # /usr/local/quagga/sbin/zebra
+
+ 2) Configure and start the pimd daemon
+
+ # cp /usr/local/quagga/etc/pimd.conf.sample /usr/local/quagga/etc/pimd.conf
+ # vi /usr/local/quagga/etc/pimd.conf
+ # /usr/local/quagga/sbin/pimd
+
+ 3) Access pimd vty interface at port TCP 2611
+
+ # telnet localhost 2611
+
+CONFIGURATION COMMANDS
+
+ See available commands in the file pimd/COMMANDS.
+
+KNOWN CAVEATS
+
+ See list of known caveats in the file pimd/CAVEATS.
+
+SUPPORT
+
+ Please post comments, questions, patches, bug reports at the
+ support site:
+
+ http://savannah.nongnu.org/projects/qpimd
+
+RELATED WORK
+
+ igmprt: An IGMPv3-router implementation
+ - http://www.loria.fr/~lahmadi/igmpv3-router.html
+
+ pimd: PIMv2-SM daemon
+ - http://netweb.usc.edu/pim/pimd (URL broken in 2008-12-23)
+ - http://packages.debian.org/source/sid/pimd (from Debian)
+
+ zpimd: zpimd is not dependent of zebra or any other routing daemon
+ - ftp://robur.slu.se/pub/Routing/Zebra
+ - http://sunsite2.icm.edu.pl/pub/unix/routing/zpimd
+
+ mrd6: an IPv6 Multicast Router for Linux systems
+ - http://fivebits.net/proj/mrd6/
+
+ MBGP: Implementation of RFC 2858 for Quagga
+ - git://git.coplanar.net/~balajig/quagga
+ - http://www.gossamer-threads.com/lists/quagga/dev/18000
+
+REFERENCES
+
+ IANA Protocol Independent Multicast (PIM) Parameters
+ http://www.iana.org/assignments/pim-parameters/pim-parameters.txt
+
+ Address Family Numbers
+ http://www.iana.org/assignments/address-family-numbers
+
+ -- END --
diff --git a/pimd/TODO b/pimd/TODO
new file mode 100644
index 00000000..1dc561dd
--- /dev/null
+++ b/pimd/TODO
@@ -0,0 +1,373 @@
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+T1 DONE Implement debug command
+ test pim receive join
+
+T2 DONE Implement debug command
+ test pim receive prune
+
+T3 DONE Per-interface Downstream (S,G) state machine
+ (RFC 4601 4.5.3. Receiving (S,G) Join/Prune Messages)
+
+T4 DONE Upstream (S,G) state machine
+ (RFC 4601 4.5.7. Sending (S,G) Join/Prune Messages)
+
+T5 DONE Verify Data Packet Forwarding Rules
+ RFC 4601 4.2. Data Packet Forwarding Rules
+ RFC 4601 4.8.2. PIM-SSM-Only Routers
+
+ Additionally, the Packet forwarding rules of Section 4.2 can be
+ simplified in a PIM-SSM-only router:
+
+ iif is the incoming interface of the packet.
+ oiflist = NULL
+ if (iif == RPF_interface(S) AND UpstreamJPState(S,G) == Joined) {
+ oiflist = inherited_olist(S,G)
+ } else if (iif is in inherited_olist(S,G)) {
+ send Assert(S,G) on iif
+ }
+ oiflist = oiflist (-) iif
+ forward packet on all interfaces in oiflist
+
+ Macro:
+ inherited_olist(S,G) =
+ joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
+
+T6 DONE Implement (S,G) Assert state machine (RFC 4601, section 4.6.1).
+ Changes in pim_ifchannel.ifassert_winner should trigger
+ pim_upstream_update_join_desired().
+ Depends on TODO T27.
+ Depends on TODO T33.
+ See also CAVEAT C7.
+ See also: RFC 4601 4.5.7. Sending (S,G) Join/Prune Messages
+ Transitions from Joined State
+ RPF'(S,G) changes due to an Assert
+
+ http://www.hep.ucl.ac.uk/~ytl/multi-cast/pim-dm_01.html:
+
+ The PIM Assert mechanism is used to shutoff duplicate flows onto
+ the same multiaccess network. Routers detect this condiction when
+ they receive an (S,G) packet via a multi-access interface that is
+ in the (S,G) OIL. This causes the routers to send Assert
+ Messages.
+
+ Note that neighbors will not accept Join/Prune or Assert messages
+ from a router unless they have first heard a Hello message from that
+ router. Thus, if a router needs to send a Join/Prune or Assert
+ message on an interface on which it has not yet sent a Hello message
+ with the currently configured IP address, then it MUST immediately
+ send the relevant Hello message without waiting for the Hello Timer
+ to expire, followed by the Join/Prune or Assert message.
+
+T7 DONE Implement hello option: LAN Prune Delay
+
+T8 DONE Implement J/P_Override_Interval(I)
+ Depends on TODO T7.
+ See pim_ifchannel.c, pim_ifchannel_prune(), jp_override_interval.
+
+T9 DONE Detect change in IGMPv3 RPF interface/next-hop for S and update.
+ channel_oil vif index accordingly ?
+ Beware accidentaly adding looped MFC entries (IIF=OIF).
+
+T10 DONE React to (S,G) join directed to another upstream address. See
+ also:
+
+ RFC 4601: 4.5.7. Sending (S,G) Join/Prune Messages
+
+ If a router wishes to propagate a Join(S,G) upstream, it must also
+ watch for messages on its upstream interface from other routers on
+ that subnet, and these may modify its behavior. If it sees a
+ Join(S,G) to the correct upstream neighbor, it should suppress its
+ own Join(S,G). If it sees a Prune(S,G), Prune(S,G,rpt), or
+ Prune(*,G) to the correct upstream neighbor towards S, it should
+ be prepared to override that prune by scheduling a Join(S,G) to be
+ sent almost immediately.
+
+T11 DONE Review protocol modifications for SSM
+ (RFC 4601 4.8.1. Protocol Modifications for SSM Destination
+ Addresses)
+
+T12 DONE Review updates of RPF entries.
+ FIXME pim_upstream.c send_join():
+ Currently only one upstream state is affected by detection of RPF change.
+ RPF change should affect all upstream states sharing the RPF cache.
+
+T13 DONE Check that RFC macros using S,G,RPF_interface(S) are actually
+ implemented with this strategy:
+ rpf_ifch=find_ifch(up->rpf->interface).
+ See pim_rpf.c pim_rpf_find_rpf_addr() for a correct example.
+
+ $ grep -i macro pimd/*.c
+ pimd/pim_iface.c: RFC 4601: 4.1.6. State Summarization Macros
+ pimd/pim_ifchannel.c: RFC 4601: 4.6.5. Assert State Macros
+ pimd/pim_ifchannel.c: RFC 4601: 4.1.6. State Summarization Macros
+ pimd/pim_ifchannel.c: RFC 4601: 4.1.6. State Summarization Macros
+ pimd/pim_ifchannel.c: RFC 4601: 4.6.5. Assert State Macros
+ pimd/pim_ifchannel.c: Macro:
+ pimd/pim_rpf.c: RFC 4601: 4.1.6. State Summarization Macros
+
+T14 DONE Send Assert(S,G) on iif as response to WRONGVIF kernel upcall.
+ See pim_mroute.c mroute_msg().
+
+T15 DONE Interface command to statically join (S,G).
+ interface eth0
+ ip igmp join-group 239.1.1.1 source 1.1.1.1
+
+T16 DONE RPF'(S,G) lookup is not working for S reachable with default route.
+ See "RPF'(S,G) not found" in pim_rpf_update() from pim_rpf.c.
+ Zebra daemon RIB is not reflecting changes in kernel routes
+ accurately?
+
+T17 DONE Prevent CLI from creating bogus interfaces.
+ Example:
+ conf t
+ interface xxx
+
+T18 Consider reliable pim solution (refresh reduction)
+ A Reliable Transport Mechanism for PIM
+ http://tools.ietf.org/wg/pim/draft-ietf-pim-port/
+ PORT=PIM-Over-Reliable-Transport
+
+T19 DONE Fix self as neighbor
+ See mailing list post:
+ http://lists.gnu.org/archive/html/qpimd-users/2009-04/msg00000.html
+
+T20 DONE Fix debug message: "pim_neighbor_update: internal error:
+ trying to replace same prefix list"
+ See mailing list post:
+ http://lists.gnu.org/archive/html/qpimd-users/2009-04/msg00000.html
+
+T21 DONE Clean-up PIM/IGMP interface mismatch debugging
+ See option PIM_CHECK_RECV_IFINDEX_SANITY in pimd/Makefile.am
+ See mailing list post:
+ http://lists.nongnu.org/archive/html/qpimd-users/2009-04/msg00003.html
+
+T22 DONE IGMP must be protected against adding looped MFC entries
+ created by both source and receiver attached to the same
+ interface.
+
+T23 DONE libzebra crash after zclient_lookup_nexthop.
+ See mailing list post:
+ http://lists.nongnu.org/archive/html/qpimd-users/2009-04/msg00008.html
+
+T24 DONE zserv may return recursive routes:
+ - nexthop type is set to ZEBRA_NEXTHOP_IPV4
+ - ifindex is not reported
+ - calls expecting ifindex (fib_lookup_if_vif_index) are disrupted
+ See also this mailing list post:
+ [PATCH 21/21] Link detect and recursive routes
+ http://www.gossamer-threads.com/lists/quagga/dev/17564
+
+T25 DONE Zclient nexthop lookup missing OSPF route to 1.1.1.1/32
+ See also:
+ pim_zlookup.c zclient_lookup_nexthop misses OSPF 1.1.1.1/32
+ zebra/zebra_vty.c show_ip_route_addr_cmd hits OSPF 1.1.1.1/32
+
+T26 DONE Zebra daemon is marking recursive static route as inactive.
+
+ FIXED: zebra daemon was incorrectly marking recursive routes
+ pointing to kernel routes as inactive:
+ zebra/zebra_rib.c nexthop_active_ipv4:
+ -- Original:
+ else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL))
+ -- Fixed:
+ else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL) ||
+ match->type == ZEBRA_ROUTE_KERNEL)
+
+ Old problem description:
+
+ This prevents rib_match_ipv4 from returning its nexthop:
+ client: pim_zlookup.c zclient_read_nexthop
+ server: zebra/zserv.c zsend_ipv4_nexthop_lookup_v2 -> rib_match_ipv4
+
+ Kernel route is injected into zebra in zebra_rib.c rib_add_ipv4
+ Examples:
+ rt_netlink.c:726: rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, flags, &p, gate, src, index, table, metric, 0);
+ rt_netlink.c:864: rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, src, index, table, 0, 0);
+
+ This patch didn't fix the issue:
+ [PATCH 21/21] Link detect and recursive routes
+ http://www.gossamer-threads.com/lists/quagga/dev/17564
+
+ See the example below for the route 2.2.2.2.
+
+bash# route add -host 1.1.1.1 gw 127.0.0.1
+bash# route add -host 2.2.2.2 gw 1.1.1.1
+bash# netstat -nvr
+Kernel IP routing table
+Destination Gateway Genmask Flags MSS Window irtt Iface
+2.2.2.2 1.1.1.1 255.255.255.255 UGH 0 0 0 lo
+1.1.1.1 127.0.0.1 255.255.255.255 UGH 0 0 0 lo
+192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
+0.0.0.0 192.168.0.2 0.0.0.0 UG 0 0 0 eth0
+bash#
+
+zebra# sh ip route
+Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
+ I - ISIS, B - BGP, > - selected route, * - FIB route
+
+K>* 0.0.0.0/0 via 192.168.0.2, eth0
+K>* 1.1.1.1/32 via 127.0.0.1, lo
+K * 2.2.2.2/32 via 1.1.1.1, lo inactive
+C>* 127.0.0.0/8 is directly connected, lo
+C>* 192.168.0.0/24 is directly connected, eth0
+
+quagga-pimd-router# sh ip route 1.1.1.1
+Address NextHop Interface Metric Preference
+1.1.1.1 127.0.0.1 lo 0 0
+quagga-pimd-router#
+quagga-pimd-router# sh ip route 2.2.2.2
+Address NextHop Interface Metric Preference
+2.2.2.2 192.168.0.2 eth0 0 0
+quagga-pimd-router#
+
+T27 DONE Implement debug command
+ test pim receive assert
+ See also TODO T6: (S,G) Assert state machine.
+
+T28 DONE Bad IPv4 address family=02 in Join/Prune dump
+ Reported by Andrew Lunn <andrew.lunn@ascom.ch>
+
+ # 58-byte pim v2 Join/Prune dump
+ # ------------------------------
+ # IPv4 address family=02 is wrong, correct IPv4 address family is 01
+ # See http://www.iana.org/assignments/address-family-numbers
+ #
+ c8XX YY03 : ip src 200.xx.yy.3
+ e000 000d : ip dst 224.0.0.13
+ 9404 0000 : ip router alert option 148.4.0.0
+ 2300 ab13 : pimv2,type=3 res=00 checksum=ab13
+ 0200 : upstream family=02, encoding=00
+ c8XX YY08 : upstream 200.xx.yy.8
+ 0001 00d2 : res=00 groups=01 holdtime=00d2
+ 0200 0020 : group family=02, encoding=00, res=00, mask_len=20
+ ef01 0101 : group address 239.1.1.1
+ 0001 0000 : joined=0001 pruned=0000
+ 0200 0020 : source family=02, encoding=00, res=00, mask_len=20
+ 0101 0101 : source address 1.1.1.1
+
+T29 DONE Reset interface PIM-hello-sent counter when primary address changes
+ See pim_ifp->pim_ifstat_hello_sent
+
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Thus, if a router needs to send a Join/Prune or Assert message on
+ an interface on which it has not yet sent a Hello message with the
+ currently configured IP address, then it MUST immediately send the
+ relevant Hello message without waiting for the Hello Timer to
+ expire, followed by the Join/Prune or Assert message.
+
+T30 DONE Run interface DR election when primary address changes
+ Reported by Andrew Lunn <andrew.lunn@ascom.ch>
+ See pim_if_dr_election().
+
+T31 If an interface changes one of its secondary IP addresses, a Hello
+ message with an updated Address_List option and a non-zero
+ HoldTime should be sent immediately.
+ See also CAVEAT C15.
+ See also RFC 4601: 4.3.1. Sending Hello Messages
+
+T32 Detection of interface primary address changes may fail when there
+ are multiple addresses.
+ See also CAVEAT C14.
+
+ pim_find_primary_addr() should return interface primary address
+ from connected list. Currently it returns the first address.
+
+ Zebra daemon "show int" is able to keep the primary address as
+ first address.
+
+T33 DONE Implement debug command: test pim receive upcall
+ See also TODO T6: (S,G) Assert state machine.
+
+T34 DONE assert_action_a1
+
+T35 DONE Review macros depending on interface I.
+
+ See also: grep ,I\) pimd/*.c
+
+ For the case (S,G,I) check if I is either
+ 1) interface attached to this per-interface S,G state (don't think so)
+ or
+ 2) an arbitrary interface (most probably)
+
+ For the arbitrary interface case (2), consider representing
+ interface ifp as its primary address (struct in_addr ifaddr). The
+ benefit is in_addr does not need to be dereferenced, so it does
+ not demand protection against crashes.
+
+T36 DONE React to zebra daemon link-detect up/down notification.
+ pim_ifp->primary_address is managed by detect_primary_address_change()
+ depending on to ifp->connected (managed by zebra_interface_address_read()).
+
+T37 DONE Review list of variables which may affect pim_upstream.c
+ pim_upstream_evaluate_join_desired().
+ Call pim_upstream_update_join_desired() accordingly.
+
+ See the order of invokation:
+ pim_if_dr_election(ifp);
+ pim_if_update_join_desired(pim_ifp); /* depends on DR */
+ pim_if_update_could_assert(ifp); /* depends on DR */
+ pim_if_update_my_assert_metric(ifp); /* depends on could_assert */
+
+ join_desired depends on:
+ pim_ifp->primary_address
+ pim_ifp->pim_dr_addr
+ ch->ifassert_winner_metric
+ ch->ifassert_winner
+ ch->local_ifmembership
+ ch->ifjoin_state
+ ch->upstream->rpf.source_nexthop.mrib_metric_preference
+ ch->upstream->rpf.source_nexthop.mrib_route_metric
+ ch->upstream->rpf.source_nexthop.interface
+
+T38 DONE Detect change in AssertTrackingDesired(S,G,I)
+
+ See the order of invokation:
+ dr_election: none
+ update_join_desired: depends on DR
+ update_tracking_desired: depends on DR, join_desired
+
+ AssertTrackingDesired(S,G,I) depends on:
+ pim_ifp->primary_address
+ pim_ifp->pim_dr_addr
+ ch->local_ifmembership
+ ch->ifassert_winner
+ ch->ifjoin_state
+ ch->upstream->rpf.source_nexthop.interface
+ PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(ch->upstream->flags)
+
+T39 DONE AssertTrackingDesired: flags is not matching evaluation
+
+ # show ip pim assert-internal
+ CA: CouldAssert
+ ECA: Evaluate CouldAssert
+ ATD: AssertTrackingDesired
+ eATD: Evaluate AssertTrackingDesired
+
+ Interface Address Source Group CA eCA ATD eATD
+ eth0 192.168.1.100 1.1.1.1 239.1.1.1 no no no yes
+ #
+
+T40 Lightweight MLDv2
+ http://tools.ietf.org/html/draft-ietf-mboned-lightweight-igmpv3-mldv2-05
+ http://www.ietf.org/internet-drafts/draft-ietf-mboned-lightweight-igmpv3-mldv2-05.txt
+ http://www.ietf.org/html.charters/mboned-charter.html
+
+T41 DONE ssmping support
+
+ See also:
+ http://www.venaas.no/multicast/ssmping/
+ draft-ietf-mboned-ssmping-07
+ http://tools.ietf.org/html/draft-ietf-mboned-ssmping-07
+
+ Example:
+
+ debug ssmpingd
+
+ conf t
+ ip ssmpingd 1.1.1.1
+
+ show ip ssmpingd
+
+-x-
diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c
new file mode 100644
index 00000000..52168d69
--- /dev/null
+++ b/pimd/pim_assert.c
@@ -0,0 +1,804 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "prefix.h"
+
+#include "pimd.h"
+#include "pim_str.h"
+#include "pim_tlv.h"
+#include "pim_msg.h"
+#include "pim_pim.h"
+#include "pim_int.h"
+#include "pim_time.h"
+#include "pim_iface.h"
+#include "pim_hello.h"
+#include "pim_macro.h"
+#include "pim_assert.h"
+#include "pim_ifchannel.h"
+
+static int assert_action_a3(struct pim_ifchannel *ch);
+static void assert_action_a2(struct pim_ifchannel *ch,
+ struct pim_assert_metric winner_metric);
+static void assert_action_a6(struct pim_ifchannel *ch,
+ struct pim_assert_metric winner_metric);
+
+void pim_ifassert_winner_set(struct pim_ifchannel *ch,
+ enum pim_ifassert_state new_state,
+ struct in_addr winner,
+ struct pim_assert_metric winner_metric)
+{
+ int winner_changed = (ch->ifassert_winner.s_addr != winner.s_addr);
+ int metric_changed = !pim_assert_metric_match(&ch->ifassert_winner_metric,
+ &winner_metric);
+
+ if (ch->ifassert_state != new_state) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_info("%s: (S,G)=(%s,%s) assert state changed from %s to %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ pim_ifchannel_ifassert_name(ch->ifassert_state),
+ pim_ifchannel_ifassert_name(new_state),
+ ch->interface->name);
+ }
+
+ {
+ char src_str[100];
+ char grp_str[100];
+ char winner_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<winner?>", winner, winner_str, sizeof(winner_str));
+ zlog_info("%s: (S,G)=(%s,%s) assert winner now is %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ winner_str, ch->interface->name);
+ }
+
+ ch->ifassert_state = new_state;
+ ch->ifassert_winner = winner;
+ ch->ifassert_winner_metric = winner_metric;
+ ch->ifassert_creation = pim_time_monotonic_sec();
+
+ if (winner_changed || metric_changed) {
+ pim_upstream_update_join_desired(ch->upstream);
+ pim_ifchannel_update_could_assert(ch);
+ pim_ifchannel_update_assert_tracking_desired(ch);
+ }
+}
+
+static void on_trace(const char *label,
+ struct interface *ifp, struct in_addr src)
+{
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src, src_str, sizeof(src_str));
+ zlog_debug("%s: from %s on %s",
+ label, src_str, ifp->name);
+ }
+}
+
+static int preferred_assert(const struct pim_ifchannel *ch,
+ const struct pim_assert_metric *recv_metric)
+{
+ return pim_assert_metric_better(recv_metric,
+ &ch->ifassert_winner_metric);
+}
+
+static int acceptable_assert(const struct pim_assert_metric *my_metric,
+ const struct pim_assert_metric *recv_metric)
+{
+ return pim_assert_metric_better(recv_metric,
+ my_metric);
+}
+
+static int inferior_assert(const struct pim_assert_metric *my_metric,
+ const struct pim_assert_metric *recv_metric)
+{
+ return pim_assert_metric_better(my_metric,
+ recv_metric);
+}
+
+static int cancel_assert(const struct pim_assert_metric *recv_metric)
+{
+ return (recv_metric->metric_preference == PIM_ASSERT_METRIC_PREFERENCE_MAX)
+ &&
+ (recv_metric->route_metric == PIM_ASSERT_ROUTE_METRIC_MAX);
+}
+
+static void if_could_assert_do_a1(const char *caller,
+ struct pim_ifchannel *ch)
+{
+ if (PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags)) {
+ if (assert_action_a1(ch)) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: %s: (S,G)=(%s,%s) assert_action_a1 failure on interface %s",
+ __PRETTY_FUNCTION__, caller,
+ src_str, grp_str, ch->interface->name);
+ /* log warning only */
+ }
+ }
+}
+
+static int dispatch_assert(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ struct pim_assert_metric recv_metric)
+{
+ struct pim_ifchannel *ch;
+
+ ch = pim_ifchannel_add(ifp, source_addr, group_addr);
+ if (!ch) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: (S,G)=(%s,%s) failure creating channel on interface %s",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, ifp->name);
+ return -1;
+ }
+
+ switch (ch->ifassert_state) {
+ case PIM_IFASSERT_NOINFO:
+ if (recv_metric.rpt_bit_flag) {
+ /* RPT bit set */
+ if_could_assert_do_a1(__PRETTY_FUNCTION__, ch);
+ }
+ else {
+ /* RPT bit clear */
+ if (inferior_assert(&ch->ifassert_my_metric, &recv_metric)) {
+ if_could_assert_do_a1(__PRETTY_FUNCTION__, ch);
+ }
+ else if (acceptable_assert(&ch->ifassert_my_metric, &recv_metric)) {
+ if (PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch->flags)) {
+ assert_action_a6(ch, recv_metric);
+ }
+ }
+ }
+ break;
+ case PIM_IFASSERT_I_AM_WINNER:
+ if (preferred_assert(ch, &recv_metric)) {
+ assert_action_a2(ch, recv_metric);
+ }
+ else {
+ if (inferior_assert(&ch->ifassert_my_metric, &recv_metric)) {
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER); /* a3 requirement */
+ assert_action_a3(ch);
+ }
+ }
+ break;
+ case PIM_IFASSERT_I_AM_LOSER:
+ if (recv_metric.ip_address.s_addr == ch->ifassert_winner.s_addr) {
+ /* Assert from current winner */
+
+ if (cancel_assert(&recv_metric)) {
+ assert_action_a5(ch);
+ }
+ else {
+ if (inferior_assert(&ch->ifassert_my_metric, &recv_metric)) {
+ assert_action_a5(ch);
+ }
+ else if (acceptable_assert(&ch->ifassert_my_metric, &recv_metric)) {
+ if (!recv_metric.rpt_bit_flag) {
+ assert_action_a2(ch, recv_metric);
+ }
+ }
+ }
+ }
+ else if (preferred_assert(ch, &recv_metric)) {
+ assert_action_a2(ch, recv_metric);
+ }
+ break;
+ default:
+ {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: (S,G)=(%s,%s) invalid assert state %d on interface %s",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, ch->ifassert_state, ifp->name);
+ }
+ return -2;
+ }
+
+ return 0;
+}
+
+int pim_assert_recv(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ struct in_addr src_addr,
+ char *buf, int buf_size)
+{
+ struct prefix msg_group_addr;
+ struct prefix msg_source_addr;
+ struct pim_assert_metric msg_metric;
+ int offset;
+ char *curr;
+ int curr_size;
+
+ on_trace(__PRETTY_FUNCTION__, ifp, src_addr);
+
+ curr = buf;
+ curr_size = buf_size;
+
+ /*
+ Parse assert group addr
+ */
+ offset = pim_parse_addr_group(ifp->name, src_addr,
+ &msg_group_addr,
+ curr, curr_size);
+ if (offset < 1) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: pim_parse_addr_group() failure: from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ return -1;
+ }
+ curr += offset;
+ curr_size -= offset;
+
+ /*
+ Parse assert source addr
+ */
+ offset = pim_parse_addr_ucast(ifp->name, src_addr,
+ &msg_source_addr,
+ curr, curr_size);
+ if (offset < 1) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ return -2;
+ }
+ curr += offset;
+ curr_size -= offset;
+
+ if (curr_size != 8) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: preference/metric size is not 8: size=%d from %s on interface %s",
+ __PRETTY_FUNCTION__,
+ curr_size,
+ src_str, ifp->name);
+ return -3;
+ }
+
+ /*
+ Parse assert metric preference
+ */
+
+ msg_metric.metric_preference = pim_read_uint32_host(curr);
+
+ msg_metric.rpt_bit_flag = msg_metric.metric_preference & 0x80000000; /* save highest bit */
+ msg_metric.metric_preference &= ~0x80000000; /* clear highest bit */
+
+ curr += 4;
+
+ /*
+ Parse assert route metric
+ */
+
+ msg_metric.route_metric = pim_read_uint32_host(curr);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char neigh_str[100];
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<neigh?>", src_addr, neigh_str, sizeof(neigh_str));
+ pim_inet4_dump("<src?>", msg_source_addr.u.prefix4, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", msg_group_addr.u.prefix4, group_str, sizeof(group_str));
+ zlog_debug("%s: from %s on %s: (S,G)=(%s,%s) pref=%u metric=%u rpt_bit=%u",
+ __PRETTY_FUNCTION__, neigh_str, ifp->name,
+ source_str, group_str,
+ msg_metric.metric_preference,
+ msg_metric.route_metric,
+ PIM_FORCE_BOOLEAN(msg_metric.rpt_bit_flag));
+ }
+
+ msg_metric.ip_address = src_addr;
+
+ return dispatch_assert(ifp,
+ msg_source_addr.u.prefix4,
+ msg_group_addr.u.prefix4,
+ msg_metric);
+}
+
+/*
+ RFC 4601: 4.6.3. Assert Metrics
+
+ Assert metrics are defined as:
+
+ When comparing assert_metrics, the rpt_bit_flag, metric_preference,
+ and route_metric field are compared in order, where the first lower
+ value wins. If all fields are equal, the primary IP address of the
+ router that sourced the Assert message is used as a tie-breaker,
+ with the highest IP address winning.
+*/
+int pim_assert_metric_better(const struct pim_assert_metric *m1,
+ const struct pim_assert_metric *m2)
+{
+ if (m1->rpt_bit_flag < m2->rpt_bit_flag)
+ return 1;
+ if (m1->rpt_bit_flag > m2->rpt_bit_flag)
+ return 0;
+
+ if (m1->metric_preference < m2->metric_preference)
+ return 1;
+ if (m1->metric_preference > m2->metric_preference)
+ return 0;
+
+ if (m1->route_metric < m2->route_metric)
+ return 1;
+ if (m1->route_metric > m2->route_metric)
+ return 0;
+
+ return ntohl(m1->ip_address.s_addr) > ntohl(m2->ip_address.s_addr);
+}
+
+int pim_assert_metric_match(const struct pim_assert_metric *m1,
+ const struct pim_assert_metric *m2)
+{
+ if (m1->rpt_bit_flag != m2->rpt_bit_flag)
+ return 0;
+ if (m1->metric_preference != m2->metric_preference)
+ return 0;
+ if (m1->route_metric != m2->route_metric)
+ return 0;
+
+ return m1->ip_address.s_addr == m2->ip_address.s_addr;
+}
+
+int pim_assert_build_msg(uint8_t *pim_msg, int buf_size,
+ struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr,
+ uint32_t metric_preference,
+ uint32_t route_metric,
+ uint32_t rpt_bit_flag)
+{
+ uint8_t *buf_pastend = pim_msg + buf_size;
+ uint8_t *pim_msg_curr;
+ int pim_msg_size;
+ int remain;
+
+ pim_msg_curr = pim_msg + PIM_MSG_HEADER_LEN; /* skip room for pim header */
+
+ /* Encode group */
+ remain = buf_pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_group(pim_msg_curr,
+ remain,
+ group_addr);
+ if (!pim_msg_curr) {
+ char group_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: failure encoding group address %s: space left=%d",
+ __PRETTY_FUNCTION__, group_str, remain);
+ return -1;
+ }
+
+ /* Encode source */
+ remain = buf_pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_ucast(pim_msg_curr,
+ remain,
+ source_addr);
+ if (!pim_msg_curr) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: failure encoding source address %s: space left=%d",
+ __PRETTY_FUNCTION__, source_str, remain);
+ return -2;
+ }
+
+ /* Metric preference */
+ pim_write_uint32(pim_msg_curr, rpt_bit_flag ?
+ metric_preference | 0x80000000 :
+ metric_preference);
+ pim_msg_curr += 4;
+
+ /* Route metric */
+ pim_write_uint32(pim_msg_curr, route_metric);
+ pim_msg_curr += 4;
+
+ /*
+ Add PIM header
+ */
+ pim_msg_size = pim_msg_curr - pim_msg;
+ pim_msg_build_header(pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_ASSERT);
+
+ return pim_msg_size;
+}
+
+static int pim_assert_do(struct pim_ifchannel *ch,
+ struct pim_assert_metric metric)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ char pim_msg[1000];
+ int pim_msg_size;
+
+ ifp = ch->interface;
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ zlog_warn("%s: pim not enabled on interface: %s",
+ __PRETTY_FUNCTION__, ifp->name);
+ return -1;
+ }
+
+ pim_msg_size = pim_assert_build_msg(pim_msg, sizeof(pim_msg), ifp,
+ ch->group_addr, ch->source_addr,
+ metric.metric_preference,
+ metric.route_metric,
+ metric.rpt_bit_flag);
+ if (pim_msg_size < 1) {
+ zlog_warn("%s: failure building PIM assert message: msg_size=%d",
+ __PRETTY_FUNCTION__, pim_msg_size);
+ return -2;
+ }
+
+ /*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Thus, if a router needs to send a Join/Prune or Assert message on
+ an interface on which it has not yet sent a Hello message with the
+ currently configured IP address, then it MUST immediately send the
+ relevant Hello message without waiting for the Hello Timer to
+ expire, followed by the Join/Prune or Assert message.
+ */
+ pim_hello_require(ifp);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: to %s: (S,G)=(%s,%s) pref=%u metric=%u rpt_bit=%u",
+ __PRETTY_FUNCTION__,
+ ifp->name, source_str, group_str,
+ metric.metric_preference,
+ metric.route_metric,
+ PIM_FORCE_BOOLEAN(metric.rpt_bit_flag));
+ }
+
+ if (pim_msg_send(pim_ifp->pim_sock_fd,
+ qpim_all_pim_routers_addr,
+ pim_msg,
+ pim_msg_size,
+ ifp->name)) {
+ zlog_warn("%s: could not send PIM message on interface %s",
+ __PRETTY_FUNCTION__, ifp->name);
+ return -3;
+ }
+
+ return 0;
+}
+
+int pim_assert_send(struct pim_ifchannel *ch)
+{
+ return pim_assert_do(ch, ch->ifassert_my_metric);
+}
+
+/*
+ RFC 4601: 4.6.4. AssertCancel Messages
+
+ An AssertCancel(S,G) is an infinite metric assert with the RPT bit
+ set that names S as the source.
+ */
+static int pim_assert_cancel(struct pim_ifchannel *ch)
+{
+ struct pim_assert_metric metric;
+
+ metric.rpt_bit_flag = 0;
+ metric.metric_preference = PIM_ASSERT_METRIC_PREFERENCE_MAX;
+ metric.route_metric = PIM_ASSERT_ROUTE_METRIC_MAX;
+ metric.ip_address = ch->source_addr;
+
+ return pim_assert_do(ch, metric);
+}
+
+static int on_assert_timer(struct thread *t)
+{
+ struct pim_ifchannel *ch;
+ struct interface *ifp;
+
+ zassert(t);
+ ch = THREAD_ARG(t);
+ zassert(ch);
+
+ ifp = ch->interface;
+ zassert(ifp);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: (S,G)=(%s,%s) timer expired on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ }
+
+ ch->t_ifassert_timer = 0;
+
+ switch (ch->ifassert_state) {
+ case PIM_IFASSERT_I_AM_WINNER:
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER); /* a3 requirement */
+ assert_action_a3(ch);
+ break;
+ case PIM_IFASSERT_I_AM_LOSER:
+ assert_action_a5(ch);
+ break;
+ default:
+ {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: (S,G)=(%s,%s) invalid assert state %d on interface %s",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, ch->ifassert_state, ifp->name);
+ }
+ }
+
+ return 0;
+}
+
+static void assert_timer_off(struct pim_ifchannel *ch)
+{
+ struct interface *ifp;
+
+ zassert(ch);
+ ifp = ch->interface;
+ zassert(ifp);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ if (ch->t_ifassert_timer) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: (S,G)=(%s,%s) cancelling timer on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ }
+ }
+ THREAD_OFF(ch->t_ifassert_timer);
+ zassert(!ch->t_ifassert_timer);
+}
+
+static void pim_assert_timer_set(struct pim_ifchannel *ch,
+ int interval)
+{
+ struct interface *ifp;
+
+ zassert(ch);
+ ifp = ch->interface;
+ zassert(ifp);
+
+ assert_timer_off(ch);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: (S,G)=(%s,%s) starting %u sec timer on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, interval, ifp->name);
+ }
+
+ THREAD_TIMER_ON(master, ch->t_ifassert_timer,
+ on_assert_timer,
+ ch, interval);
+}
+
+static void pim_assert_timer_reset(struct pim_ifchannel *ch)
+{
+ pim_assert_timer_set(ch, PIM_ASSERT_TIME - PIM_ASSERT_OVERRIDE_INTERVAL);
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ (S,G) Assert State machine Actions
+
+ A1: Send Assert(S,G).
+ Set Assert Timer to (Assert_Time - Assert_Override_Interval).
+ Store self as AssertWinner(S,G,I).
+ Store spt_assert_metric(S,I) as AssertWinnerMetric(S,G,I).
+*/
+int assert_action_a1(struct pim_ifchannel *ch)
+{
+ struct interface *ifp = ch->interface;
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s) multicast no enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return -1; /* must return since pim_ifp is used below */
+ }
+
+ /* Switch to I_AM_WINNER before performing action_a3 below */
+ pim_ifassert_winner_set(ch, PIM_IFASSERT_I_AM_WINNER,
+ pim_ifp->primary_address,
+ pim_macro_spt_assert_metric(&ch->upstream->rpf,
+ pim_ifp->primary_address));
+
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER); /* a3 requirement */
+ if (assert_action_a3(ch)) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s) assert_action_a3 failure on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ /* warning only */
+ }
+
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER);
+
+ return 0;
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ (S,G) Assert State machine Actions
+
+ A2: Store new assert winner as AssertWinner(S,G,I) and assert
+ winner metric as AssertWinnerMetric(S,G,I).
+ Set Assert Timer to Assert_Time.
+*/
+static void assert_action_a2(struct pim_ifchannel *ch,
+ struct pim_assert_metric winner_metric)
+{
+ pim_ifassert_winner_set(ch, PIM_IFASSERT_I_AM_LOSER,
+ winner_metric.ip_address,
+ winner_metric);
+
+ pim_assert_timer_set(ch, PIM_ASSERT_TIME);
+
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER);
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ (S,G) Assert State machine Actions
+
+ A3: Send Assert(S,G).
+ Set Assert Timer to (Assert_Time - Assert_Override_Interval).
+*/
+static int assert_action_a3(struct pim_ifchannel *ch)
+{
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER);
+
+ pim_assert_timer_reset(ch);
+
+ if (pim_assert_send(ch)) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+
+ zlog_warn("%s: (S,G)=(%s,%s) failure sending assert on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name);
+ return -1;
+ }
+
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER);
+
+ return 0;
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ (S,G) Assert State machine Actions
+
+ A4: Send AssertCancel(S,G).
+ Delete assert info (AssertWinner(S,G,I) and
+ AssertWinnerMetric(S,G,I) will then return their default
+ values).
+*/
+void assert_action_a4(struct pim_ifchannel *ch)
+{
+ if (pim_assert_cancel(ch)) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: failure sending AssertCancel(%s,%s) on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name);
+ /* log warning only */
+ }
+
+ assert_action_a5(ch);
+
+ zassert(ch->ifassert_state == PIM_IFASSERT_NOINFO);
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ (S,G) Assert State machine Actions
+
+ A5: Delete assert info (AssertWinner(S,G,I) and
+ AssertWinnerMetric(S,G,I) will then return their default values).
+*/
+void assert_action_a5(struct pim_ifchannel *ch)
+{
+ reset_ifassert_state(ch);
+ zassert(ch->ifassert_state == PIM_IFASSERT_NOINFO);
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ (S,G) Assert State machine Actions
+
+ A6: Store new assert winner as AssertWinner(S,G,I) and assert
+ winner metric as AssertWinnerMetric(S,G,I).
+ Set Assert Timer to Assert_Time.
+ If (I is RPF_interface(S)) AND (UpstreamJPState(S,G) == true)
+ set SPTbit(S,G) to TRUE.
+*/
+static void assert_action_a6(struct pim_ifchannel *ch,
+ struct pim_assert_metric winner_metric)
+{
+ assert_action_a2(ch, winner_metric);
+
+ /*
+ If (I is RPF_interface(S)) AND (UpstreamJPState(S,G) == true) set
+ SPTbit(S,G) to TRUE.
+
+ Notice: For PIM SSM, SPTbit(S,G) is already always true.
+ */
+
+ zassert(ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER);
+}
+
diff --git a/pimd/pim_assert.h b/pimd/pim_assert.h
new file mode 100644
index 00000000..feeb91df
--- /dev/null
+++ b/pimd/pim_assert.h
@@ -0,0 +1,75 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_ASSERT_H
+#define PIM_ASSERT_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+#include "pim_neighbor.h"
+#include "pim_ifchannel.h"
+
+/*
+ RFC 4601: 4.11. Timer Values
+
+ Note that for historical reasons, the Assert message lacks a
+ Holdtime field. Thus, changing the Assert Time from the default
+ value is not recommended.
+ */
+#define PIM_ASSERT_OVERRIDE_INTERVAL (3) /* seconds */
+#define PIM_ASSERT_TIME (180) /* seconds */
+
+#define PIM_ASSERT_METRIC_PREFERENCE_MAX (0xFFFFFFFF)
+#define PIM_ASSERT_ROUTE_METRIC_MAX (0xFFFFFFFF)
+
+void pim_ifassert_winner_set(struct pim_ifchannel *ch,
+ enum pim_ifassert_state new_state,
+ struct in_addr winner,
+ struct pim_assert_metric winner_metric);
+
+int pim_assert_recv(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ struct in_addr src_addr,
+ char *buf, int buf_size);
+
+int pim_assert_metric_better(const struct pim_assert_metric *m1,
+ const struct pim_assert_metric *m2);
+int pim_assert_metric_match(const struct pim_assert_metric *m1,
+ const struct pim_assert_metric *m2);
+
+int pim_assert_build_msg(uint8_t *pim_msg, int buf_size,
+ struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr,
+ uint32_t metric_preference,
+ uint32_t route_metric,
+ uint32_t rpt_bit_flag);
+
+int pim_assert_send(struct pim_ifchannel *ch);
+
+int assert_action_a1(struct pim_ifchannel *ch);
+void assert_action_a4(struct pim_ifchannel *ch);
+void assert_action_a5(struct pim_ifchannel *ch);
+
+#endif /* PIM_ASSERT_H */
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
new file mode 100644
index 00000000..23ad11f6
--- /dev/null
+++ b/pimd/pim_cmd.c
@@ -0,0 +1,4284 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <sys/ioctl.h>
+
+#include <zebra.h>
+
+#include "command.h"
+#include "if.h"
+#include "prefix.h"
+
+#include "pimd.h"
+#include "pim_cmd.h"
+#include "pim_iface.h"
+#include "pim_vty.h"
+#include "pim_mroute.h"
+#include "pim_str.h"
+#include "pim_igmpv3.h"
+#include "pim_sock.h"
+#include "pim_time.h"
+#include "pim_util.h"
+#include "pim_oil.h"
+#include "pim_neighbor.h"
+#include "pim_pim.h"
+#include "pim_ifchannel.h"
+#include "pim_hello.h"
+#include "pim_msg.h"
+#include "pim_upstream.h"
+#include "pim_rpf.h"
+#include "pim_macro.h"
+#include "pim_ssmpingd.h"
+
+static struct cmd_node pim_global_node = {
+ PIM_NODE,
+ "",
+ 1 /* vtysh ? yes */
+};
+
+static struct cmd_node interface_node = {
+ INTERFACE_NODE,
+ "%s(config-if)# ",
+ 1 /* vtysh ? yes */
+};
+
+static void pim_if_membership_clear(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ if (PIM_IF_TEST_PIM(pim_ifp->options) &&
+ PIM_IF_TEST_IGMP(pim_ifp->options)) {
+ return;
+ }
+
+ pim_ifchannel_membership_clear(ifp);
+}
+
+/*
+ When PIM is disabled on interface, IGMPv3 local membership
+ information is not injected into PIM interface state.
+
+ The function pim_if_membership_refresh() fetches all IGMPv3 local
+ membership information into PIM. It is intented to be called
+ whenever PIM is enabled on the interface in order to collect missed
+ local membership information.
+ */
+static void pim_if_membership_refresh(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ if (!PIM_IF_TEST_PIM(pim_ifp->options))
+ return;
+ if (!PIM_IF_TEST_IGMP(pim_ifp->options))
+ return;
+
+ /*
+ First clear off membership from all PIM (S,G) entries on the
+ interface
+ */
+
+ pim_ifchannel_membership_clear(ifp);
+
+ /*
+ Then restore PIM (S,G) membership from all IGMPv3 (S,G) entries on
+ the interface
+ */
+
+ /* scan igmp sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ struct listnode *grpnode;
+ struct igmp_group *grp;
+
+ /* scan igmp groups */
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
+ struct listnode *srcnode;
+ struct igmp_source *src;
+
+ /* scan group sources */
+ for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, srcnode, src)) {
+
+ if (IGMP_SOURCE_TEST_FORWARDING(src->source_flags)) {
+ pim_ifchannel_local_membership_add(ifp,
+ src->source_addr,
+ grp->group_addr);
+ }
+
+ } /* scan group sources */
+ } /* scan igmp groups */
+ } /* scan igmp sockets */
+
+ /*
+ Finally delete every PIM (S,G) entry lacking all state info
+ */
+
+ pim_ifchannel_delete_on_noinfo(ifp);
+
+}
+
+static void pim_show_assert(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty,
+ "Interface Address Source Group State Winner Uptime Timer%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ char ch_src_str[100];
+ char ch_grp_str[100];
+ char winner_str[100];
+ char uptime[10];
+ char timer[10];
+
+ pim_inet4_dump("<ch_src?>", ch->source_addr,
+ ch_src_str, sizeof(ch_src_str));
+ pim_inet4_dump("<ch_grp?>", ch->group_addr,
+ ch_grp_str, sizeof(ch_grp_str));
+ pim_inet4_dump("<assrt_win?>", ch->ifassert_winner,
+ winner_str, sizeof(winner_str));
+
+ pim_time_uptime(uptime, sizeof(uptime), now - ch->ifassert_creation);
+ pim_time_timer_to_mmss(timer, sizeof(timer),
+ ch->t_ifassert_timer);
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %-6s %-15s %-8s %-5s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ch_src_str,
+ ch_grp_str,
+ pim_ifchannel_ifassert_name(ch->ifassert_state),
+ winner_str,
+ uptime,
+ timer,
+ VTY_NEWLINE);
+ } /* scan interface channels */
+ } /* scan interfaces */
+}
+
+static void pim_show_assert_internal(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "CA: CouldAssert%s"
+ "ECA: Evaluate CouldAssert%s"
+ "ATD: AssertTrackingDesired%s"
+ "eATD: Evaluate AssertTrackingDesired%s%s",
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty,
+ "Interface Address Source Group CA eCA ATD eATD%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ char ch_src_str[100];
+ char ch_grp_str[100];
+
+ pim_inet4_dump("<ch_src?>", ch->source_addr,
+ ch_src_str, sizeof(ch_src_str));
+ pim_inet4_dump("<ch_grp?>", ch->group_addr,
+ ch_grp_str, sizeof(ch_grp_str));
+ vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %-3s %-3s %-4s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ch_src_str,
+ ch_grp_str,
+ PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags) ? "yes" : "no",
+ pim_macro_ch_could_assert_eval(ch) ? "yes" : "no",
+ PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch->flags) ? "yes" : "no",
+ pim_macro_assert_tracking_desired_eval(ch) ? "yes" : "no",
+ VTY_NEWLINE);
+ } /* scan interface channels */
+ } /* scan interfaces */
+}
+
+static void pim_show_assert_metric(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "Interface Address Source Group RPT Pref Metric Address %s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ char ch_src_str[100];
+ char ch_grp_str[100];
+ char addr_str[100];
+ struct pim_assert_metric am;
+
+ am = pim_macro_spt_assert_metric(&ch->upstream->rpf, pim_ifp->primary_address);
+
+ pim_inet4_dump("<ch_src?>", ch->source_addr,
+ ch_src_str, sizeof(ch_src_str));
+ pim_inet4_dump("<ch_grp?>", ch->group_addr,
+ ch_grp_str, sizeof(ch_grp_str));
+ pim_inet4_dump("<addr?>", am.ip_address,
+ addr_str, sizeof(addr_str));
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %4u %6u %-15s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ch_src_str,
+ ch_grp_str,
+ am.rpt_bit_flag ? "yes" : "no",
+ am.metric_preference,
+ am.route_metric,
+ addr_str,
+ VTY_NEWLINE);
+ } /* scan interface channels */
+ } /* scan interfaces */
+}
+
+static void pim_show_assert_winner_metric(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "Interface Address Source Group RPT Pref Metric Address %s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ char ch_src_str[100];
+ char ch_grp_str[100];
+ char addr_str[100];
+ struct pim_assert_metric *am;
+ char pref_str[5];
+ char metr_str[7];
+
+ am = &ch->ifassert_winner_metric;
+
+ pim_inet4_dump("<ch_src?>", ch->source_addr,
+ ch_src_str, sizeof(ch_src_str));
+ pim_inet4_dump("<ch_grp?>", ch->group_addr,
+ ch_grp_str, sizeof(ch_grp_str));
+ pim_inet4_dump("<addr?>", am->ip_address,
+ addr_str, sizeof(addr_str));
+
+ if (am->metric_preference == PIM_ASSERT_METRIC_PREFERENCE_MAX)
+ snprintf(pref_str, sizeof(pref_str), "INFI");
+ else
+ snprintf(pref_str, sizeof(pref_str), "%4u", am->metric_preference);
+
+ if (am->route_metric == PIM_ASSERT_ROUTE_METRIC_MAX)
+ snprintf(metr_str, sizeof(metr_str), "INFI");
+ else
+ snprintf(metr_str, sizeof(metr_str), "%6u", am->route_metric);
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %-4s %-6s %-15s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ch_src_str,
+ ch_grp_str,
+ am->rpt_bit_flag ? "yes" : "no",
+ pref_str,
+ metr_str,
+ addr_str,
+ VTY_NEWLINE);
+ } /* scan interface channels */
+ } /* scan interfaces */
+}
+
+static void pim_show_membership(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "Interface Address Source Group Membership%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ char ch_src_str[100];
+ char ch_grp_str[100];
+
+ pim_inet4_dump("<ch_src?>", ch->source_addr,
+ ch_src_str, sizeof(ch_src_str));
+ pim_inet4_dump("<ch_grp?>", ch->group_addr,
+ ch_grp_str, sizeof(ch_grp_str));
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %-10s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ch_src_str,
+ ch_grp_str,
+ ch->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO ?
+ "NOINFO" : "INCLUDE",
+ VTY_NEWLINE);
+ } /* scan interface channels */
+ } /* scan interfaces */
+
+}
+
+static void igmp_show_interfaces(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty,
+ "Interface Address ifIndex Socket Uptime Multi Broad MLoop AllMu Prmsc Del%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char uptime[10];
+ int mloop;
+
+ pim_time_uptime(uptime, sizeof(uptime), now - igmp->sock_creation);
+
+ mloop = pim_socket_mcastloop_get(igmp->fd);
+
+ vty_out(vty, "%-9s %-15s %7d %6d %8s %5s %5s %5s %5s %5s %3s%s",
+ ifp->name,
+ inet_ntoa(igmp->ifaddr),
+ ifp->ifindex,
+ igmp->fd,
+ uptime,
+ if_is_multicast(ifp) ? "yes" : "no",
+ if_is_broadcast(ifp) ? "yes" : "no",
+ (mloop < 0) ? "?" : (mloop ? "yes" : "no"),
+ (ifp->flags & IFF_ALLMULTI) ? "yes" : "no",
+ (ifp->flags & IFF_PROMISC) ? "yes" : "no",
+ PIM_IF_IS_DELETED(ifp) ? "yes" : "no",
+ VTY_NEWLINE);
+ }
+ }
+}
+
+static void show_interface_address(struct vty *vty)
+{
+ struct listnode *ifpnode;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "Interface Primary Secondary %s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifpnode, ifp)) {
+ struct listnode *ifcnode;
+ struct connected *ifc;
+ struct in_addr pri_addr;
+ char pri_addr_str[100];
+
+ pri_addr = pim_find_primary_addr(ifp);
+
+ pim_inet4_dump("<pri?>", pri_addr, pri_addr_str, sizeof(pri_addr_str));
+
+ for (ALL_LIST_ELEMENTS_RO(ifp->connected, ifcnode, ifc)) {
+ char sec_addr_str[100];
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ if (p->u.prefix4.s_addr == pri_addr.s_addr) {
+ sec_addr_str[0] = '\0';
+ }
+ else {
+ pim_inet4_dump("<sec?>", p->u.prefix4, sec_addr_str, sizeof(sec_addr_str));
+ }
+
+ vty_out(vty, "%-9s %-15s %-15s%s",
+ ifp->name,
+ pri_addr_str,
+ sec_addr_str,
+ VTY_NEWLINE);
+ }
+ }
+}
+
+static void pim_show_dr(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty,
+ "NonPri: Number of neighbors missing DR Priority hello option%s%s",
+ VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty, "Interface Address DR Uptime Elections NonPri%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ char dr_str[100];
+ char dr_uptime[10];
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ pim_time_uptime(dr_uptime, sizeof(dr_uptime),
+ now - pim_ifp->pim_dr_election_last);
+
+ pim_inet4_dump("<dr?>", pim_ifp->pim_dr_addr,
+ dr_str, sizeof(dr_str));
+
+ vty_out(vty, "%-9s %-15s %-15s %8s %9d %6d%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ dr_str,
+ dr_uptime,
+ pim_ifp->pim_dr_election_count,
+ pim_ifp->pim_dr_num_nondrpri_neighbors,
+ VTY_NEWLINE);
+ }
+}
+
+static void pim_show_hello(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Interface Address Period Timer StatStart Recv Rfail Send Sfail%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ char hello_period[10];
+ char hello_timer[10];
+ char stat_uptime[10];
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ pim_time_timer_to_mmss(hello_timer, sizeof(hello_timer), pim_ifp->t_pim_hello_timer);
+ pim_time_mmss(hello_period, sizeof(hello_period), pim_ifp->pim_hello_period);
+ pim_time_uptime(stat_uptime, sizeof(stat_uptime), now - pim_ifp->pim_ifstat_start);
+
+ vty_out(vty, "%-9s %-15s %6s %5s %9s %4u %5u %4u %5u%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ hello_period,
+ hello_timer,
+ stat_uptime,
+ pim_ifp->pim_ifstat_hello_recv,
+ pim_ifp->pim_ifstat_hello_recvfail,
+ pim_ifp->pim_ifstat_hello_sent,
+ pim_ifp->pim_ifstat_hello_sendfail,
+ VTY_NEWLINE);
+ }
+}
+
+static void pim_show_interfaces(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Interface Address ifIndex Socket Uptime Multi Broad MLoop AllMu Prmsc Del%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ char uptime[10];
+ int mloop;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ pim_time_uptime(uptime, sizeof(uptime), now - pim_ifp->pim_sock_creation);
+
+ mloop = pim_socket_mcastloop_get(pim_ifp->pim_sock_fd);
+
+ vty_out(vty, "%-9s %-15s %7d %6d %8s %5s %5s %5s %5s %5s %3s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ifp->ifindex,
+ pim_ifp->pim_sock_fd,
+ uptime,
+ if_is_multicast(ifp) ? "yes" : "no",
+ if_is_broadcast(ifp) ? "yes" : "no",
+ (mloop < 0) ? "?" : (mloop ? "yes" : "no"),
+ (ifp->flags & IFF_ALLMULTI) ? "yes" : "no",
+ (ifp->flags & IFF_PROMISC) ? "yes" : "no",
+ PIM_IF_IS_DELETED(ifp) ? "yes" : "no",
+ VTY_NEWLINE);
+ }
+}
+
+static void pim_show_join(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty,
+ "Interface Address Source Group State Uptime Expire Prune%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ char ch_src_str[100];
+ char ch_grp_str[100];
+ char uptime[10];
+ char expire[10];
+ char prune[10];
+
+ pim_inet4_dump("<ch_src?>", ch->source_addr,
+ ch_src_str, sizeof(ch_src_str));
+ pim_inet4_dump("<ch_grp?>", ch->group_addr,
+ ch_grp_str, sizeof(ch_grp_str));
+
+ pim_time_uptime(uptime, sizeof(uptime), now - ch->ifjoin_creation);
+ pim_time_timer_to_mmss(expire, sizeof(expire),
+ ch->t_ifjoin_expiry_timer);
+ pim_time_timer_to_mmss(prune, sizeof(prune),
+ ch->t_ifjoin_prune_pending_timer);
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %-6s %8s %-6s %5s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ch_src_str,
+ ch_grp_str,
+ pim_ifchannel_ifjoin_name(ch->ifjoin_state),
+ uptime,
+ expire,
+ prune,
+ VTY_NEWLINE);
+ } /* scan interface channels */
+ } /* scan interfaces */
+
+}
+
+static void pim_show_neighbors(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty,
+ "Recv flags: H=holdtime L=lan_prune_delay P=dr_priority G=generation_id A=address_list%s"
+ " T=can_disable_join_suppression%s%s",
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty, "Interface Address Neighbor Uptime Timer Holdt DrPri GenId Recv %s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *neighnode;
+ struct pim_neighbor *neigh;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
+ char uptime[10];
+ char holdtime[10];
+ char expire[10];
+ char neigh_src_str[100];
+ char recv[7];
+
+ pim_inet4_dump("<src?>", neigh->source_addr,
+ neigh_src_str, sizeof(neigh_src_str));
+ pim_time_uptime(uptime, sizeof(uptime), now - neigh->creation);
+ pim_time_mmss(holdtime, sizeof(holdtime), neigh->holdtime);
+ pim_time_timer_to_mmss(expire, sizeof(expire), neigh->t_expire_timer);
+
+ recv[0] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_HOLDTIME) ? 'H' : ' ';
+ recv[1] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY) ? 'L' : ' ';
+ recv[2] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_DR_PRIORITY) ? 'P' : ' ';
+ recv[3] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_GENERATION_ID) ? 'G' : ' ';
+ recv[4] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_ADDRESS_LIST) ? 'A' : ' ';
+ recv[5] = PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION) ? 'T' : ' ';
+ recv[6] = '\0';
+
+ vty_out(vty, "%-9s %-15s %-15s %8s %5s %5s %5u %08x %6s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ neigh_src_str,
+ uptime,
+ expire,
+ holdtime,
+ neigh->dr_priority,
+ neigh->generation_id,
+ recv,
+ VTY_NEWLINE);
+ }
+
+
+ }
+}
+
+static void pim_show_lan_prune_delay(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "PrDly=propagation_delay (msec) OvInt=override_interval (msec)%s"
+ "HiDly=highest_propagation_delay (msec) HiInt=highest_override_interval (msec)%s"
+ "NoDly=number_of_non_lan_delay_neighbors%s"
+ "T=t_bit LPD=lan_prune_delay_hello_option%s%s",
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty, "Interface Address PrDly OvInt NoDly HiDly HiInt T Neighbor LPD PrDly OvInt T%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *neighnode;
+ struct pim_neighbor *neigh;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
+ char neigh_src_str[100];
+
+ pim_inet4_dump("<src?>", neigh->source_addr,
+ neigh_src_str, sizeof(neigh_src_str));
+
+ vty_out(vty, "%-9s %-15s %5u %5u %5u %5u %5u %1u %-15s %-3s %5u %5u %1u%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ pim_ifp->pim_propagation_delay_msec,
+ pim_ifp->pim_override_interval_msec,
+ pim_ifp->pim_number_of_nonlandelay_neighbors,
+ pim_ifp->pim_neighbors_highest_propagation_delay_msec,
+ pim_ifp->pim_neighbors_highest_override_interval_msec,
+ PIM_FORCE_BOOLEAN(PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options)),
+ neigh_src_str,
+ PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY) ? "yes" : "no",
+ neigh->propagation_delay_msec,
+ neigh->override_interval_msec,
+ PIM_FORCE_BOOLEAN(PIM_OPTION_IS_SET(neigh->hello_options,
+ PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION)),
+ VTY_NEWLINE);
+ }
+
+ }
+}
+
+static void pim_show_jp_override_interval(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "EffPDelay=effective_propagation_delay (msec)%s"
+ "EffOvrInt=override_interval (msec)%s"
+ "JPOvrInt=jp_override_interval (msec)%s%s",
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty, "Interface Address LAN_Delay EffPDelay EffOvrInt JPOvrInt%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ vty_out(vty, "%-9s %-15s %-9s %9u %9u %8u%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ pim_if_lan_delay_enabled(ifp) ? "enabled" : "disabled",
+ pim_if_effective_propagation_delay_msec(ifp),
+ pim_if_effective_override_interval_msec(ifp),
+ pim_if_jp_override_interval_msec(ifp),
+ VTY_NEWLINE);
+ }
+}
+
+static void pim_show_neighbors_secondary(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+
+ vty_out(vty, "Interface Address Neighbor Secondary %s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct listnode *neighnode;
+ struct pim_neighbor *neigh;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->pim_sock_fd < 0)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
+ char neigh_src_str[100];
+ struct listnode *prefix_node;
+ struct prefix *p;
+
+ if (!neigh->prefix_list)
+ continue;
+
+ pim_inet4_dump("<src?>", neigh->source_addr,
+ neigh_src_str, sizeof(neigh_src_str));
+
+ for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, prefix_node, p)) {
+ char neigh_sec_str[100];
+
+ if (p->family != AF_INET)
+ continue;
+
+ pim_inet4_dump("<src?>", p->u.prefix4,
+ neigh_sec_str, sizeof(neigh_sec_str));
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ neigh_src_str,
+ neigh_sec_str,
+ VTY_NEWLINE);
+ }
+ }
+ }
+}
+
+static void pim_show_upstream(struct vty *vty)
+{
+ struct listnode *upnode;
+ struct pim_upstream *up;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Source Group State Uptime JoinTimer RefCnt%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, upnode, up)) {
+ char src_str[100];
+ char grp_str[100];
+ char uptime[10];
+ char join_timer[10];
+
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_time_uptime(uptime, sizeof(uptime), now - up->state_transition);
+ pim_time_timer_to_hhmmss(join_timer, sizeof(join_timer), up->t_join_timer);
+
+ vty_out(vty, "%-15s %-15s %-5s %-8s %-9s %6d%s",
+ src_str,
+ grp_str,
+ up->join_state == PIM_UPSTREAM_JOINED ? "Jnd" : "NtJnd",
+ uptime,
+ join_timer,
+ up->ref_count,
+ VTY_NEWLINE);
+ }
+}
+
+static void pim_show_join_desired(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct listnode *chnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+ struct in_addr me_ifaddr;
+ char src_str[100];
+ char grp_str[100];
+
+ vty_out(vty,
+ "Interface Source Group LostAssert Joins PimInclude JoinDesired EvalJD%s",
+ VTY_NEWLINE);
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ me_ifaddr = pim_ifp->primary_address;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, chnode, ch)) {
+ struct pim_upstream *up = ch->upstream;
+
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+
+ vty_out(vty, "%-9s %-15s %-15s %-10s %-5s %-10s %-11s %-6s%s",
+ ifp->name,
+ src_str,
+ grp_str,
+ pim_macro_ch_lost_assert(ch) ? "yes" : "no",
+ pim_macro_chisin_joins(ch) ? "yes" : "no",
+ pim_macro_chisin_pim_include(ch) ? "yes" : "no",
+ PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags) ? "yes" : "no",
+ pim_upstream_evaluate_join_desired(up) ? "yes" : "no",
+ VTY_NEWLINE);
+ }
+ }
+}
+
+static void pim_show_upstream_rpf(struct vty *vty)
+{
+ struct listnode *upnode;
+ struct pim_upstream *up;
+
+ vty_out(vty,
+ "Source Group RpfIface RibNextHop RpfAddress %s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, upnode, up)) {
+ char src_str[100];
+ char grp_str[100];
+ char rpf_nexthop_str[100];
+ char rpf_addr_str[100];
+ struct pim_rpf *rpf;
+ const char *rpf_ifname;
+
+ rpf = &up->rpf;
+
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<nexthop?>", rpf->source_nexthop.mrib_nexthop_addr, rpf_nexthop_str, sizeof(rpf_nexthop_str));
+ pim_inet4_dump("<rpf?>", rpf->rpf_addr, rpf_addr_str, sizeof(rpf_addr_str));
+
+ rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
+
+ vty_out(vty, "%-15s %-15s %-8s %-15s %-15s%s",
+ src_str,
+ grp_str,
+ rpf_ifname,
+ rpf_nexthop_str,
+ rpf_addr_str,
+ VTY_NEWLINE);
+ }
+}
+
+static void show_rpf_refresh_stats(struct vty *vty, time_t now)
+{
+ char refresh_uptime[10];
+
+ pim_time_uptime(refresh_uptime, sizeof(refresh_uptime), now - qpim_rpf_cache_refresh_last);
+
+ vty_out(vty,
+ "RPF Cache Refresh Delay: %ld msecs%s"
+ "RPF Cache Refresh Timer: %ld msecs%s"
+ "RPF Cache Refresh Requests: %lld%s"
+ "RPF Cache Refresh Events: %lld%s"
+ "RPF Cache Refresh Last: %s%s",
+ qpim_rpf_cache_refresh_delay_msec, VTY_NEWLINE,
+ pim_time_timer_remain_msec(qpim_rpf_cache_refresher), VTY_NEWLINE,
+ qpim_rpf_cache_refresh_requests, VTY_NEWLINE,
+ qpim_rpf_cache_refresh_events, VTY_NEWLINE,
+ refresh_uptime, VTY_NEWLINE);
+}
+
+static void pim_show_rpf(struct vty *vty)
+{
+ struct listnode *up_node;
+ struct pim_upstream *up;
+ time_t now = pim_time_monotonic_sec();
+
+ show_rpf_refresh_stats(vty, now);
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+
+ vty_out(vty,
+ "Source Group RpfIface RpfAddress RibNextHop Metric Pref%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, up_node, up)) {
+ char src_str[100];
+ char grp_str[100];
+ char rpf_addr_str[100];
+ char rib_nexthop_str[100];
+ const char *rpf_ifname;
+ struct pim_rpf *rpf = &up->rpf;
+
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<rpf?>", rpf->rpf_addr, rpf_addr_str, sizeof(rpf_addr_str));
+ pim_inet4_dump("<nexthop?>", rpf->source_nexthop.mrib_nexthop_addr, rib_nexthop_str, sizeof(rib_nexthop_str));
+
+ rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
+
+ vty_out(vty, "%-15s %-15s %-8s %-15s %-15s %6d %4d%s",
+ src_str,
+ grp_str,
+ rpf_ifname,
+ rpf_addr_str,
+ rib_nexthop_str,
+ rpf->source_nexthop.mrib_route_metric,
+ rpf->source_nexthop.mrib_metric_preference,
+ VTY_NEWLINE);
+ }
+}
+
+static void igmp_show_querier(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+
+ vty_out(vty, "Interface Address Querier StartCount Query-Timer Other-Timer%s", VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp = ifp->info;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ if (!pim_ifp)
+ continue;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char query_hhmmss[10];
+ char other_hhmmss[10];
+
+ pim_time_timer_to_hhmmss(query_hhmmss, sizeof(query_hhmmss), igmp->t_igmp_query_timer);
+ pim_time_timer_to_hhmmss(other_hhmmss, sizeof(other_hhmmss), igmp->t_other_querier_timer);
+
+ vty_out(vty, "%-9s %-15s %-7s %10d %11s %11s%s",
+ ifp->name,
+ inet_ntoa(igmp->ifaddr),
+ igmp->t_igmp_query_timer ? "THIS" : "OTHER",
+ igmp->startup_query_count,
+ query_hhmmss,
+ other_hhmmss,
+ VTY_NEWLINE);
+ }
+ }
+}
+
+static void igmp_show_groups(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Interface Address Group Mode Timer Srcs V Uptime %s", VTY_NEWLINE);
+
+ /* scan interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp = ifp->info;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ if (!pim_ifp)
+ continue;
+
+ /* scan igmp sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char ifaddr_str[100];
+ struct listnode *grpnode;
+ struct igmp_group *grp;
+
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+
+ /* scan igmp groups */
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
+ char group_str[100];
+ char hhmmss[10];
+ char uptime[10];
+
+ pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
+ pim_time_timer_to_hhmmss(hhmmss, sizeof(hhmmss), grp->t_group_timer);
+ pim_time_uptime(uptime, sizeof(uptime), now - grp->group_creation);
+
+ vty_out(vty, "%-9s %-15s %-15s %4s %8s %4d %d %8s%s",
+ ifp->name,
+ ifaddr_str,
+ group_str,
+ grp->group_filtermode_isexcl ? "EXCL" : "INCL",
+ hhmmss,
+ grp->group_source_list ? listcount(grp->group_source_list) : 0,
+ igmp_group_compat_mode(igmp, grp),
+ uptime,
+ VTY_NEWLINE);
+
+ } /* scan igmp groups */
+ } /* scan igmp sockets */
+ } /* scan interfaces */
+}
+
+static void igmp_show_group_retransmission(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Interface Address Group RetTimer Counter RetSrcs%s", VTY_NEWLINE);
+
+ /* scan interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp = ifp->info;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ if (!pim_ifp)
+ continue;
+
+ /* scan igmp sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char ifaddr_str[100];
+ struct listnode *grpnode;
+ struct igmp_group *grp;
+
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+
+ /* scan igmp groups */
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
+ char group_str[100];
+ char grp_retr_mmss[10];
+ struct listnode *src_node;
+ struct igmp_source *src;
+ int grp_retr_sources = 0;
+
+ pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
+ pim_time_timer_to_mmss(grp_retr_mmss, sizeof(grp_retr_mmss), grp->t_group_query_retransmit_timer);
+
+
+ /* count group sources with retransmission state */
+ for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, src_node, src)) {
+ if (src->source_query_retransmit_count > 0) {
+ ++grp_retr_sources;
+ }
+ }
+
+ vty_out(vty, "%-9s %-15s %-15s %-8s %7d %7d%s",
+ ifp->name,
+ ifaddr_str,
+ group_str,
+ grp_retr_mmss,
+ grp->group_specific_query_retransmit_count,
+ grp_retr_sources,
+ VTY_NEWLINE);
+
+ } /* scan igmp groups */
+ } /* scan igmp sockets */
+ } /* scan interfaces */
+}
+
+static void igmp_show_parameters(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ vty_out(vty,
+ "QRV: Robustness Variable SQI: Startup Query Interval%s"
+ "QQI: Query Interval OQPI: Other Querier Present Interval%s"
+ "QRI: Query Response Interval LMQT: Last Member Query Time%s"
+ "GMI: Group Membership Interval OHPI: Older Host Present Interval%s%s",
+ VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty,
+ "Interface Address QRV QQI QRI GMI SQI OQPI LMQT OHPI %s",
+ VTY_NEWLINE);
+
+ /* scan interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp = ifp->info;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ if (!pim_ifp)
+ continue;
+
+ /* scan igmp sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char ifaddr_str[100];
+ long gmi_dsec; /* Group Membership Interval */
+ long oqpi_dsec; /* Other Querier Present Interval */
+ int sqi;
+ long lmqt_dsec;
+ long ohpi_dsec;
+ long qri_dsec;
+
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+
+ gmi_dsec = PIM_IGMP_GMI_MSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec) / 100;
+
+ sqi = PIM_IGMP_SQI(pim_ifp->igmp_default_query_interval);
+
+ oqpi_dsec = PIM_IGMP_OQPI_MSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec) / 100;
+
+ lmqt_dsec = PIM_IGMP_LMQT_MSEC(pim_ifp->igmp_query_max_response_time_dsec,
+ igmp->querier_robustness_variable) / 100;
+
+ ohpi_dsec = PIM_IGMP_OHPI_DSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec);
+
+ qri_dsec = pim_ifp->igmp_query_max_response_time_dsec;
+
+ vty_out(vty,
+ "%-9s %-15s %3d %3d %3ld.%ld %3ld.%ld %3d %3ld.%ld %3ld.%ld %3ld.%ld%s",
+ ifp->name,
+ ifaddr_str,
+ igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ qri_dsec / 10, qri_dsec % 10,
+ gmi_dsec / 10, gmi_dsec % 10,
+ sqi,
+ oqpi_dsec / 10, oqpi_dsec % 10,
+ lmqt_dsec / 10, lmqt_dsec % 10,
+ ohpi_dsec / 10, ohpi_dsec % 10,
+ VTY_NEWLINE);
+
+ } /* scan igmp sockets */
+ } /* scan interfaces */
+}
+
+static void igmp_show_sources(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Interface Address Group Source Timer Fwd Uptime %s", VTY_NEWLINE);
+
+ /* scan interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp = ifp->info;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ if (!pim_ifp)
+ continue;
+
+ /* scan igmp sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char ifaddr_str[100];
+ struct listnode *grpnode;
+ struct igmp_group *grp;
+
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+
+ /* scan igmp groups */
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
+ char group_str[100];
+ struct listnode *srcnode;
+ struct igmp_source *src;
+
+ pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
+
+ /* scan group sources */
+ for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, srcnode, src)) {
+ char source_str[100];
+ char mmss[10];
+ char uptime[10];
+
+ pim_inet4_dump("<source?>", src->source_addr, source_str, sizeof(source_str));
+
+ pim_time_timer_to_mmss(mmss, sizeof(mmss), src->t_source_timer);
+
+ pim_time_uptime(uptime, sizeof(uptime), now - src->source_creation);
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %5s %3s %8s%s",
+ ifp->name,
+ ifaddr_str,
+ group_str,
+ source_str,
+ mmss,
+ IGMP_SOURCE_TEST_FORWARDING(src->source_flags) ? "Y" : "N",
+ uptime,
+ VTY_NEWLINE);
+
+ } /* scan group sources */
+ } /* scan igmp groups */
+ } /* scan igmp sockets */
+ } /* scan interfaces */
+}
+
+static void igmp_show_source_retransmission(struct vty *vty)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ time_t now;
+
+ now = pim_time_monotonic_sec();
+
+ vty_out(vty, "Interface Address Group Source Counter%s", VTY_NEWLINE);
+
+ /* scan interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp = ifp->info;
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ if (!pim_ifp)
+ continue;
+
+ /* scan igmp sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ char ifaddr_str[100];
+ struct listnode *grpnode;
+ struct igmp_group *grp;
+
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+
+ /* scan igmp groups */
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode, grp)) {
+ char group_str[100];
+ struct listnode *srcnode;
+ struct igmp_source *src;
+
+ pim_inet4_dump("<group?>", grp->group_addr, group_str, sizeof(group_str));
+
+ /* scan group sources */
+ for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, srcnode, src)) {
+ char source_str[100];
+
+ pim_inet4_dump("<source?>", src->source_addr, source_str, sizeof(source_str));
+
+ vty_out(vty, "%-9s %-15s %-15s %-15s %7d%s",
+ ifp->name,
+ ifaddr_str,
+ group_str,
+ source_str,
+ src->source_query_retransmit_count,
+ VTY_NEWLINE);
+
+ } /* scan group sources */
+ } /* scan igmp groups */
+ } /* scan igmp sockets */
+ } /* scan interfaces */
+}
+
+static void clear_igmp_interfaces()
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct interface *ifp;
+
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_if_addr_del_all_igmp(ifp);
+ }
+
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_if_addr_add_all(ifp);
+ }
+}
+
+static void clear_pim_interfaces()
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct interface *ifp;
+
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ if (ifp->info) {
+ pim_neighbor_delete_all(ifp, "interface cleared");
+ }
+ }
+}
+
+static void clear_interfaces()
+{
+ clear_igmp_interfaces();
+ clear_pim_interfaces();
+}
+
+DEFUN (pim_interface,
+ pim_interface_cmd,
+ "interface IFNAME",
+ "Select an interface to configure\n"
+ "Interface's name\n")
+{
+ struct interface *ifp;
+ const char *ifname = argv[0];
+ size_t sl;
+
+ sl = strlen(ifname);
+ if (sl > INTERFACE_NAMSIZ) {
+ vty_out(vty, "%% Interface name %s is invalid: length exceeds "
+ "%d characters%s",
+ ifname, INTERFACE_NAMSIZ, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ ifp = if_lookup_by_name_len(ifname, sl);
+ if (!ifp) {
+ vty_out(vty, "%% Interface %s does not exist%s", ifname, VTY_NEWLINE);
+
+ /* Returning here would prevent pimd from booting when there are
+ interface commands in pimd.conf, since all interfaces are
+ unknown at pimd boot time (the zebra daemon has not been
+ contacted for interface discovery). */
+
+ ifp = if_get_by_name_len(ifname, sl);
+ if (!ifp) {
+ vty_out(vty, "%% Could not create interface %s%s", ifname, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ vty->index = ifp;
+ vty->node = INTERFACE_NODE;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (clear_ip_interfaces,
+ clear_ip_interfaces_cmd,
+ "clear ip interfaces",
+ CLEAR_STR
+ IP_STR
+ "Reset interfaces\n")
+{
+ clear_interfaces();
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (clear_ip_igmp_interfaces,
+ clear_ip_igmp_interfaces_cmd,
+ "clear ip igmp interfaces",
+ CLEAR_STR
+ IP_STR
+ CLEAR_IP_IGMP_STR
+ "Reset IGMP interfaces\n")
+{
+ clear_igmp_interfaces();
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (clear_ip_pim_interfaces,
+ clear_ip_pim_interfaces_cmd,
+ "clear ip pim interfaces",
+ CLEAR_STR
+ IP_STR
+ CLEAR_IP_PIM_STR
+ "Reset PIM interfaces\n")
+{
+ clear_pim_interfaces();
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_interface,
+ show_ip_igmp_interface_cmd,
+ "show ip igmp interface",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ "IGMP interface information\n")
+{
+ igmp_show_interfaces(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_groups,
+ show_ip_igmp_groups_cmd,
+ "show ip igmp groups",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ IGMP_GROUP_STR)
+{
+ igmp_show_groups(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_groups_retransmissions,
+ show_ip_igmp_groups_retransmissions_cmd,
+ "show ip igmp groups retransmissions",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ IGMP_GROUP_STR
+ "IGMP group retransmissions\n")
+{
+ igmp_show_group_retransmission(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_parameters,
+ show_ip_igmp_parameters_cmd,
+ "show ip igmp parameters",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ "IGMP parameters information\n")
+{
+ igmp_show_parameters(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_sources,
+ show_ip_igmp_sources_cmd,
+ "show ip igmp sources",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ IGMP_SOURCE_STR)
+{
+ igmp_show_sources(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_sources_retransmissions,
+ show_ip_igmp_sources_retransmissions_cmd,
+ "show ip igmp sources retransmissions",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ IGMP_SOURCE_STR
+ "IGMP source retransmissions\n")
+{
+ igmp_show_source_retransmission(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_igmp_querier,
+ show_ip_igmp_querier_cmd,
+ "show ip igmp querier",
+ SHOW_STR
+ IP_STR
+ IGMP_STR
+ "IGMP querier information\n")
+{
+ igmp_show_querier(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_address,
+ show_ip_pim_address_cmd,
+ "show ip pim address",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface address\n")
+{
+ show_interface_address(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_assert,
+ show_ip_pim_assert_cmd,
+ "show ip pim assert",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface assert\n")
+{
+ pim_show_assert(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_assert_internal,
+ show_ip_pim_assert_internal_cmd,
+ "show ip pim assert-internal",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface internal assert state\n")
+{
+ pim_show_assert_internal(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_assert_metric,
+ show_ip_pim_assert_metric_cmd,
+ "show ip pim assert-metric",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface assert metric\n")
+{
+ pim_show_assert_metric(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_assert_winner_metric,
+ show_ip_pim_assert_winner_metric_cmd,
+ "show ip pim assert-winner-metric",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface assert winner metric\n")
+{
+ pim_show_assert_winner_metric(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_dr,
+ show_ip_pim_dr_cmd,
+ "show ip pim designated-router",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface designated router\n")
+{
+ pim_show_dr(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_hello,
+ show_ip_pim_hello_cmd,
+ "show ip pim hello",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface hello information\n")
+{
+ pim_show_hello(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_interface,
+ show_ip_pim_interface_cmd,
+ "show ip pim interface",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface information\n")
+{
+ pim_show_interfaces(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_join,
+ show_ip_pim_join_cmd,
+ "show ip pim join",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface join information\n")
+{
+ pim_show_join(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_lan_prune_delay,
+ show_ip_pim_lan_prune_delay_cmd,
+ "show ip pim lan-prune-delay",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM neighbors LAN prune delay parameters\n")
+{
+ pim_show_lan_prune_delay(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_local_membership,
+ show_ip_pim_local_membership_cmd,
+ "show ip pim local-membership",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface local-membership\n")
+{
+ pim_show_membership(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_jp_override_interval,
+ show_ip_pim_jp_override_interval_cmd,
+ "show ip pim jp-override-interval",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM interface J/P override interval\n")
+{
+ pim_show_jp_override_interval(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_neighbor,
+ show_ip_pim_neighbor_cmd,
+ "show ip pim neighbor",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM neighbor information\n")
+{
+ pim_show_neighbors(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_secondary,
+ show_ip_pim_secondary_cmd,
+ "show ip pim secondary",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM neighbor addresses\n")
+{
+ pim_show_neighbors_secondary(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_upstream,
+ show_ip_pim_upstream_cmd,
+ "show ip pim upstream",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM upstream information\n")
+{
+ pim_show_upstream(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_upstream_join_desired,
+ show_ip_pim_upstream_join_desired_cmd,
+ "show ip pim upstream-join-desired",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM upstream join-desired\n")
+{
+ pim_show_join_desired(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_upstream_rpf,
+ show_ip_pim_upstream_rpf_cmd,
+ "show ip pim upstream-rpf",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM upstream source rpf\n")
+{
+ pim_show_upstream_rpf(vty);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_pim_rpf,
+ show_ip_pim_rpf_cmd,
+ "show ip pim rpf",
+ SHOW_STR
+ IP_STR
+ PIM_STR
+ "PIM cached source rpf information\n")
+{
+ pim_show_rpf(vty);
+
+ return CMD_SUCCESS;
+}
+
+static void show_multicast_interfaces(struct vty *vty)
+{
+ struct listnode *node;
+ struct interface *ifp;
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+
+ vty_out(vty, "Interface Address ifi Vif PktsIn PktsOut BytesIn BytesOut%s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+ struct sioc_vif_req vreq;
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ continue;
+
+ memset(&vreq, 0, sizeof(vreq));
+ vreq.vifi = pim_ifp->mroute_vif_index;
+
+ if (ioctl(qpim_mroute_socket_fd, SIOCGETVIFCNT, &vreq)) {
+ int e = errno;
+ vty_out(vty,
+ "ioctl(SIOCGETVIFCNT=%d) failure for interface %s vif_index=%d: errno=%d: %s%s",
+ SIOCGETVIFCNT,
+ ifp->name,
+ pim_ifp->mroute_vif_index,
+ e,
+ safe_strerror(e),
+ VTY_NEWLINE);
+ continue;
+ }
+
+ ifaddr = pim_ifp->primary_address;
+
+ vty_out(vty, "%-9s %-15s %3d %3d %7lu %7lu %10lu %10lu%s",
+ ifp->name,
+ inet_ntoa(ifaddr),
+ ifp->ifindex,
+ pim_ifp->mroute_vif_index,
+ vreq.icount,
+ vreq.ocount,
+ vreq.ibytes,
+ vreq.obytes,
+ VTY_NEWLINE);
+ }
+}
+
+DEFUN (show_ip_multicast,
+ show_ip_multicast_cmd,
+ "show ip multicast",
+ SHOW_STR
+ IP_STR
+ "Multicast global information\n")
+{
+ time_t now = pim_time_monotonic_sec();
+
+ if (PIM_MROUTE_IS_ENABLED) {
+ char uptime[10];
+
+ vty_out(vty, "Mroute socket descriptor: %d%s",
+ qpim_mroute_socket_fd,
+ VTY_NEWLINE);
+
+ pim_time_uptime(uptime, sizeof(uptime), now - qpim_mroute_socket_creation);
+ vty_out(vty, "Mroute socket uptime: %s%s",
+ uptime,
+ VTY_NEWLINE);
+ }
+ else {
+ vty_out(vty, "Multicast disabled%s",
+ VTY_NEWLINE);
+ }
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out(vty, "Current highest VifIndex: %d%s",
+ qpim_mroute_oif_highest_vif_index,
+ VTY_NEWLINE);
+ vty_out(vty, "Maximum highest VifIndex: %d%s",
+ MAXVIFS - 1,
+ VTY_NEWLINE);
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+ vty_out(vty, "Upstream Join Timer: %d secs%s",
+ qpim_t_periodic,
+ VTY_NEWLINE);
+ vty_out(vty, "Join/Prune Holdtime: %d secs%s",
+ PIM_JP_HOLDTIME,
+ VTY_NEWLINE);
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+
+ show_rpf_refresh_stats(vty, now);
+
+ show_multicast_interfaces(vty);
+
+ return CMD_SUCCESS;
+}
+
+static void show_mroute(struct vty *vty)
+{
+ struct listnode *node;
+ struct channel_oil *c_oil;
+ time_t now;
+
+ vty_out(vty, "Proto: I=IGMP P=PIM%s%s", VTY_NEWLINE, VTY_NEWLINE);
+
+ vty_out(vty, "Source Group Proto Input iVifI Output oVifI TTL Uptime %s",
+ VTY_NEWLINE);
+
+ now = pim_time_monotonic_sec();
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
+ char group_str[100];
+ char source_str[100];
+ int oif_vif_index;
+
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+
+ for (oif_vif_index = 0; oif_vif_index < MAXVIFS; ++oif_vif_index) {
+ struct interface *ifp_in;
+ struct interface *ifp_out;
+ char oif_uptime[10];
+ int ttl;
+ char proto[5];
+
+ ttl = c_oil->oil.mfcc_ttls[oif_vif_index];
+ if (ttl < 1)
+ continue;
+
+ ifp_in = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
+ ifp_out = pim_if_find_by_vif_index(oif_vif_index);
+
+ pim_time_uptime(oif_uptime, sizeof(oif_uptime), now - c_oil->oif_creation[oif_vif_index]);
+
+ proto[0] = '\0';
+ if (c_oil->oif_flags[oif_vif_index] & PIM_OIF_FLAG_PROTO_PIM) {
+ strcat(proto, "P");
+ }
+ if (c_oil->oif_flags[oif_vif_index] & PIM_OIF_FLAG_PROTO_IGMP) {
+ strcat(proto, "I");
+ }
+
+ vty_out(vty, "%-15s %-15s %-5s %-5s %5d %-6s %5d %3d %8s %s",
+ source_str,
+ group_str,
+ proto,
+ ifp_in ? ifp_in->name : "<iif?>",
+ c_oil->oil.mfcc_parent,
+ ifp_out ? ifp_out->name : "<oif?>",
+ oif_vif_index,
+ ttl,
+ oif_uptime,
+ VTY_NEWLINE);
+ }
+ }
+}
+
+DEFUN (show_ip_mroute,
+ show_ip_mroute_cmd,
+ "show ip mroute",
+ SHOW_STR
+ IP_STR
+ MROUTE_STR)
+{
+ show_mroute(vty);
+ return CMD_SUCCESS;
+}
+
+static void show_mroute_count(struct vty *vty)
+{
+ struct listnode *node;
+ struct channel_oil *c_oil;
+
+ vty_out(vty, "%s", VTY_NEWLINE);
+
+ vty_out(vty, "Source Group Packets Bytes WrongIf %s",
+ VTY_NEWLINE);
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
+ char group_str[100];
+ char source_str[100];
+ struct sioc_sg_req sgreq;
+
+ memset(&sgreq, 0, sizeof(sgreq));
+ sgreq.src = c_oil->oil.mfcc_origin;
+ sgreq.grp = c_oil->oil.mfcc_mcastgrp;
+
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+
+ if (ioctl(qpim_mroute_socket_fd, SIOCGETSGCNT, &sgreq)) {
+ int e = errno;
+ vty_out(vty,
+ "ioctl(SIOCGETSGCNT=%d) failure for (S,G)=(%s,%s): errno=%d: %s%s",
+ SIOCGETSGCNT,
+ source_str,
+ group_str,
+ e,
+ safe_strerror(e),
+ VTY_NEWLINE);
+ continue;
+ }
+
+ vty_out(vty, "%-15s %-15s %7ld %10ld %7ld %s",
+ source_str,
+ group_str,
+ sgreq.pktcnt,
+ sgreq.bytecnt,
+ sgreq.wrong_if,
+ VTY_NEWLINE);
+
+ }
+}
+
+DEFUN (show_ip_mroute_count,
+ show_ip_mroute_count_cmd,
+ "show ip mroute count",
+ SHOW_STR
+ IP_STR
+ MROUTE_STR
+ "Route and packet count data\n")
+{
+ show_mroute_count(vty);
+ return CMD_SUCCESS;
+}
+
+DEFUN (show_ip_route,
+ show_ip_route_cmd,
+ "show ip route A.B.C.D",
+ SHOW_STR
+ IP_STR
+ ROUTE_STR
+ "Unicast address\n")
+{
+ struct in_addr addr;
+ const char *addr_str;
+ struct pim_nexthop nexthop;
+ char nexthop_addr_str[100];
+ int result;
+
+ addr_str = argv[0];
+ result = inet_pton(AF_INET, addr_str, &addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad unicast address %s: errno=%d: %s%s",
+ addr_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (pim_nexthop_lookup(&nexthop, addr)) {
+ vty_out(vty, "Failure querying RIB nexthop for unicast address %s%s",
+ addr_str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ vty_out(vty, "Address NextHop Interface Metric Preference%s",
+ VTY_NEWLINE);
+
+ pim_inet4_dump("<nexthop?>", nexthop.mrib_nexthop_addr,
+ nexthop_addr_str, sizeof(nexthop_addr_str));
+
+ vty_out(vty, "%-15s %-15s %-9s %6d %10d%s",
+ addr_str,
+ nexthop_addr_str,
+ nexthop.interface ? nexthop.interface->name : "<ifname?>",
+ nexthop.mrib_route_metric,
+ nexthop.mrib_metric_preference,
+ VTY_NEWLINE);
+
+ return CMD_SUCCESS;
+}
+
+static void show_ssmpingd(struct vty *vty)
+{
+ struct listnode *node;
+ struct ssmpingd_sock *ss;
+ time_t now;
+
+ vty_out(vty, "Source Socket Address Port Uptime Requests%s",
+ VTY_NEWLINE);
+
+ if (!qpim_ssmpingd_list)
+ return;
+
+ now = pim_time_monotonic_sec();
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_ssmpingd_list, node, ss)) {
+ char source_str[100];
+ char ss_uptime[10];
+ struct sockaddr_in bind_addr;
+ int len = sizeof(bind_addr);
+ char bind_addr_str[100];
+
+ pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
+
+ if (pim_socket_getsockname(ss->sock_fd, (struct sockaddr *) &bind_addr, &len)) {
+ vty_out(vty, "%% Failure reading socket name for ssmpingd source %s on fd=%d%s",
+ source_str, ss->sock_fd, VTY_NEWLINE);
+ }
+
+ pim_inet4_dump("<addr?>", bind_addr.sin_addr, bind_addr_str, sizeof(bind_addr_str));
+ pim_time_uptime(ss_uptime, sizeof(ss_uptime), now - ss->creation);
+
+ vty_out(vty, "%-15s %6d %-15s %5d %8s %8lld%s",
+ source_str,
+ ss->sock_fd,
+ bind_addr_str,
+ ntohs(bind_addr.sin_port),
+ ss_uptime,
+ ss->requests,
+ VTY_NEWLINE);
+ }
+}
+
+DEFUN (show_ip_ssmpingd,
+ show_ip_ssmpingd_cmd,
+ "show ip ssmpingd",
+ SHOW_STR
+ IP_STR
+ SHOW_SSMPINGD_STR)
+{
+ show_ssmpingd(vty);
+ return CMD_SUCCESS;
+}
+
+static void mroute_add_all()
+{
+ struct listnode *node;
+ struct channel_oil *c_oil;
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
+ if (pim_mroute_add(&c_oil->oil)) {
+ /* just log warning */
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ zlog_warn("%s %s: (S,G)=(%s,%s) failure writing MFC",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str);
+ }
+ }
+}
+
+static void mroute_del_all()
+{
+ struct listnode *node;
+ struct channel_oil *c_oil;
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
+ if (pim_mroute_del(&c_oil->oil)) {
+ /* just log warning */
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ zlog_warn("%s %s: (S,G)=(%s,%s) failure clearing MFC",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str);
+ }
+ }
+}
+
+DEFUN (ip_multicast_routing,
+ ip_multicast_routing_cmd,
+ PIM_CMD_IP_MULTICAST_ROUTING,
+ IP_STR
+ "Enable IP multicast forwarding\n")
+{
+ pim_mroute_socket_enable();
+ pim_if_add_vif_all();
+ mroute_add_all();
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_ip_multicast_routing,
+ no_ip_multicast_routing_cmd,
+ PIM_CMD_NO " " PIM_CMD_IP_MULTICAST_ROUTING,
+ NO_STR
+ IP_STR
+ "Global IP configuration subcommands\n"
+ "Enable IP multicast forwarding\n")
+{
+ mroute_del_all();
+ pim_if_del_vif_all();
+ pim_mroute_socket_disable();
+ return CMD_SUCCESS;
+}
+
+DEFUN (ip_ssmpingd,
+ ip_ssmpingd_cmd,
+ "ip ssmpingd [A.B.C.D]",
+ IP_STR
+ CONF_SSMPINGD_STR
+ "Source address\n")
+{
+ int result;
+ struct in_addr source_addr;
+ const char *source_str = (argc > 0) ? argv[0] : "0.0.0.0";
+
+ result = inet_pton(AF_INET, source_str, &source_addr);
+ if (result <= 0) {
+ vty_out(vty, "%% Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ result = pim_ssmpingd_start(source_addr);
+ if (result) {
+ vty_out(vty, "%% Failure starting ssmpingd for source %s: %d%s",
+ source_str, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_ip_ssmpingd,
+ no_ip_ssmpingd_cmd,
+ "no ip ssmpingd [A.B.C.D]",
+ NO_STR
+ IP_STR
+ CONF_SSMPINGD_STR
+ "Source address\n")
+{
+ int result;
+ struct in_addr source_addr;
+ const char *source_str = (argc > 0) ? argv[0] : "0.0.0.0";
+
+ result = inet_pton(AF_INET, source_str, &source_addr);
+ if (result <= 0) {
+ vty_out(vty, "%% Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ result = pim_ssmpingd_stop(source_addr);
+ if (result) {
+ vty_out(vty, "%% Failure stopping ssmpingd for source %s: %d%s",
+ source_str, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_ip_igmp,
+ interface_ip_igmp_cmd,
+ "ip igmp",
+ IP_STR
+ IFACE_IGMP_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ pim_ifp = pim_if_new(ifp, 1 /* igmp=true */, 0 /* pim=false */);
+ if (!pim_ifp) {
+ vty_out(vty, "Could not enable IGMP on interface %s%s",
+ ifp->name, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else {
+ PIM_IF_DO_IGMP(pim_ifp->options);
+ }
+
+ pim_if_addr_add_all(ifp);
+ pim_if_membership_refresh(ifp);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_no_ip_igmp,
+ interface_no_ip_igmp_cmd,
+ "no ip igmp",
+ NO_STR
+ IP_STR
+ IFACE_IGMP_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return CMD_SUCCESS;
+
+ PIM_IF_DONT_IGMP(pim_ifp->options);
+
+ pim_if_membership_clear(ifp);
+
+ pim_if_addr_del_all(ifp);
+
+ if (!PIM_IF_TEST_PIM(pim_ifp->options)) {
+ pim_if_delete(ifp);
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_ip_igmp_join,
+ interface_ip_igmp_join_cmd,
+ "ip igmp join A.B.C.D A.B.C.D",
+ IP_STR
+ IFACE_IGMP_STR
+ "IGMP join multicast group\n"
+ "Multicast group address\n"
+ "Source address\n")
+{
+ struct interface *ifp;
+ const char *group_str;
+ const char *source_str;
+ struct in_addr group_addr;
+ struct in_addr source_addr;
+ int result;
+
+ ifp = vty->index;
+
+ /* Group address */
+ group_str = argv[0];
+ result = inet_pton(AF_INET, group_str, &group_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad group address %s: errno=%d: %s%s",
+ group_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Source address */
+ source_str = argv[1];
+ result = inet_pton(AF_INET, source_str, &source_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ result = pim_if_igmp_join_add(ifp, group_addr, source_addr);
+ if (result) {
+ vty_out(vty, "%% Failure joining IGMP group %s source %s on interface %s: %d%s",
+ group_str, source_str, ifp->name, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_no_ip_igmp_join,
+ interface_no_ip_igmp_join_cmd,
+ "no ip igmp join A.B.C.D A.B.C.D",
+ NO_STR
+ IP_STR
+ IFACE_IGMP_STR
+ "IGMP join multicast group\n"
+ "Multicast group address\n"
+ "Source address\n")
+{
+ struct interface *ifp;
+ const char *group_str;
+ const char *source_str;
+ struct in_addr group_addr;
+ struct in_addr source_addr;
+ int result;
+
+ ifp = vty->index;
+
+ /* Group address */
+ group_str = argv[0];
+ result = inet_pton(AF_INET, group_str, &group_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad group address %s: errno=%d: %s%s",
+ group_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Source address */
+ source_str = argv[1];
+ result = inet_pton(AF_INET, source_str, &source_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ result = pim_if_igmp_join_del(ifp, group_addr, source_addr);
+ if (result) {
+ vty_out(vty, "%% Failure leaving IGMP group %s source %s on interface %s: %d%s",
+ group_str, source_str, ifp->name, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+/*
+ CLI reconfiguration affects the interface level (struct pim_interface).
+ This function propagates the reconfiguration to every active socket
+ for that interface.
+ */
+static void igmp_sock_query_interval_reconfig(struct igmp_sock *igmp)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+
+ zassert(igmp);
+
+ /* other querier present? */
+
+ if (igmp->t_other_querier_timer)
+ return;
+
+ /* this is the querier */
+
+ zassert(igmp->interface);
+ zassert(igmp->interface->info);
+
+ ifp = igmp->interface;
+ pim_ifp = ifp->info;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("%s: Querier %s on %s reconfig query_interval=%d",
+ __PRETTY_FUNCTION__,
+ ifaddr_str,
+ ifp->name,
+ pim_ifp->igmp_default_query_interval);
+ }
+
+ /*
+ igmp_startup_mode_on() will reset QQI:
+
+ igmp->querier_query_interval = pim_ifp->igmp_default_query_interval;
+ */
+ igmp_startup_mode_on(igmp);
+}
+
+static void igmp_sock_query_reschedule(struct igmp_sock *igmp)
+{
+ if (igmp->t_igmp_query_timer) {
+ /* other querier present */
+ zassert(igmp->t_igmp_query_timer);
+ zassert(!igmp->t_other_querier_timer);
+
+ pim_igmp_general_query_off(igmp);
+ pim_igmp_general_query_on(igmp);
+
+ zassert(igmp->t_igmp_query_timer);
+ zassert(!igmp->t_other_querier_timer);
+ }
+ else {
+ /* this is the querier */
+
+ zassert(!igmp->t_igmp_query_timer);
+ zassert(igmp->t_other_querier_timer);
+
+ pim_igmp_other_querier_timer_off(igmp);
+ pim_igmp_other_querier_timer_on(igmp);
+
+ zassert(!igmp->t_igmp_query_timer);
+ zassert(igmp->t_other_querier_timer);
+ }
+}
+
+static void change_query_interval(struct pim_interface *pim_ifp,
+ int query_interval)
+{
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ pim_ifp->igmp_default_query_interval = query_interval;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ igmp_sock_query_interval_reconfig(igmp);
+ igmp_sock_query_reschedule(igmp);
+ }
+}
+
+static void change_query_max_response_time(struct pim_interface *pim_ifp,
+ int query_max_response_time_dsec)
+{
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ pim_ifp->igmp_query_max_response_time_dsec = query_max_response_time_dsec;
+
+ /*
+ Below we modify socket/group/source timers in order to quickly
+ reflect the change. Otherwise, those timers would eventually catch
+ up.
+ */
+
+ /* scan all sockets */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
+ struct listnode *grp_node;
+ struct igmp_group *grp;
+
+ /* reschedule socket general query */
+ igmp_sock_query_reschedule(igmp);
+
+ /* scan socket groups */
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grp_node, grp)) {
+ struct listnode *src_node;
+ struct igmp_source *src;
+
+ /* reset group timers for groups in EXCLUDE mode */
+ if (grp->group_filtermode_isexcl) {
+ igmp_group_reset_gmi(grp);
+ }
+
+ /* scan group sources */
+ for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, src_node, src)) {
+
+ /* reset source timers for sources with running timers */
+ if (src->t_source_timer) {
+ igmp_source_reset_gmi(igmp, grp, src);
+ }
+ }
+ }
+ }
+}
+
+#define IGMP_QUERY_INTERVAL_MIN (1)
+#define IGMP_QUERY_INTERVAL_MAX (1800)
+
+DEFUN (interface_ip_igmp_query_interval,
+ interface_ip_igmp_query_interval_cmd,
+ PIM_CMD_IP_IGMP_QUERY_INTERVAL " <1-1800>",
+ IP_STR
+ IFACE_IGMP_STR
+ IFACE_IGMP_QUERY_INTERVAL_STR
+ "Query interval in seconds\n")
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int query_interval;
+ int query_interval_dsec;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ vty_out(vty,
+ "IGMP not enabled on interface %s. Please enable IGMP first.%s",
+ ifp->name,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ query_interval = atoi(argv[0]);
+ query_interval_dsec = 10 * query_interval;
+
+ /*
+ It seems we don't need to check bounds since command.c does it
+ already, but we verify them anyway for extra safety.
+ */
+ if (query_interval < IGMP_QUERY_INTERVAL_MIN) {
+ vty_out(vty, "General query interval %d lower than minimum %d%s",
+ query_interval,
+ IGMP_QUERY_INTERVAL_MIN,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (query_interval > IGMP_QUERY_INTERVAL_MAX) {
+ vty_out(vty, "General query interval %d higher than maximum %d%s",
+ query_interval,
+ IGMP_QUERY_INTERVAL_MAX,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (query_interval_dsec <= pim_ifp->igmp_query_max_response_time_dsec) {
+ vty_out(vty,
+ "Can't set general query interval %d dsec <= query max response time %d dsec.%s",
+ query_interval_dsec, pim_ifp->igmp_query_max_response_time_dsec,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ change_query_interval(pim_ifp, query_interval);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_no_ip_igmp_query_interval,
+ interface_no_ip_igmp_query_interval_cmd,
+ PIM_CMD_NO " " PIM_CMD_IP_IGMP_QUERY_INTERVAL,
+ NO_STR
+ IP_STR
+ IFACE_IGMP_STR
+ IFACE_IGMP_QUERY_INTERVAL_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int default_query_interval_dsec;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ return CMD_SUCCESS;
+
+ default_query_interval_dsec = IGMP_GENERAL_QUERY_INTERVAL * 10;
+
+ if (default_query_interval_dsec <= pim_ifp->igmp_query_max_response_time_dsec) {
+ vty_out(vty,
+ "Can't set default general query interval %d dsec <= query max response time %d dsec.%s",
+ default_query_interval_dsec, pim_ifp->igmp_query_max_response_time_dsec,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ change_query_interval(pim_ifp, IGMP_GENERAL_QUERY_INTERVAL);
+
+ return CMD_SUCCESS;
+}
+
+#define IGMP_QUERY_MAX_RESPONSE_TIME_MIN (1)
+#define IGMP_QUERY_MAX_RESPONSE_TIME_MAX (25)
+
+DEFUN (interface_ip_igmp_query_max_response_time,
+ interface_ip_igmp_query_max_response_time_cmd,
+ PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME " <1-25>",
+ IP_STR
+ IFACE_IGMP_STR
+ IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_STR
+ "Query response value in seconds\n")
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int query_max_response_time;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ vty_out(vty,
+ "IGMP not enabled on interface %s. Please enable IGMP first.%s",
+ ifp->name,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ query_max_response_time = atoi(argv[0]);
+
+ /*
+ It seems we don't need to check bounds since command.c does it
+ already, but we verify them anyway for extra safety.
+ */
+ if (query_max_response_time < IGMP_QUERY_MAX_RESPONSE_TIME_MIN) {
+ vty_out(vty, "Query max response time %d sec lower than minimum %d sec%s",
+ query_max_response_time,
+ IGMP_QUERY_MAX_RESPONSE_TIME_MIN,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (query_max_response_time > IGMP_QUERY_MAX_RESPONSE_TIME_MAX) {
+ vty_out(vty, "Query max response time %d sec higher than maximum %d sec%s",
+ query_max_response_time,
+ IGMP_QUERY_MAX_RESPONSE_TIME_MAX,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (query_max_response_time >= pim_ifp->igmp_default_query_interval) {
+ vty_out(vty,
+ "Can't set query max response time %d sec >= general query interval %d sec%s",
+ query_max_response_time, pim_ifp->igmp_default_query_interval,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ change_query_max_response_time(pim_ifp, 10 * query_max_response_time);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_no_ip_igmp_query_max_response_time,
+ interface_no_ip_igmp_query_max_response_time_cmd,
+ PIM_CMD_NO " " PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME,
+ NO_STR
+ IP_STR
+ IFACE_IGMP_STR
+ IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int default_query_interval_dsec;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ return CMD_SUCCESS;
+
+ default_query_interval_dsec = 10 * pim_ifp->igmp_default_query_interval;
+
+ if (IGMP_QUERY_MAX_RESPONSE_TIME_DSEC >= default_query_interval_dsec) {
+ vty_out(vty,
+ "Can't set default query max response time %d dsec >= general query interval %d dsec.%s",
+ IGMP_QUERY_MAX_RESPONSE_TIME_DSEC, default_query_interval_dsec,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ change_query_max_response_time(pim_ifp, IGMP_QUERY_MAX_RESPONSE_TIME_DSEC);
+
+ return CMD_SUCCESS;
+}
+
+#define IGMP_QUERY_MAX_RESPONSE_TIME_MIN_DSEC (10)
+#define IGMP_QUERY_MAX_RESPONSE_TIME_MAX_DSEC (250)
+
+DEFUN (interface_ip_igmp_query_max_response_time_dsec,
+ interface_ip_igmp_query_max_response_time_dsec_cmd,
+ PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC " <10-250>",
+ IP_STR
+ IFACE_IGMP_STR
+ IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC_STR
+ "Query response value in deciseconds\n")
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int query_max_response_time_dsec;
+ int default_query_interval_dsec;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ vty_out(vty,
+ "IGMP not enabled on interface %s. Please enable IGMP first.%s",
+ ifp->name,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ query_max_response_time_dsec = atoi(argv[0]);
+
+ /*
+ It seems we don't need to check bounds since command.c does it
+ already, but we verify them anyway for extra safety.
+ */
+ if (query_max_response_time_dsec < IGMP_QUERY_MAX_RESPONSE_TIME_MIN_DSEC) {
+ vty_out(vty, "Query max response time %d dsec lower than minimum %d dsec%s",
+ query_max_response_time_dsec,
+ IGMP_QUERY_MAX_RESPONSE_TIME_MIN_DSEC,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (query_max_response_time_dsec > IGMP_QUERY_MAX_RESPONSE_TIME_MAX_DSEC) {
+ vty_out(vty, "Query max response time %d dsec higher than maximum %d dsec%s",
+ query_max_response_time_dsec,
+ IGMP_QUERY_MAX_RESPONSE_TIME_MAX_DSEC,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ default_query_interval_dsec = 10 * pim_ifp->igmp_default_query_interval;
+
+ if (query_max_response_time_dsec >= default_query_interval_dsec) {
+ vty_out(vty,
+ "Can't set query max response time %d dsec >= general query interval %d dsec%s",
+ query_max_response_time_dsec, default_query_interval_dsec,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ change_query_max_response_time(pim_ifp, query_max_response_time_dsec);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_no_ip_igmp_query_max_response_time_dsec,
+ interface_no_ip_igmp_query_max_response_time_dsec_cmd,
+ PIM_CMD_NO " " PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC,
+ NO_STR
+ IP_STR
+ IFACE_IGMP_STR
+ IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int default_query_interval_dsec;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp)
+ return CMD_SUCCESS;
+
+ default_query_interval_dsec = 10 * pim_ifp->igmp_default_query_interval;
+
+ if (IGMP_QUERY_MAX_RESPONSE_TIME_DSEC >= default_query_interval_dsec) {
+ vty_out(vty,
+ "Can't set default query max response time %d dsec >= general query interval %d dsec.%s",
+ IGMP_QUERY_MAX_RESPONSE_TIME_DSEC, default_query_interval_dsec,
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ change_query_max_response_time(pim_ifp, IGMP_QUERY_MAX_RESPONSE_TIME_DSEC);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_ip_pim_ssm,
+ interface_ip_pim_ssm_cmd,
+ "ip pim ssm",
+ IP_STR
+ PIM_STR
+ IFACE_PIM_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ pim_ifp = pim_if_new(ifp, 0 /* igmp=false */, 1 /* pim=true */);
+ if (!pim_ifp) {
+ vty_out(vty, "Could not enable PIM on interface%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ else {
+ PIM_IF_DO_PIM(pim_ifp->options);
+ }
+
+ pim_if_addr_add_all(ifp);
+ pim_if_membership_refresh(ifp);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (interface_no_ip_pim_ssm,
+ interface_no_ip_pim_ssm_cmd,
+ "no ip pim ssm",
+ NO_STR
+ IP_STR
+ PIM_STR
+ IFACE_PIM_STR)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+
+ ifp = vty->index;
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return CMD_SUCCESS;
+
+ PIM_IF_DONT_PIM(pim_ifp->options);
+
+ pim_if_membership_clear(ifp);
+
+ /*
+ pim_if_addr_del_all() removes all sockets from
+ pim_ifp->igmp_socket_list.
+ */
+ pim_if_addr_del_all(ifp);
+
+ /*
+ pim_sock_delete() removes all neighbors from
+ pim_ifp->pim_neighbor_list.
+ */
+ pim_sock_delete(ifp, "pim unconfigured on interface");
+
+ if (!PIM_IF_TEST_IGMP(pim_ifp->options)) {
+ pim_if_delete(ifp);
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (debug_igmp,
+ debug_igmp_cmd,
+ "debug igmp",
+ DEBUG_STR
+ DEBUG_IGMP_STR)
+{
+ PIM_DO_DEBUG_IGMP_EVENTS;
+ PIM_DO_DEBUG_IGMP_PACKETS;
+ PIM_DO_DEBUG_IGMP_TRACE;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_igmp,
+ no_debug_igmp_cmd,
+ "no debug igmp",
+ NO_STR
+ DEBUG_STR
+ DEBUG_IGMP_STR)
+{
+ PIM_DONT_DEBUG_IGMP_EVENTS;
+ PIM_DONT_DEBUG_IGMP_PACKETS;
+ PIM_DONT_DEBUG_IGMP_TRACE;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_igmp,
+ undebug_igmp_cmd,
+ "undebug igmp",
+ UNDEBUG_STR
+ DEBUG_IGMP_STR)
+
+DEFUN (debug_igmp_events,
+ debug_igmp_events_cmd,
+ "debug igmp events",
+ DEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_EVENTS_STR)
+{
+ PIM_DO_DEBUG_IGMP_EVENTS;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_igmp_events,
+ no_debug_igmp_events_cmd,
+ "no debug igmp events",
+ NO_STR
+ DEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_EVENTS_STR)
+{
+ PIM_DONT_DEBUG_IGMP_EVENTS;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_igmp_events,
+ undebug_igmp_events_cmd,
+ "undebug igmp events",
+ UNDEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_EVENTS_STR)
+
+DEFUN (debug_igmp_packets,
+ debug_igmp_packets_cmd,
+ "debug igmp packets",
+ DEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_PACKETS_STR)
+{
+ PIM_DO_DEBUG_IGMP_PACKETS;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_igmp_packets,
+ no_debug_igmp_packets_cmd,
+ "no debug igmp packets",
+ NO_STR
+ DEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_PACKETS_STR)
+{
+ PIM_DONT_DEBUG_IGMP_PACKETS;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_igmp_packets,
+ undebug_igmp_packets_cmd,
+ "undebug igmp packets",
+ UNDEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_PACKETS_STR)
+
+DEFUN (debug_igmp_trace,
+ debug_igmp_trace_cmd,
+ "debug igmp trace",
+ DEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_TRACE_STR)
+{
+ PIM_DO_DEBUG_IGMP_TRACE;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_igmp_trace,
+ no_debug_igmp_trace_cmd,
+ "no debug igmp trace",
+ NO_STR
+ DEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_TRACE_STR)
+{
+ PIM_DONT_DEBUG_IGMP_TRACE;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_igmp_trace,
+ undebug_igmp_trace_cmd,
+ "undebug igmp trace",
+ UNDEBUG_STR
+ DEBUG_IGMP_STR
+ DEBUG_IGMP_TRACE_STR)
+
+DEFUN (debug_pim,
+ debug_pim_cmd,
+ "debug pim",
+ DEBUG_STR
+ DEBUG_PIM_STR)
+{
+ PIM_DO_DEBUG_PIM_EVENTS;
+ PIM_DO_DEBUG_PIM_PACKETS;
+ PIM_DO_DEBUG_PIM_TRACE;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim,
+ no_debug_pim_cmd,
+ "no debug pim",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR)
+{
+ PIM_DONT_DEBUG_PIM_EVENTS;
+ PIM_DONT_DEBUG_PIM_PACKETS;
+ PIM_DONT_DEBUG_PIM_TRACE;
+
+ PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND;
+ PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV;
+
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim,
+ undebug_pim_cmd,
+ "undebug pim",
+ UNDEBUG_STR
+ DEBUG_PIM_STR)
+
+DEFUN (debug_pim_events,
+ debug_pim_events_cmd,
+ "debug pim events",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_EVENTS_STR)
+{
+ PIM_DO_DEBUG_PIM_EVENTS;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim_events,
+ no_debug_pim_events_cmd,
+ "no debug pim events",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_EVENTS_STR)
+{
+ PIM_DONT_DEBUG_PIM_EVENTS;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim_events,
+ undebug_pim_events_cmd,
+ "undebug pim events",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_EVENTS_STR)
+
+DEFUN (debug_pim_packets,
+ debug_pim_packets_cmd,
+ "debug pim packets",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETS_STR)
+{
+ PIM_DO_DEBUG_PIM_PACKETS;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim_packets,
+ no_debug_pim_packets_cmd,
+ "no debug pim packets",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETS_STR)
+{
+ PIM_DONT_DEBUG_PIM_PACKETS;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim_packets,
+ undebug_pim_packets_cmd,
+ "undebug pim packets",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETS_STR)
+
+DEFUN (debug_pim_packetdump_send,
+ debug_pim_packetdump_send_cmd,
+ "debug pim packet-dump send",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETDUMP_STR
+ DEBUG_PIM_PACKETDUMP_SEND_STR)
+{
+ PIM_DO_DEBUG_PIM_PACKETDUMP_SEND;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim_packetdump_send,
+ no_debug_pim_packetdump_send_cmd,
+ "no debug pim packet-dump send",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETDUMP_STR
+ DEBUG_PIM_PACKETDUMP_SEND_STR)
+{
+ PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim_packetdump_send,
+ undebug_pim_packetdump_send_cmd,
+ "undebug pim packet-dump send",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETDUMP_STR
+ DEBUG_PIM_PACKETDUMP_SEND_STR)
+
+DEFUN (debug_pim_packetdump_recv,
+ debug_pim_packetdump_recv_cmd,
+ "debug pim packet-dump receive",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETDUMP_STR
+ DEBUG_PIM_PACKETDUMP_RECV_STR)
+{
+ PIM_DO_DEBUG_PIM_PACKETDUMP_RECV;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim_packetdump_recv,
+ no_debug_pim_packetdump_recv_cmd,
+ "no debug pim packet-dump receive",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETDUMP_STR
+ DEBUG_PIM_PACKETDUMP_RECV_STR)
+{
+ PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim_packetdump_recv,
+ undebug_pim_packetdump_recv_cmd,
+ "undebug pim packet-dump receive",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_PACKETDUMP_STR
+ DEBUG_PIM_PACKETDUMP_RECV_STR)
+
+DEFUN (debug_pim_trace,
+ debug_pim_trace_cmd,
+ "debug pim trace",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_TRACE_STR)
+{
+ PIM_DO_DEBUG_PIM_TRACE;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim_trace,
+ no_debug_pim_trace_cmd,
+ "no debug pim trace",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_TRACE_STR)
+{
+ PIM_DONT_DEBUG_PIM_TRACE;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim_trace,
+ undebug_pim_trace_cmd,
+ "undebug pim trace",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_TRACE_STR)
+
+DEFUN (debug_ssmpingd,
+ debug_ssmpingd_cmd,
+ "debug ssmpingd",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_SSMPINGD_STR)
+{
+ PIM_DO_DEBUG_SSMPINGD;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_ssmpingd,
+ no_debug_ssmpingd_cmd,
+ "no debug ssmpingd",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_SSMPINGD_STR)
+{
+ PIM_DONT_DEBUG_SSMPINGD;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_ssmpingd,
+ undebug_ssmpingd_cmd,
+ "undebug ssmpingd",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_SSMPINGD_STR)
+
+DEFUN (debug_pim_zebra,
+ debug_pim_zebra_cmd,
+ "debug pim zebra",
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_ZEBRA_STR)
+{
+ PIM_DO_DEBUG_ZEBRA;
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_pim_zebra,
+ no_debug_pim_zebra_cmd,
+ "no debug pim zebra",
+ NO_STR
+ DEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_ZEBRA_STR)
+{
+ PIM_DONT_DEBUG_ZEBRA;
+ return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_pim_zebra,
+ undebug_pim_zebra_cmd,
+ "undebug pim zebra",
+ UNDEBUG_STR
+ DEBUG_PIM_STR
+ DEBUG_PIM_ZEBRA_STR)
+
+DEFUN (show_debugging,
+ show_debugging_cmd,
+ "show debugging",
+ SHOW_STR
+ "State of each debugging option\n")
+{
+ pim_debug_config_write(vty);
+ return CMD_SUCCESS;
+}
+
+static struct igmp_sock *find_igmp_sock_by_fd(int fd)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ struct pim_interface *pim_ifp;
+ struct igmp_sock *igmp;
+
+ if (!ifp->info)
+ continue;
+
+ pim_ifp = ifp->info;
+
+ /* lookup igmp socket under current interface */
+ igmp = igmp_sock_lookup_by_fd(pim_ifp->igmp_socket_list, fd);
+ if (igmp)
+ return igmp;
+ }
+
+ return 0;
+}
+
+DEFUN (test_igmp_receive_report,
+ test_igmp_receive_report_cmd,
+ "test igmp receive report <0-65535> A.B.C.D <1-6> .LINE",
+ "Test\n"
+ "Test IGMP protocol\n"
+ "Test IGMP message\n"
+ "Test IGMP report\n"
+ "Socket\n"
+ "IGMP group address\n"
+ "Record type\n"
+ "Sources\n")
+{
+ char buf[1000];
+ char *igmp_msg;
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ int ip_msg_len;
+ int igmp_msg_len;
+ const char *socket;
+ int socket_fd;
+ const char *grp_str;
+ struct in_addr grp_addr;
+ const char *record_type_str;
+ int record_type;
+ const char *src_str;
+ int result;
+ struct igmp_sock *igmp;
+ char *group_record;
+ int num_sources;
+ struct in_addr *sources;
+ struct in_addr *src_addr;
+ int argi;
+
+ socket = argv[0];
+ socket_fd = atoi(socket);
+ igmp = find_igmp_sock_by_fd(socket_fd);
+ if (!igmp) {
+ vty_out(vty, "Could not find IGMP socket %s: fd=%d%s",
+ socket, socket_fd, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ grp_str = argv[1];
+ result = inet_pton(AF_INET, grp_str, &grp_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad group address %s: errno=%d: %s%s",
+ grp_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ record_type_str = argv[2];
+ record_type = atoi(record_type_str);
+
+ /*
+ Tweak IP header
+ */
+ ip_hdr = (struct ip *) buf;
+ ip_hdr->ip_p = PIM_IP_PROTO_IGMP;
+ ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
+ ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
+ ip_hdr->ip_src = igmp->ifaddr;
+ ip_hdr->ip_dst = igmp->ifaddr;
+
+ /*
+ Build IGMP v3 report message
+ */
+ igmp_msg = buf + ip_hlen;
+ group_record = igmp_msg + IGMP_V3_REPORT_GROUPPRECORD_OFFSET;
+ *igmp_msg = PIM_IGMP_V3_MEMBERSHIP_REPORT; /* type */
+ *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = 0; /* for computing checksum */
+ *(uint16_t *) (igmp_msg + IGMP_V3_REPORT_NUMGROUPS_OFFSET) = htons(1); /* one group record */
+ *(uint8_t *) (group_record + IGMP_V3_GROUP_RECORD_TYPE_OFFSET) = record_type;
+ *(struct in_addr *)(group_record + IGMP_V3_GROUP_RECORD_GROUP_OFFSET) = grp_addr;
+
+ /* Scan LINE sources */
+ sources = (struct in_addr *) (group_record + IGMP_V3_GROUP_RECORD_SOURCE_OFFSET);
+ src_addr = sources;
+ for (argi = 3; argi < argc; ++argi,++src_addr) {
+ src_str = argv[argi];
+ result = inet_pton(AF_INET, src_str, src_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad source address %s: errno=%d: %s%s",
+ src_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+ num_sources = src_addr - sources;
+
+ *(uint16_t *)(group_record + IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET) = htons(num_sources);
+
+ igmp_msg_len = IGMP_V3_MSG_MIN_SIZE + (num_sources << 4); /* v3 report for one single group record */
+
+ /* compute checksum */
+ *(uint16_t *)(igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = pim_inet_checksum(igmp_msg, igmp_msg_len);
+
+ /* "receive" message */
+
+ ip_msg_len = ip_hlen + igmp_msg_len;
+ result = pim_igmp_packet(igmp, buf, ip_msg_len);
+ if (result) {
+ vty_out(vty, "pim_igmp_packet(len=%d) returned: %d%s",
+ ip_msg_len, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+static int hexval(uint8_t ch)
+{
+ return isdigit(ch) ? (ch - '0') : (10 + tolower(ch) - 'a');
+}
+
+DEFUN (test_pim_receive_dump,
+ test_pim_receive_dump_cmd,
+ "test pim receive dump INTERFACE A.B.C.D .LINE",
+ "Test\n"
+ "Test PIM protocol\n"
+ "Test PIM message reception\n"
+ "Test PIM packet dump reception from neighbor\n"
+ "Interface\n"
+ "Neighbor address\n"
+ "Packet dump\n")
+{
+ char buf[1000];
+ char *pim_msg;
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ int ip_msg_len;
+ int pim_msg_size;
+ const char *neigh_str;
+ struct in_addr neigh_addr;
+ const char *ifname;
+ struct interface *ifp;
+ int argi;
+ int result;
+
+ /* Find interface */
+ ifname = argv[0];
+ ifp = if_lookup_by_name(ifname);
+ if (!ifp) {
+ vty_out(vty, "No such interface name %s%s",
+ ifname, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Neighbor address */
+ neigh_str = argv[1];
+ result = inet_pton(AF_INET, neigh_str, &neigh_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad neighbor address %s: errno=%d: %s%s",
+ neigh_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /*
+ Tweak IP header
+ */
+ ip_hdr = (struct ip *) buf;
+ ip_hdr->ip_p = PIM_IP_PROTO_PIM;
+ ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
+ ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
+ ip_hdr->ip_src = neigh_addr;
+ ip_hdr->ip_dst = qpim_all_pim_routers_addr;
+
+ /*
+ Build PIM hello message
+ */
+ pim_msg = buf + ip_hlen;
+ pim_msg_size = 0;
+
+ /* Scan LINE dump into buffer */
+ for (argi = 2; argi < argc; ++argi) {
+ const char *str = argv[argi];
+ int str_len = strlen(str);
+ int str_last = str_len - 1;
+ int i;
+
+ if (str_len % 2) {
+ vty_out(vty, "%% Uneven hex array arg %d=%s%s",
+ argi, str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ for (i = 0; i < str_last; i += 2) {
+ uint8_t octet;
+ int left;
+ uint8_t h1 = str[i];
+ uint8_t h2 = str[i + 1];
+
+ if (!isxdigit(h1) || !isxdigit(h2)) {
+ vty_out(vty, "%% Non-hex octet %c%c at hex array arg %d=%s%s",
+ h1, h2, argi, str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ octet = (hexval(h1) << 4) + hexval(h2);
+
+ left = sizeof(buf) - ip_hlen - pim_msg_size;
+ if (left < 1) {
+ vty_out(vty, "%% Overflow buf_size=%d buf_left=%d at hex array arg %d=%s octet %02x%s",
+ sizeof(buf), left, argi, str, octet, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ pim_msg[pim_msg_size++] = octet;
+ }
+ }
+
+ ip_msg_len = ip_hlen + pim_msg_size;
+
+ vty_out(vty, "Receiving: buf_size=%d ip_msg_size=%d pim_msg_size=%d%s",
+ sizeof(buf), ip_msg_len, pim_msg_size, VTY_NEWLINE);
+
+ /* "receive" message */
+
+ result = pim_pim_packet(ifp, buf, ip_msg_len);
+ if (result) {
+ vty_out(vty, "%% pim_pim_packet(len=%d) returned failure: %d%s",
+ ip_msg_len, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (test_pim_receive_hello,
+ test_pim_receive_hello_cmd,
+ "test pim receive hello INTERFACE A.B.C.D <0-65535> <0-65535> <0-65535> <0-32767> <0-65535> <0-1>[LINE]",
+ "Test\n"
+ "Test PIM protocol\n"
+ "Test PIM message reception\n"
+ "Test PIM hello reception from neighbor\n"
+ "Interface\n"
+ "Neighbor address\n"
+ "Neighbor holdtime\n"
+ "Neighbor DR priority\n"
+ "Neighbor generation ID\n"
+ "Neighbor propagation delay (msec)\n"
+ "Neighbor override interval (msec)\n"
+ "Neighbor LAN prune delay T-bit\n"
+ "Neighbor secondary addresses\n")
+{
+ char buf[1000];
+ char *pim_msg;
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ int ip_msg_len;
+ int pim_tlv_size;
+ int pim_msg_size;
+ const char *neigh_str;
+ struct in_addr neigh_addr;
+ const char *ifname;
+ struct interface *ifp;
+ uint16_t neigh_holdtime;
+ uint16_t neigh_propagation_delay;
+ uint16_t neigh_override_interval;
+ int neigh_can_disable_join_suppression;
+ uint32_t neigh_dr_priority;
+ uint32_t neigh_generation_id;
+ int argi;
+ int result;
+
+ /* Find interface */
+ ifname = argv[0];
+ ifp = if_lookup_by_name(ifname);
+ if (!ifp) {
+ vty_out(vty, "No such interface name %s%s",
+ ifname, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Neighbor address */
+ neigh_str = argv[1];
+ result = inet_pton(AF_INET, neigh_str, &neigh_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad neighbor address %s: errno=%d: %s%s",
+ neigh_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ neigh_holdtime = atoi(argv[2]);
+ neigh_dr_priority = atoi(argv[3]);
+ neigh_generation_id = atoi(argv[4]);
+ neigh_propagation_delay = atoi(argv[5]);
+ neigh_override_interval = atoi(argv[6]);
+ neigh_can_disable_join_suppression = atoi(argv[7]);
+
+ /*
+ Tweak IP header
+ */
+ ip_hdr = (struct ip *) buf;
+ ip_hdr->ip_p = PIM_IP_PROTO_PIM;
+ ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
+ ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
+ ip_hdr->ip_src = neigh_addr;
+ ip_hdr->ip_dst = qpim_all_pim_routers_addr;
+
+ /*
+ Build PIM hello message
+ */
+ pim_msg = buf + ip_hlen;
+
+ /* Scan LINE addresses */
+ for (argi = 8; argi < argc; ++argi) {
+ const char *sec_str = argv[argi];
+ struct in_addr sec_addr;
+ result = inet_pton(AF_INET, sec_str, &sec_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad neighbor secondary address %s: errno=%d: %s%s",
+ sec_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ vty_out(vty,
+ "FIXME WRITEME consider neighbor secondary address %s%s",
+ sec_str, VTY_NEWLINE);
+ }
+
+ pim_tlv_size = pim_hello_build_tlv(ifp->name,
+ pim_msg + PIM_PIM_MIN_LEN,
+ sizeof(buf) - ip_hlen - PIM_PIM_MIN_LEN,
+ neigh_holdtime,
+ neigh_dr_priority,
+ neigh_generation_id,
+ neigh_propagation_delay,
+ neigh_override_interval,
+ neigh_can_disable_join_suppression,
+ 0 /* FIXME secondary address list */);
+ if (pim_tlv_size < 0) {
+ vty_out(vty, "pim_hello_build_tlv() returned failure: %d%s",
+ pim_tlv_size, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ pim_msg_size = pim_tlv_size + PIM_PIM_MIN_LEN;
+
+ pim_msg_build_header(pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_HELLO);
+
+ /* "receive" message */
+
+ ip_msg_len = ip_hlen + pim_msg_size;
+ result = pim_pim_packet(ifp, buf, ip_msg_len);
+ if (result) {
+ vty_out(vty, "pim_pim_packet(len=%d) returned failure: %d%s",
+ ip_msg_len, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (test_pim_receive_assert,
+ test_pim_receive_assert_cmd,
+ "test pim receive assert INTERFACE A.B.C.D A.B.C.D A.B.C.D <0-65535> <0-65535> <0-1>",
+ "Test\n"
+ "Test PIM protocol\n"
+ "Test PIM message reception\n"
+ "Test reception of PIM assert\n"
+ "Interface\n"
+ "Neighbor address\n"
+ "Assert multicast group address\n"
+ "Assert unicast source address\n"
+ "Assert metric preference\n"
+ "Assert route metric\n"
+ "Assert RPT bit flag\n")
+{
+ char buf[1000];
+ char *buf_pastend = buf + sizeof(buf);
+ char *pim_msg;
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ int ip_msg_len;
+ int pim_msg_size;
+ const char *neigh_str;
+ struct in_addr neigh_addr;
+ const char *group_str;
+ struct in_addr group_addr;
+ const char *source_str;
+ struct in_addr source_addr;
+ const char *ifname;
+ struct interface *ifp;
+ uint32_t assert_metric_preference;
+ uint32_t assert_route_metric;
+ uint32_t assert_rpt_bit_flag;
+ int remain;
+ int result;
+
+ /* Find interface */
+ ifname = argv[0];
+ ifp = if_lookup_by_name(ifname);
+ if (!ifp) {
+ vty_out(vty, "No such interface name %s%s",
+ ifname, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Neighbor address */
+ neigh_str = argv[1];
+ result = inet_pton(AF_INET, neigh_str, &neigh_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad neighbor address %s: errno=%d: %s%s",
+ neigh_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Group address */
+ group_str = argv[2];
+ result = inet_pton(AF_INET, group_str, &group_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad group address %s: errno=%d: %s%s",
+ group_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Source address */
+ source_str = argv[3];
+ result = inet_pton(AF_INET, source_str, &source_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ assert_metric_preference = atoi(argv[4]);
+ assert_route_metric = atoi(argv[5]);
+ assert_rpt_bit_flag = atoi(argv[6]);
+
+ remain = buf_pastend - buf;
+ if (remain < (int) sizeof(struct ip)) {
+ vty_out(vty, "No room for ip header: buf_size=%d < ip_header_size=%d%s",
+ remain, sizeof(struct ip), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /*
+ Tweak IP header
+ */
+ ip_hdr = (struct ip *) buf;
+ ip_hdr->ip_p = PIM_IP_PROTO_PIM;
+ ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
+ ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
+ ip_hdr->ip_src = neigh_addr;
+ ip_hdr->ip_dst = qpim_all_pim_routers_addr;
+
+ /*
+ Build PIM assert message
+ */
+ pim_msg = buf + ip_hlen; /* skip ip header */
+
+ pim_msg_size = pim_assert_build_msg(pim_msg, buf_pastend - pim_msg, ifp,
+ group_addr, source_addr,
+ assert_metric_preference,
+ assert_route_metric,
+ assert_rpt_bit_flag);
+ if (pim_msg_size < 0) {
+ vty_out(vty, "Failure building PIM assert message: size=%d%s",
+ pim_msg_size, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* "receive" message */
+
+ ip_msg_len = ip_hlen + pim_msg_size;
+ result = pim_pim_packet(ifp, buf, ip_msg_len);
+ if (result) {
+ vty_out(vty, "pim_pim_packet(len=%d) returned failure: %d%s",
+ ip_msg_len, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+static int recv_joinprune(struct vty *vty,
+ const char *argv[],
+ int src_is_join)
+{
+ char buf[1000];
+ const char *buf_pastend = buf + sizeof(buf);
+ char *pim_msg;
+ char *pim_msg_curr;
+ int pim_msg_size;
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ int ip_msg_len;
+ uint16_t neigh_holdtime;
+ const char *neigh_dst_str;
+ struct in_addr neigh_dst_addr;
+ const char *neigh_src_str;
+ struct in_addr neigh_src_addr;
+ const char *group_str;
+ struct in_addr group_addr;
+ const char *source_str;
+ struct in_addr source_addr;
+ const char *ifname;
+ struct interface *ifp;
+ int result;
+ int remain;
+ uint16_t num_joined;
+ uint16_t num_pruned;
+
+ /* Find interface */
+ ifname = argv[0];
+ ifp = if_lookup_by_name(ifname);
+ if (!ifp) {
+ vty_out(vty, "No such interface name %s%s",
+ ifname, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ neigh_holdtime = atoi(argv[1]);
+
+ /* Neighbor destination address */
+ neigh_dst_str = argv[2];
+ result = inet_pton(AF_INET, neigh_dst_str, &neigh_dst_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad neighbor destination address %s: errno=%d: %s%s",
+ neigh_dst_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Neighbor source address */
+ neigh_src_str = argv[3];
+ result = inet_pton(AF_INET, neigh_src_str, &neigh_src_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad neighbor source address %s: errno=%d: %s%s",
+ neigh_src_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Multicast group address */
+ group_str = argv[4];
+ result = inet_pton(AF_INET, group_str, &group_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad group address %s: errno=%d: %s%s",
+ group_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Multicast source address */
+ source_str = argv[5];
+ result = inet_pton(AF_INET, source_str, &source_addr);
+ if (result <= 0) {
+ vty_out(vty, "Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /*
+ Tweak IP header
+ */
+ ip_hdr = (struct ip *) buf;
+ ip_hdr->ip_p = PIM_IP_PROTO_PIM;
+ ip_hlen = PIM_IP_HEADER_MIN_LEN; /* ip header length in bytes */
+ ip_hdr->ip_hl = ip_hlen >> 2; /* ip header length in 4-byte words */
+ ip_hdr->ip_src = neigh_src_addr;
+ ip_hdr->ip_dst = qpim_all_pim_routers_addr;
+
+ /*
+ Build PIM message
+ */
+ pim_msg = buf + ip_hlen;
+
+ /* skip room for pim header */
+ pim_msg_curr = pim_msg + PIM_MSG_HEADER_LEN;
+
+ remain = buf_pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_ucast(pim_msg_curr,
+ remain,
+ neigh_dst_addr);
+ if (!pim_msg_curr) {
+ vty_out(vty, "Failure encoding destination address %s: space left=%d%s",
+ neigh_dst_str, remain, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ remain = buf_pastend - pim_msg_curr;
+ if (remain < 4) {
+ vty_out(vty, "Group will not fit: space left=%d%s",
+ remain, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ *pim_msg_curr = 0; /* reserved */
+ ++pim_msg_curr;
+ *pim_msg_curr = 1; /* number of groups */
+ ++pim_msg_curr;
+ *((uint16_t *) pim_msg_curr) = htons(neigh_holdtime);
+ ++pim_msg_curr;
+ ++pim_msg_curr;
+
+ remain = buf_pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_group(pim_msg_curr,
+ remain,
+ group_addr);
+ if (!pim_msg_curr) {
+ vty_out(vty, "Failure encoding group address %s: space left=%d%s",
+ group_str, remain, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ remain = buf_pastend - pim_msg_curr;
+ if (remain < 4) {
+ vty_out(vty, "Sources will not fit: space left=%d%s",
+ remain, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (src_is_join) {
+ num_joined = 1;
+ num_pruned = 0;
+ }
+ else {
+ num_joined = 0;
+ num_pruned = 1;
+ }
+
+ /* number of joined sources */
+ *((uint16_t *) pim_msg_curr) = htons(num_joined);
+ ++pim_msg_curr;
+ ++pim_msg_curr;
+
+ /* number of pruned sources */
+ *((uint16_t *) pim_msg_curr) = htons(num_pruned);
+ ++pim_msg_curr;
+ ++pim_msg_curr;
+
+ remain = buf_pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_source(pim_msg_curr,
+ remain,
+ source_addr);
+ if (!pim_msg_curr) {
+ vty_out(vty, "Failure encoding source address %s: space left=%d%s",
+ source_str, remain, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Add PIM header */
+
+ pim_msg_size = pim_msg_curr - pim_msg;
+
+ pim_msg_build_header(pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_JOIN_PRUNE);
+
+ /*
+ "Receive" message
+ */
+
+ ip_msg_len = ip_hlen + pim_msg_size;
+ result = pim_pim_packet(ifp, buf, ip_msg_len);
+ if (result) {
+ vty_out(vty, "pim_pim_packet(len=%d) returned failure: %d%s",
+ ip_msg_len, result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (test_pim_receive_join,
+ test_pim_receive_join_cmd,
+ "test pim receive join INTERFACE <0-65535> A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
+ "Test\n"
+ "Test PIM protocol\n"
+ "Test PIM message reception\n"
+ "Test PIM join reception from neighbor\n"
+ "Interface\n"
+ "Neighbor holdtime\n"
+ "Upstream neighbor unicast destination address\n"
+ "Downstream neighbor unicast source address\n"
+ "Multicast group address\n"
+ "Unicast source address\n")
+{
+ return recv_joinprune(vty, argv, 1 /* src_is_join=true */);
+}
+
+DEFUN (test_pim_receive_prune,
+ test_pim_receive_prune_cmd,
+ "test pim receive prune INTERFACE <0-65535> A.B.C.D A.B.C.D A.B.C.D A.B.C.D",
+ "Test\n"
+ "Test PIM protocol\n"
+ "Test PIM message reception\n"
+ "Test PIM prune reception from neighbor\n"
+ "Interface\n"
+ "Neighbor holdtime\n"
+ "Upstream neighbor unicast destination address\n"
+ "Downstream neighbor unicast source address\n"
+ "Multicast group address\n"
+ "Unicast source address\n")
+{
+ return recv_joinprune(vty, argv, 0 /* src_is_join=false */);
+}
+
+DEFUN (test_pim_receive_upcall,
+ test_pim_receive_upcall_cmd,
+ "test pim receive upcall (nocache|wrongvif|wholepkt) <0-65535> A.B.C.D A.B.C.D",
+ "Test\n"
+ "Test PIM protocol\n"
+ "Test PIM message reception\n"
+ "Test reception of kernel upcall\n"
+ "NOCACHE kernel upcall\n"
+ "WRONGVIF kernel upcall\n"
+ "WHOLEPKT kernel upcall\n"
+ "Input interface vif index\n"
+ "Multicast group address\n"
+ "Multicast source address\n")
+{
+ struct igmpmsg msg;
+ const char *upcall_type;
+ const char *group_str;
+ const char *source_str;
+ int result;
+
+ upcall_type = argv[0];
+
+ if (upcall_type[0] == 'n')
+ msg.im_msgtype = IGMPMSG_NOCACHE;
+ else if (upcall_type[1] == 'r')
+ msg.im_msgtype = IGMPMSG_WRONGVIF;
+ else if (upcall_type[1] == 'h')
+ msg.im_msgtype = IGMPMSG_WHOLEPKT;
+ else {
+ vty_out(vty, "Unknown kernel upcall type: %s%s",
+ upcall_type, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ msg.im_vif = atoi(argv[1]);
+
+ /* Group address */
+ group_str = argv[2];
+ result = inet_pton(AF_INET, group_str, &msg.im_dst);
+ if (result <= 0) {
+ vty_out(vty, "Bad group address %s: errno=%d: %s%s",
+ group_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* Source address */
+ source_str = argv[3];
+ result = inet_pton(AF_INET, source_str, &msg.im_src);
+ if (result <= 0) {
+ vty_out(vty, "Bad source address %s: errno=%d: %s%s",
+ source_str, errno, safe_strerror(errno), VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ msg.im_mbz = 0; /* Must be zero */
+
+ result = pim_mroute_msg(-1, (char *) &msg, sizeof(msg));
+ if (result) {
+ vty_out(vty, "pim_mroute_msg(len=%d) returned failure: %d%s",
+ sizeof(msg), result, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+void pim_cmd_init()
+{
+ install_node (&pim_global_node, pim_global_config_write); /* PIM_NODE */
+ install_node (&interface_node, pim_interface_config_write); /* INTERFACE_NODE */
+
+ install_element (CONFIG_NODE, &ip_multicast_routing_cmd);
+ install_element (CONFIG_NODE, &no_ip_multicast_routing_cmd);
+ install_element (CONFIG_NODE, &ip_ssmpingd_cmd);
+ install_element (CONFIG_NODE, &no_ip_ssmpingd_cmd);
+#if 0
+ install_element (CONFIG_NODE, &interface_cmd); /* from if.h */
+#else
+ install_element (CONFIG_NODE, &pim_interface_cmd);
+#endif
+ install_element (CONFIG_NODE, &no_interface_cmd); /* from if.h */
+
+ install_default (INTERFACE_NODE);
+ install_element (INTERFACE_NODE, &interface_ip_igmp_cmd);
+ install_element (INTERFACE_NODE, &interface_no_ip_igmp_cmd);
+ install_element (INTERFACE_NODE, &interface_ip_igmp_join_cmd);
+ install_element (INTERFACE_NODE, &interface_no_ip_igmp_join_cmd);
+ install_element (INTERFACE_NODE, &interface_ip_igmp_query_interval_cmd);
+ install_element (INTERFACE_NODE, &interface_no_ip_igmp_query_interval_cmd);
+ install_element (INTERFACE_NODE, &interface_ip_igmp_query_max_response_time_cmd);
+ install_element (INTERFACE_NODE, &interface_no_ip_igmp_query_max_response_time_cmd);
+ install_element (INTERFACE_NODE, &interface_ip_igmp_query_max_response_time_dsec_cmd);
+ install_element (INTERFACE_NODE, &interface_no_ip_igmp_query_max_response_time_dsec_cmd);
+ install_element (INTERFACE_NODE, &interface_ip_pim_ssm_cmd);
+ install_element (INTERFACE_NODE, &interface_no_ip_pim_ssm_cmd);
+
+ install_element (VIEW_NODE, &show_ip_igmp_interface_cmd);
+ install_element (VIEW_NODE, &show_ip_igmp_parameters_cmd);
+ install_element (VIEW_NODE, &show_ip_igmp_groups_cmd);
+ install_element (VIEW_NODE, &show_ip_igmp_groups_retransmissions_cmd);
+ install_element (VIEW_NODE, &show_ip_igmp_sources_cmd);
+ install_element (VIEW_NODE, &show_ip_igmp_sources_retransmissions_cmd);
+ install_element (VIEW_NODE, &show_ip_igmp_querier_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_assert_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_assert_internal_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_assert_metric_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_assert_winner_metric_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_dr_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_hello_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_interface_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_join_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_jp_override_interval_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_lan_prune_delay_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_local_membership_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_neighbor_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_rpf_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_secondary_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_upstream_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_upstream_join_desired_cmd);
+ install_element (VIEW_NODE, &show_ip_pim_upstream_rpf_cmd);
+ install_element (VIEW_NODE, &show_ip_multicast_cmd);
+ install_element (VIEW_NODE, &show_ip_mroute_cmd);
+ install_element (VIEW_NODE, &show_ip_mroute_count_cmd);
+ install_element (VIEW_NODE, &show_ip_route_cmd);
+ install_element (VIEW_NODE, &show_ip_ssmpingd_cmd);
+ install_element (VIEW_NODE, &show_debugging_cmd);
+
+ install_element (ENABLE_NODE, &clear_ip_interfaces_cmd);
+ install_element (ENABLE_NODE, &clear_ip_igmp_interfaces_cmd);
+ install_element (ENABLE_NODE, &clear_ip_pim_interfaces_cmd);
+
+ install_element (ENABLE_NODE, &show_ip_igmp_interface_cmd);
+ install_element (ENABLE_NODE, &show_ip_igmp_parameters_cmd);
+ install_element (ENABLE_NODE, &show_ip_igmp_groups_cmd);
+ install_element (ENABLE_NODE, &show_ip_igmp_groups_retransmissions_cmd);
+ install_element (ENABLE_NODE, &show_ip_igmp_sources_cmd);
+ install_element (ENABLE_NODE, &show_ip_igmp_sources_retransmissions_cmd);
+ install_element (ENABLE_NODE, &show_ip_igmp_querier_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_address_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_assert_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_assert_internal_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_assert_metric_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_assert_winner_metric_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_dr_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_hello_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_interface_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_join_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_jp_override_interval_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_lan_prune_delay_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_local_membership_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_neighbor_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_rpf_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_secondary_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_upstream_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_upstream_join_desired_cmd);
+ install_element (ENABLE_NODE, &show_ip_pim_upstream_rpf_cmd);
+ install_element (ENABLE_NODE, &show_ip_multicast_cmd);
+ install_element (ENABLE_NODE, &show_ip_mroute_cmd);
+ install_element (ENABLE_NODE, &show_ip_mroute_count_cmd);
+ install_element (ENABLE_NODE, &show_ip_route_cmd);
+ install_element (ENABLE_NODE, &show_ip_ssmpingd_cmd);
+ install_element (ENABLE_NODE, &show_debugging_cmd);
+
+ install_element (ENABLE_NODE, &test_igmp_receive_report_cmd);
+ install_element (ENABLE_NODE, &test_pim_receive_assert_cmd);
+ install_element (ENABLE_NODE, &test_pim_receive_dump_cmd);
+ install_element (ENABLE_NODE, &test_pim_receive_hello_cmd);
+ install_element (ENABLE_NODE, &test_pim_receive_join_cmd);
+ install_element (ENABLE_NODE, &test_pim_receive_prune_cmd);
+ install_element (ENABLE_NODE, &test_pim_receive_upcall_cmd);
+
+ install_element (ENABLE_NODE, &debug_igmp_cmd);
+ install_element (ENABLE_NODE, &no_debug_igmp_cmd);
+ install_element (ENABLE_NODE, &undebug_igmp_cmd);
+ install_element (ENABLE_NODE, &debug_igmp_events_cmd);
+ install_element (ENABLE_NODE, &no_debug_igmp_events_cmd);
+ install_element (ENABLE_NODE, &undebug_igmp_events_cmd);
+ install_element (ENABLE_NODE, &debug_igmp_packets_cmd);
+ install_element (ENABLE_NODE, &no_debug_igmp_packets_cmd);
+ install_element (ENABLE_NODE, &undebug_igmp_packets_cmd);
+ install_element (ENABLE_NODE, &debug_igmp_trace_cmd);
+ install_element (ENABLE_NODE, &no_debug_igmp_trace_cmd);
+ install_element (ENABLE_NODE, &undebug_igmp_trace_cmd);
+ install_element (ENABLE_NODE, &debug_pim_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_cmd);
+ install_element (ENABLE_NODE, &debug_pim_events_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_events_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_events_cmd);
+ install_element (ENABLE_NODE, &debug_pim_packets_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_packets_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_packets_cmd);
+ install_element (ENABLE_NODE, &debug_pim_packetdump_send_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_packetdump_send_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_packetdump_send_cmd);
+ install_element (ENABLE_NODE, &debug_pim_packetdump_recv_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_packetdump_recv_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_packetdump_recv_cmd);
+ install_element (ENABLE_NODE, &debug_pim_trace_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_trace_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_trace_cmd);
+ install_element (ENABLE_NODE, &debug_ssmpingd_cmd);
+ install_element (ENABLE_NODE, &no_debug_ssmpingd_cmd);
+ install_element (ENABLE_NODE, &undebug_ssmpingd_cmd);
+ install_element (ENABLE_NODE, &debug_pim_zebra_cmd);
+ install_element (ENABLE_NODE, &no_debug_pim_zebra_cmd);
+ install_element (ENABLE_NODE, &undebug_pim_zebra_cmd);
+
+ install_element (CONFIG_NODE, &debug_igmp_cmd);
+ install_element (CONFIG_NODE, &no_debug_igmp_cmd);
+ install_element (CONFIG_NODE, &undebug_igmp_cmd);
+ install_element (CONFIG_NODE, &debug_igmp_events_cmd);
+ install_element (CONFIG_NODE, &no_debug_igmp_events_cmd);
+ install_element (CONFIG_NODE, &undebug_igmp_events_cmd);
+ install_element (CONFIG_NODE, &debug_igmp_packets_cmd);
+ install_element (CONFIG_NODE, &no_debug_igmp_packets_cmd);
+ install_element (CONFIG_NODE, &undebug_igmp_packets_cmd);
+ install_element (CONFIG_NODE, &debug_igmp_trace_cmd);
+ install_element (CONFIG_NODE, &no_debug_igmp_trace_cmd);
+ install_element (CONFIG_NODE, &undebug_igmp_trace_cmd);
+ install_element (CONFIG_NODE, &debug_pim_cmd);
+ install_element (CONFIG_NODE, &no_debug_pim_cmd);
+ install_element (CONFIG_NODE, &undebug_pim_cmd);
+ install_element (CONFIG_NODE, &debug_pim_events_cmd);
+ install_element (CONFIG_NODE, &no_debug_pim_events_cmd);
+ install_element (CONFIG_NODE, &undebug_pim_events_cmd);
+ install_element (CONFIG_NODE, &debug_pim_packets_cmd);
+ install_element (CONFIG_NODE, &no_debug_pim_packets_cmd);
+ install_element (CONFIG_NODE, &undebug_pim_packets_cmd);
+ install_element (CONFIG_NODE, &debug_pim_trace_cmd);
+ install_element (CONFIG_NODE, &no_debug_pim_trace_cmd);
+ install_element (CONFIG_NODE, &undebug_pim_trace_cmd);
+ install_element (CONFIG_NODE, &debug_ssmpingd_cmd);
+ install_element (CONFIG_NODE, &no_debug_ssmpingd_cmd);
+ install_element (CONFIG_NODE, &undebug_ssmpingd_cmd);
+ install_element (CONFIG_NODE, &debug_pim_zebra_cmd);
+ install_element (CONFIG_NODE, &no_debug_pim_zebra_cmd);
+ install_element (CONFIG_NODE, &undebug_pim_zebra_cmd);
+}
diff --git a/pimd/pim_cmd.h b/pimd/pim_cmd.h
new file mode 100644
index 00000000..fd1a62fa
--- /dev/null
+++ b/pimd/pim_cmd.h
@@ -0,0 +1,62 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_CMD_H
+#define PIM_CMD_H
+
+#define PIM_STR "PIM information\n"
+#define IGMP_STR "IGMP information\n"
+#define IGMP_GROUP_STR "IGMP groups information\n"
+#define IGMP_SOURCE_STR "IGMP sources information\n"
+#define CONF_SSMPINGD_STR "Enable ssmpingd operation\n"
+#define SHOW_SSMPINGD_STR "ssmpingd operation\n"
+#define IFACE_PIM_STR "Enable PIM SSM operation\n"
+#define IFACE_IGMP_STR "Enable IGMP operation\n"
+#define IFACE_IGMP_QUERY_INTERVAL_STR "IGMP host query interval\n"
+#define IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_STR "IGMP max query response value (seconds)\n"
+#define IFACE_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC_STR "IGMP max query response value (deciseconds)\n"
+#define DEBUG_IGMP_STR "IGMP protocol activity\n"
+#define DEBUG_IGMP_EVENTS_STR "IGMP protocol events\n"
+#define DEBUG_IGMP_PACKETS_STR "IGMP protocol packets\n"
+#define DEBUG_IGMP_TRACE_STR "IGMP internal daemon activity\n"
+#define DEBUG_PIM_STR "PIM protocol activity\n"
+#define DEBUG_PIM_EVENTS_STR "PIM protocol events\n"
+#define DEBUG_PIM_PACKETS_STR "PIM protocol packets\n"
+#define DEBUG_PIM_PACKETDUMP_STR "PIM packet dump\n"
+#define DEBUG_PIM_PACKETDUMP_SEND_STR "Dump sent packets\n"
+#define DEBUG_PIM_PACKETDUMP_RECV_STR "Dump received packets\n"
+#define DEBUG_PIM_TRACE_STR "PIM internal daemon activity\n"
+#define DEBUG_PIM_ZEBRA_STR "ZEBRA protocol activity\n"
+#define DEBUG_SSMPINGD_STR "ssmpingd activity\n"
+#define CLEAR_IP_IGMP_STR "IGMP clear commands\n"
+#define CLEAR_IP_PIM_STR "PIM clear commands\n"
+#define MROUTE_STR "IP multicast routing table\n"
+
+#define PIM_CMD_NO "no"
+#define PIM_CMD_IP_MULTICAST_ROUTING "ip multicast-routing"
+#define PIM_CMD_IP_IGMP_QUERY_INTERVAL "ip igmp query-interval"
+#define PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME "ip igmp query-max-response-time"
+#define PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC "ip igmp query-max-response-time-dsec"
+
+void pim_cmd_init(void);
+
+#endif /* PIM_CMD_H */
diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c
new file mode 100644
index 00000000..545b3b12
--- /dev/null
+++ b/pimd/pim_hello.c
@@ -0,0 +1,529 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+
+#include "pimd.h"
+#include "pim_pim.h"
+#include "pim_str.h"
+#include "pim_tlv.h"
+#include "pim_util.h"
+#include "pim_hello.h"
+#include "pim_iface.h"
+#include "pim_neighbor.h"
+#include "pim_upstream.h"
+
+static void on_trace(const char *label,
+ struct interface *ifp, struct in_addr src)
+{
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src, src_str, sizeof(src_str));
+ zlog_debug("%s: from %s on %s",
+ label, src_str, ifp->name);
+ }
+}
+
+static void tlv_trace_bool(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int isset, int value)
+{
+ if (isset) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello option from %s on interface %s: %s=%d",
+ label,
+ src_str, ifname,
+ tlv_name, value);
+ }
+}
+
+static void tlv_trace_uint16(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int isset, uint16_t value)
+{
+ if (isset) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello option from %s on interface %s: %s=%u",
+ label,
+ src_str, ifname,
+ tlv_name, value);
+ }
+}
+
+static void tlv_trace_uint32(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int isset, uint32_t value)
+{
+ if (isset) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello option from %s on interface %s: %s=%u",
+ label,
+ src_str, ifname,
+ tlv_name, value);
+ }
+}
+
+static void tlv_trace_uint32_hex(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int isset, uint32_t value)
+{
+ if (isset) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello option from %s on interface %s: %s=%08x",
+ label,
+ src_str, ifname,
+ tlv_name, value);
+ }
+}
+
+#if 0
+static void tlv_trace(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int isset)
+{
+ if (isset) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello option from %s on interface %s: %s",
+ label,
+ src_str, ifname,
+ tlv_name);
+ }
+}
+#endif
+
+static void tlv_trace_list(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int isset, struct list *addr_list)
+{
+ if (isset) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello option from %s on interface %s: %s size=%d list=%x",
+ label,
+ src_str, ifname,
+ tlv_name,
+ addr_list ? ((int) listcount(addr_list)) : -1,
+ (unsigned) addr_list);
+ }
+}
+
+#define FREE_ADDR_LIST \
+ if (hello_option_addr_list) { \
+ list_delete(hello_option_addr_list); \
+ }
+
+#define FREE_ADDR_LIST_THEN_RETURN(code) \
+{ \
+ FREE_ADDR_LIST \
+ return (code); \
+}
+
+int pim_hello_recv(struct interface *ifp,
+ struct in_addr src_addr,
+ char *tlv_buf, int tlv_buf_size)
+{
+ struct pim_interface *pim_ifp;
+ struct pim_neighbor *neigh;
+ char *tlv_curr;
+ char *tlv_pastend;
+ pim_hello_options hello_options = 0; /* bit array recording options found */
+ uint16_t hello_option_holdtime = 0;
+ uint16_t hello_option_propagation_delay = 0;
+ uint16_t hello_option_override_interval = 0;
+ uint32_t hello_option_dr_priority = 0;
+ uint32_t hello_option_generation_id = 0;
+ struct list *hello_option_addr_list = 0;
+
+ on_trace(__PRETTY_FUNCTION__, ifp, src_addr);
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ ++pim_ifp->pim_ifstat_hello_recv;
+
+ /*
+ Parse PIM hello TLVs
+ */
+ zassert(tlv_buf_size >= 0);
+ tlv_curr = tlv_buf;
+ tlv_pastend = tlv_buf + tlv_buf_size;
+
+ while (tlv_curr < tlv_pastend) {
+ uint16_t option_type;
+ uint16_t option_len;
+ int remain = tlv_pastend - tlv_curr;
+
+ if (remain < PIM_TLV_MIN_SIZE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: short PIM hello TLV size=%d < min=%d from %s on interface %s",
+ __PRETTY_FUNCTION__,
+ remain, PIM_TLV_MIN_SIZE,
+ src_str, ifp->name);
+ FREE_ADDR_LIST_THEN_RETURN(-1);
+ }
+
+ option_type = PIM_TLV_GET_TYPE(tlv_curr);
+ tlv_curr += PIM_TLV_TYPE_SIZE;
+ option_len = PIM_TLV_GET_LENGTH(tlv_curr);
+ tlv_curr += PIM_TLV_LENGTH_SIZE;
+
+ if ((tlv_curr + option_len) > tlv_pastend) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: long PIM hello TLV type=%d length=%d > left=%d from %s on interface %s",
+ __PRETTY_FUNCTION__,
+ option_type, option_len, tlv_pastend - tlv_curr,
+ src_str, ifp->name);
+ FREE_ADDR_LIST_THEN_RETURN(-2);
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: parse left_size=%d: PIM hello TLV type=%d length=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ remain,
+ option_type, option_len,
+ src_str, ifp->name);
+ }
+
+ switch (option_type) {
+ case PIM_MSG_OPTION_TYPE_HOLDTIME:
+ if (pim_tlv_parse_holdtime(ifp->name, src_addr,
+ &hello_options,
+ &hello_option_holdtime,
+ option_len,
+ tlv_curr)) {
+ FREE_ADDR_LIST_THEN_RETURN(-3);
+ }
+ break;
+ case PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY:
+ if (pim_tlv_parse_lan_prune_delay(ifp->name, src_addr,
+ &hello_options,
+ &hello_option_propagation_delay,
+ &hello_option_override_interval,
+ option_len,
+ tlv_curr)) {
+ FREE_ADDR_LIST_THEN_RETURN(-4);
+ }
+ break;
+ case PIM_MSG_OPTION_TYPE_DR_PRIORITY:
+ if (pim_tlv_parse_dr_priority(ifp->name, src_addr,
+ &hello_options,
+ &hello_option_dr_priority,
+ option_len,
+ tlv_curr)) {
+ FREE_ADDR_LIST_THEN_RETURN(-5);
+ }
+ break;
+ case PIM_MSG_OPTION_TYPE_GENERATION_ID:
+ if (pim_tlv_parse_generation_id(ifp->name, src_addr,
+ &hello_options,
+ &hello_option_generation_id,
+ option_len,
+ tlv_curr)) {
+ FREE_ADDR_LIST_THEN_RETURN(-6);
+ }
+ break;
+ case PIM_MSG_OPTION_TYPE_ADDRESS_LIST:
+ if (pim_tlv_parse_addr_list(ifp->name, src_addr,
+ &hello_options,
+ &hello_option_addr_list,
+ option_len,
+ tlv_curr)) {
+ return -7;
+ }
+ break;
+ case PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH:
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: ignoring PIM hello dense-mode state refresh TLV option type=%d length=%d from %s on interface %s",
+ __PRETTY_FUNCTION__,
+ option_type, option_len,
+ src_str, ifp->name);
+ }
+ break;
+ default:
+ {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: ignoring unknown PIM hello TLV type=%d length=%d from %s on interface %s",
+ __PRETTY_FUNCTION__,
+ option_type, option_len,
+ src_str, ifp->name);
+ }
+ }
+
+ tlv_curr += option_len;
+ }
+
+ /*
+ Check received PIM hello options
+ */
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ tlv_trace_uint16(__PRETTY_FUNCTION__, "holdtime",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME),
+ hello_option_holdtime);
+ tlv_trace_uint16(__PRETTY_FUNCTION__, "propagation_delay",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY),
+ hello_option_propagation_delay);
+ tlv_trace_uint16(__PRETTY_FUNCTION__, "override_interval",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY),
+ hello_option_override_interval);
+ tlv_trace_bool(__PRETTY_FUNCTION__, "can_disable_join_suppression",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY),
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION));
+ tlv_trace_uint32(__PRETTY_FUNCTION__, "dr_priority",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_DR_PRIORITY),
+ hello_option_dr_priority);
+ tlv_trace_uint32_hex(__PRETTY_FUNCTION__, "generation_id",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_GENERATION_ID),
+ hello_option_generation_id);
+ tlv_trace_list(__PRETTY_FUNCTION__, "address_list",
+ ifp->name, src_addr,
+ PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_ADDRESS_LIST),
+ hello_option_addr_list);
+ }
+
+ if (!PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME)) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: PIM hello missing holdtime from %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ }
+
+ /*
+ New neighbor?
+ */
+
+ neigh = pim_neighbor_find(ifp, src_addr);
+ if (!neigh) {
+ /* Add as new neighbor */
+
+ neigh = pim_neighbor_add(ifp, src_addr,
+ hello_options,
+ hello_option_holdtime,
+ hello_option_propagation_delay,
+ hello_option_override_interval,
+ hello_option_dr_priority,
+ hello_option_generation_id,
+ hello_option_addr_list);
+ if (!neigh) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: failure creating PIM neighbor %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ FREE_ADDR_LIST_THEN_RETURN(-8);
+ }
+
+ /* actual addr list has been saved under neighbor */
+ return 0;
+ }
+
+ /*
+ Received generation ID ?
+ */
+
+ if (PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_GENERATION_ID)) {
+ /* GenID mismatch ? */
+ if (!PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_GENERATION_ID) ||
+ (hello_option_generation_id != neigh->generation_id)) {
+
+ /* GenID changed */
+
+ pim_upstream_rpf_genid_changed(neigh->source_addr);
+
+ /* GenID mismatch, then replace neighbor */
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: GenId mismatch new=%08x old=%08x: replacing neighbor %s on %s",
+ __PRETTY_FUNCTION__,
+ hello_option_generation_id,
+ neigh->generation_id,
+ src_str, ifp->name);
+ }
+
+ pim_upstream_rpf_genid_changed(neigh->source_addr);
+
+ pim_neighbor_delete(ifp, neigh, "GenID mismatch");
+ neigh = pim_neighbor_add(ifp, src_addr,
+ hello_options,
+ hello_option_holdtime,
+ hello_option_propagation_delay,
+ hello_option_override_interval,
+ hello_option_dr_priority,
+ hello_option_generation_id,
+ hello_option_addr_list);
+ if (!neigh) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: failure re-creating PIM neighbor %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ FREE_ADDR_LIST_THEN_RETURN(-9);
+ }
+ /* actual addr list is saved under neighbor */
+ return 0;
+
+ } /* GenId mismatch: replace neighbor */
+
+ } /* GenId received */
+
+ /*
+ Update existing neighbor
+ */
+
+ pim_neighbor_update(neigh,
+ hello_options,
+ hello_option_holdtime,
+ hello_option_dr_priority,
+ hello_option_addr_list);
+ /* actual addr list is saved under neighbor */
+ return 0;
+}
+
+int pim_hello_build_tlv(const char *ifname,
+ char *tlv_buf, int tlv_buf_size,
+ uint16_t holdtime,
+ uint32_t dr_priority,
+ uint32_t generation_id,
+ uint16_t propagation_delay,
+ uint16_t override_interval,
+ int can_disable_join_suppression,
+ struct list *ifconnected)
+{
+ char *curr = tlv_buf;
+ char *pastend = tlv_buf + tlv_buf_size;
+ char *tmp;
+
+ /*
+ * Append options
+ */
+
+ /* Holdtime */
+ curr = pim_tlv_append_uint16(curr,
+ pastend,
+ PIM_MSG_OPTION_TYPE_HOLDTIME,
+ holdtime);
+ if (!curr) {
+ zlog_warn("%s: could not set PIM hello Holdtime option for interface %s",
+ __PRETTY_FUNCTION__, ifname);
+ return -1;
+ }
+
+ /* LAN Prune Delay */
+ tmp = pim_tlv_append_2uint16(curr,
+ pastend,
+ PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY,
+ propagation_delay,
+ override_interval);
+ if (!tmp) {
+ zlog_warn("%s: could not set PIM LAN Prune Delay option for interface %s",
+ __PRETTY_FUNCTION__, ifname);
+ return -1;
+ }
+ if (can_disable_join_suppression) {
+ *((uint8_t*)(curr) + 4) |= 0x80; /* enable T bit */
+ }
+ curr = tmp;
+
+ /* DR Priority */
+ curr = pim_tlv_append_uint32(curr,
+ pastend,
+ PIM_MSG_OPTION_TYPE_DR_PRIORITY,
+ dr_priority);
+ if (!curr) {
+ zlog_warn("%s: could not set PIM hello DR Priority option for interface %s",
+ __PRETTY_FUNCTION__, ifname);
+ return -2;
+ }
+
+ /* Generation ID */
+ curr = pim_tlv_append_uint32(curr,
+ pastend,
+ PIM_MSG_OPTION_TYPE_GENERATION_ID,
+ generation_id);
+ if (!curr) {
+ zlog_warn("%s: could not set PIM hello Generation ID option for interface %s",
+ __PRETTY_FUNCTION__, ifname);
+ return -3;
+ }
+
+ /* Secondary Address List */
+ if (ifconnected) {
+ curr = pim_tlv_append_addrlist_ucast(curr,
+ pastend,
+ ifconnected);
+ if (!curr) {
+ zlog_warn("%s: could not set PIM hello Secondary Address List option for interface %s",
+ __PRETTY_FUNCTION__, ifname);
+ return -4;
+ }
+ }
+
+ return curr - tlv_buf;
+}
+
+/*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Thus, if a router needs to send a Join/Prune or Assert message on an
+ interface on which it has not yet sent a Hello message with the
+ currently configured IP address, then it MUST immediately send the
+ relevant Hello message without waiting for the Hello Timer to
+ expire, followed by the Join/Prune or Assert message.
+*/
+void pim_hello_require(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+
+ zassert(pim_ifp);
+
+ if (pim_ifp->pim_ifstat_hello_sent)
+ return;
+
+ pim_hello_restart_now(ifp); /* Send hello and restart timer */
+}
diff --git a/pimd/pim_hello.h b/pimd/pim_hello.h
new file mode 100644
index 00000000..90a11ba6
--- /dev/null
+++ b/pimd/pim_hello.h
@@ -0,0 +1,46 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_HELLO_H
+#define PIM_HELLO_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+int pim_hello_recv(struct interface *ifp,
+ struct in_addr src_addr,
+ char *tlv_buf, int tlv_buf_size);
+
+int pim_hello_build_tlv(const char *ifname,
+ char *tlv_buf, int tlv_buf_size,
+ uint16_t holdtime,
+ uint32_t dr_priority,
+ uint32_t generation_id,
+ uint16_t propagation_delay,
+ uint16_t override_interval,
+ int can_disable_join_suppression,
+ struct list *ifconnected);
+
+void pim_hello_require(struct interface *ifp);
+
+#endif /* PIM_HELLO_H */
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c
new file mode 100644
index 00000000..7806c805
--- /dev/null
+++ b/pimd/pim_iface.c
@@ -0,0 +1,1134 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "if.h"
+#include "log.h"
+#include "vty.h"
+#include "memory.h"
+#include "prefix.h"
+
+#include "pimd.h"
+#include "pim_iface.h"
+#include "pim_igmp.h"
+#include "pim_mroute.h"
+#include "pim_oil.h"
+#include "pim_str.h"
+#include "pim_pim.h"
+#include "pim_neighbor.h"
+#include "pim_ifchannel.h"
+#include "pim_rand.h"
+#include "pim_sock.h"
+#include "pim_ssmpingd.h"
+
+static void pim_if_igmp_join_del_all(struct interface *ifp);
+
+void pim_if_init()
+{
+ if_init();
+}
+
+static void *if_list_clean(struct pim_interface *pim_ifp)
+{
+ if (pim_ifp->igmp_join_list) {
+ list_delete(pim_ifp->igmp_join_list);
+ }
+
+ if (pim_ifp->igmp_socket_list) {
+ list_delete(pim_ifp->igmp_socket_list);
+ }
+
+ if (pim_ifp->pim_neighbor_list) {
+ list_delete(pim_ifp->pim_neighbor_list);
+ }
+
+ if (pim_ifp->pim_ifchannel_list) {
+ list_delete(pim_ifp->pim_ifchannel_list);
+ }
+
+ XFREE(MTYPE_PIM_INTERFACE, pim_ifp);
+
+ return 0;
+}
+
+struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ zassert(!ifp->info);
+
+ pim_ifp = XMALLOC(MTYPE_PIM_INTERFACE, sizeof(*pim_ifp));
+ if (!pim_ifp) {
+ zlog_err("PIM XMALLOC(%d) failure", sizeof(*pim_ifp));
+ return 0;
+ }
+
+ pim_ifp->options = 0;
+ pim_ifp->mroute_vif_index = -1;
+
+ pim_ifp->igmp_default_robustness_variable = IGMP_DEFAULT_ROBUSTNESS_VARIABLE;
+ pim_ifp->igmp_default_query_interval = IGMP_GENERAL_QUERY_INTERVAL;
+ pim_ifp->igmp_query_max_response_time_dsec = IGMP_QUERY_MAX_RESPONSE_TIME_DSEC;
+ pim_ifp->igmp_specific_query_max_response_time_dsec = IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC;
+
+ /*
+ RFC 3376: 8.3. Query Response Interval
+ The number of seconds represented by the [Query Response Interval]
+ must be less than the [Query Interval].
+ */
+ zassert(pim_ifp->igmp_query_max_response_time_dsec < pim_ifp->igmp_default_query_interval);
+
+ if (pim)
+ PIM_IF_DO_PIM(pim_ifp->options);
+ if (igmp)
+ PIM_IF_DO_IGMP(pim_ifp->options);
+
+#if 0
+ /* FIXME: Should join? */
+ PIM_IF_DO_IGMP_LISTEN_ALLROUTERS(pim_ifp->options);
+#endif
+
+ pim_ifp->igmp_join_list = 0;
+ pim_ifp->igmp_socket_list = 0;
+ pim_ifp->pim_neighbor_list = 0;
+ pim_ifp->pim_ifchannel_list = 0;
+
+ /* list of struct igmp_sock */
+ pim_ifp->igmp_socket_list = list_new();
+ if (!pim_ifp->igmp_socket_list) {
+ zlog_err("%s %s: failure: igmp_socket_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return if_list_clean(pim_ifp);
+ }
+ pim_ifp->igmp_socket_list->del = (void (*)(void *)) igmp_sock_free;
+
+ /* list of struct pim_neighbor */
+ pim_ifp->pim_neighbor_list = list_new();
+ if (!pim_ifp->pim_neighbor_list) {
+ zlog_err("%s %s: failure: pim_neighbor_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return if_list_clean(pim_ifp);
+ }
+ pim_ifp->pim_neighbor_list->del = (void (*)(void *)) pim_neighbor_free;
+
+ /* list of struct pim_ifchannel */
+ pim_ifp->pim_ifchannel_list = list_new();
+ if (!pim_ifp->pim_ifchannel_list) {
+ zlog_err("%s %s: failure: pim_ifchannel_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return if_list_clean(pim_ifp);
+ }
+ pim_ifp->pim_ifchannel_list->del = (void (*)(void *)) pim_ifchannel_free;
+
+ ifp->info = pim_ifp;
+
+ pim_sock_reset(ifp);
+
+ zassert(PIM_IF_TEST_PIM(pim_ifp->options) || PIM_IF_TEST_IGMP(pim_ifp->options));
+
+ if (PIM_MROUTE_IS_ENABLED) {
+ pim_if_add_vif(ifp);
+ }
+
+ return pim_ifp;
+}
+
+void pim_if_delete(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ if (pim_ifp->igmp_join_list) {
+ pim_if_igmp_join_del_all(ifp);
+ }
+ zassert(!pim_ifp->igmp_join_list);
+
+ zassert(pim_ifp->igmp_socket_list);
+ zassert(!listcount(pim_ifp->igmp_socket_list));
+
+ zassert(pim_ifp->pim_neighbor_list);
+ zassert(!listcount(pim_ifp->pim_neighbor_list));
+
+ zassert(pim_ifp->pim_ifchannel_list);
+ zassert(!listcount(pim_ifp->pim_ifchannel_list));
+
+ if (PIM_MROUTE_IS_ENABLED) {
+ pim_if_del_vif(ifp);
+ }
+
+ list_delete(pim_ifp->igmp_socket_list);
+ list_delete(pim_ifp->pim_neighbor_list);
+ list_delete(pim_ifp->pim_ifchannel_list);
+
+ XFREE(MTYPE_PIM_INTERFACE, pim_ifp);
+
+ ifp->info = 0;
+}
+
+void pim_if_update_could_assert(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct listnode *next_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, node, next_node, ch)) {
+ pim_ifchannel_update_could_assert(ch);
+ }
+}
+
+static void pim_if_update_my_assert_metric(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct listnode *next_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, node, next_node, ch)) {
+ pim_ifchannel_update_my_assert_metric(ch);
+ }
+}
+
+static void pim_addr_change(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ pim_if_dr_election(ifp); /* Done TODO T30 */
+ pim_if_update_join_desired(pim_ifp); /* depends on DR */
+ pim_if_update_could_assert(ifp); /* depends on DR */
+ pim_if_update_my_assert_metric(ifp); /* depends on could_assert */
+ pim_if_update_assert_tracking_desired(ifp); /* depends on DR, join_desired */
+
+ /*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ 1) Before an interface goes down or changes primary IP address, a
+ Hello message with a zero HoldTime should be sent immediately
+ (with the old IP address if the IP address changed).
+ -- FIXME See CAVEAT C13
+
+ 2) After an interface has changed its IP address, it MUST send a
+ Hello message with its new IP address.
+ -- DONE below
+
+ 3) If an interface changes one of its secondary IP addresses, a
+ Hello message with an updated Address_List option and a non-zero
+ HoldTime should be sent immediately.
+ -- FIXME See TODO T31
+ */
+ pim_ifp->pim_ifstat_hello_sent = 0; /* reset hello counter */
+ if (pim_ifp->pim_sock_fd < 0)
+ return;
+ pim_hello_restart_now(ifp); /* send hello and restart timer */
+}
+
+static void on_primary_address_change(struct interface *ifp,
+ const char *caller,
+ struct in_addr old_addr,
+ struct in_addr new_addr)
+{
+ struct pim_interface *pim_ifp;
+
+ {
+ char old_str[100];
+ char new_str[100];
+ pim_inet4_dump("<old?>", old_addr, old_str, sizeof(old_str));
+ pim_inet4_dump("<new?>", new_addr, new_str, sizeof(new_str));
+ zlog_info("%s: %s: primary address changed from %s to %s on interface %s",
+ __PRETTY_FUNCTION__, caller,
+ old_str, new_str, ifp->name);
+ }
+
+ pim_ifp = ifp->info;
+
+ if (pim_ifp) {
+ if (PIM_IF_TEST_PIM(pim_ifp->options)) {
+ pim_addr_change(ifp);
+ }
+ }
+}
+
+static void detect_primary_address_change(struct interface *ifp,
+ const char *caller)
+{
+ struct pim_interface *pim_ifp;
+ struct in_addr new_prim_addr;
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return;
+
+ new_prim_addr = pim_find_primary_addr(ifp);
+
+ if (PIM_DEBUG_ZEBRA) {
+ char new_prim_str[100];
+ char old_prim_str[100];
+ pim_inet4_dump("<new?>", new_prim_addr, new_prim_str, sizeof(new_prim_str));
+ pim_inet4_dump("<old?>", pim_ifp->primary_address, old_prim_str, sizeof(old_prim_str));
+ zlog_debug("%s: old primary addr %s, new primary addr %s on interface %s",
+ __PRETTY_FUNCTION__,
+ old_prim_str, new_prim_str, ifp->name);
+ }
+
+ if (new_prim_addr.s_addr != pim_ifp->primary_address.s_addr) {
+ struct in_addr old_addr = pim_ifp->primary_address;
+ pim_ifp->primary_address = new_prim_addr;
+
+ on_primary_address_change(ifp, caller, old_addr, new_prim_addr);
+ }
+}
+
+void pim_if_addr_add(struct connected *ifc)
+{
+ struct pim_interface *pim_ifp;
+ struct interface *ifp;
+ struct in_addr ifaddr;
+
+ zassert(ifc);
+
+ ifp = ifc->ifp;
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return;
+
+ if (!if_is_operative(ifp))
+ return;
+
+ ifaddr = ifc->address->u.prefix4;
+
+ detect_primary_address_change(ifp, __PRETTY_FUNCTION__);
+
+ if (PIM_IF_TEST_IGMP(pim_ifp->options)) {
+ struct igmp_sock *igmp;
+
+ /* lookup IGMP socket */
+ igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list,
+ ifaddr);
+ if (!igmp) {
+ /* if addr new, add IGMP socket */
+ pim_igmp_sock_add(pim_ifp->igmp_socket_list, ifaddr, ifp);
+ }
+ } /* igmp */
+
+ if (PIM_IF_TEST_PIM(pim_ifp->options)) {
+
+ /* Interface has a valid primary address ? */
+ if (PIM_INADDR_ISNOT_ANY(pim_ifp->primary_address)) {
+
+ /* Interface has a valid socket ? */
+ if (pim_ifp->pim_sock_fd < 0) {
+ if (pim_sock_add(ifp)) {
+ zlog_warn("Failure creating PIM socket for interface %s",
+ ifp->name);
+ }
+ }
+
+ }
+ } /* pim */
+
+ if (PIM_MROUTE_IS_ENABLED) {
+ /*
+ PIM or IGMP is enabled on interface, and there is at least one
+ address assigned, then try to create a vif_index.
+ */
+ if (pim_ifp->mroute_vif_index < 0) {
+ pim_if_add_vif(ifp);
+ }
+ }
+}
+
+static void pim_if_addr_del_igmp(struct connected *ifc)
+{
+ struct pim_interface *pim_ifp = ifc->ifp->info;
+ struct igmp_sock *igmp;
+ struct in_addr ifaddr;
+
+ if (ifc->address->family != AF_INET) {
+ /* non-IPv4 address */
+ return;
+ }
+
+ if (!pim_ifp) {
+ /* IGMP not enabled on interface */
+ return;
+ }
+
+ ifaddr = ifc->address->u.prefix4;
+
+ /* lookup IGMP socket */
+ igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list,
+ ifaddr);
+ if (igmp) {
+ /* if addr found, del IGMP socket */
+ igmp_sock_delete(igmp);
+ }
+}
+
+static void pim_if_addr_del_pim(struct connected *ifc)
+{
+ struct pim_interface *pim_ifp = ifc->ifp->info;
+
+ if (ifc->address->family != AF_INET) {
+ /* non-IPv4 address */
+ return;
+ }
+
+ if (!pim_ifp) {
+ /* PIM not enabled on interface */
+ return;
+ }
+
+ if (PIM_INADDR_ISNOT_ANY(pim_ifp->primary_address)) {
+ /* Interface keeps a valid primary address */
+ return;
+ }
+
+ if (pim_ifp->pim_sock_fd < 0) {
+ /* Interface does not hold a valid socket any longer */
+ return;
+ }
+
+ /*
+ pim_sock_delete() closes the socket, stops read and timer threads,
+ and kills all neighbors.
+ */
+ pim_sock_delete(ifc->ifp, "last address has been removed from interface");
+}
+
+void pim_if_addr_del(struct connected *ifc)
+{
+ struct interface *ifp;
+
+ zassert(ifc);
+ ifp = ifc->ifp;
+ zassert(ifp);
+
+ detect_primary_address_change(ifp, __PRETTY_FUNCTION__);
+
+ pim_if_addr_del_igmp(ifc);
+ pim_if_addr_del_pim(ifc);
+}
+
+void pim_if_addr_add_all(struct interface *ifp)
+{
+ struct connected *ifc;
+ struct listnode *node;
+ struct listnode *nextnode;
+
+ /* PIM/IGMP enabled ? */
+ if (!ifp->info)
+ return;
+
+ for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ pim_if_addr_add(ifc);
+ }
+}
+
+void pim_if_addr_del_all(struct interface *ifp)
+{
+ struct connected *ifc;
+ struct listnode *node;
+ struct listnode *nextnode;
+
+ /* PIM/IGMP enabled ? */
+ if (!ifp->info)
+ return;
+
+ for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ pim_if_addr_del(ifc);
+ }
+}
+
+void pim_if_addr_del_all_igmp(struct interface *ifp)
+{
+ struct connected *ifc;
+ struct listnode *node;
+ struct listnode *nextnode;
+
+ /* PIM/IGMP enabled ? */
+ if (!ifp->info)
+ return;
+
+ for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ pim_if_addr_del_igmp(ifc);
+ }
+}
+
+void pim_if_addr_del_all_pim(struct interface *ifp)
+{
+ struct connected *ifc;
+ struct listnode *node;
+ struct listnode *nextnode;
+
+ /* PIM/IGMP enabled ? */
+ if (!ifp->info)
+ return;
+
+ for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ pim_if_addr_del_pim(ifc);
+ }
+}
+
+static struct in_addr find_first_addr(struct interface *ifp)
+{
+ struct connected *ifc;
+ struct listnode *node;
+ struct in_addr addr;
+
+ for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ if (PIM_INADDR_IS_ANY(p->u.prefix4)) {
+ zlog_warn("%s: null IPv4 address connected to interface %s",
+ __PRETTY_FUNCTION__, ifp->name);
+ continue;
+ }
+
+ return p->u.prefix4;
+ }
+
+ addr.s_addr = PIM_NET_INADDR_ANY;
+
+ return addr;
+}
+
+struct in_addr pim_find_primary_addr(struct interface *ifp)
+{
+ return find_first_addr(ifp);
+}
+
+/*
+ pim_if_add_vif() uses ifindex as vif_index
+
+ see also pim_if_find_vifindex_by_ifindex()
+ */
+int pim_if_add_vif(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp = ifp->info;
+ struct in_addr ifaddr;
+
+ zassert(pim_ifp);
+
+ if (pim_ifp->mroute_vif_index > 0) {
+ zlog_warn("%s: vif_index=%d > 0 on interface %s ifindex=%d",
+ __PRETTY_FUNCTION__,
+ pim_ifp->mroute_vif_index, ifp->name, ifp->ifindex);
+ return -1;
+ }
+
+ if (ifp->ifindex < 1) {
+ zlog_warn("%s: ifindex=%d < 1 on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->ifindex, ifp->name);
+ return -2;
+ }
+
+ if (ifp->ifindex >= MAXVIFS) {
+ zlog_warn("%s: ifindex=%d >= MAXVIFS=%d on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->ifindex, MAXVIFS, ifp->name);
+ return -3;
+ }
+
+ ifaddr = pim_ifp->primary_address;
+ if (PIM_INADDR_IS_ANY(ifaddr)) {
+ zlog_warn("%s: could not get address for interface %s ifindex=%d",
+ __PRETTY_FUNCTION__,
+ ifp->name, ifp->ifindex);
+ return -4;
+ }
+
+ if (pim_mroute_add_vif(ifp->ifindex, ifaddr)) {
+ /* pim_mroute_add_vif reported error */
+ return -5;
+ }
+
+ pim_ifp->mroute_vif_index = ifp->ifindex;
+
+ /*
+ Update highest vif_index
+ */
+ if (pim_ifp->mroute_vif_index > qpim_mroute_oif_highest_vif_index) {
+ qpim_mroute_oif_highest_vif_index = pim_ifp->mroute_vif_index;
+ }
+
+ return 0;
+}
+
+static int iflist_find_highest_vif_index()
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int highest_vif_index = -1;
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ if (pim_ifp->mroute_vif_index > highest_vif_index) {
+ highest_vif_index = pim_ifp->mroute_vif_index;
+ }
+ }
+
+ return highest_vif_index;
+}
+
+int pim_if_del_vif(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp = ifp->info;
+ int old_vif_index;
+
+ if (pim_ifp->mroute_vif_index < 1) {
+ zlog_warn("%s: vif_index=%d < 1 on interface %s ifindex=%d",
+ __PRETTY_FUNCTION__,
+ pim_ifp->mroute_vif_index, ifp->name, ifp->ifindex);
+ return -1;
+ }
+
+ if (pim_mroute_del_vif(pim_ifp->mroute_vif_index)) {
+ /* pim_mroute_del_vif reported error */
+ return -2;
+ }
+
+ /*
+ Update highest vif_index
+ */
+
+ /* save old vif_index in order to compare with highest below */
+ old_vif_index = pim_ifp->mroute_vif_index;
+
+ pim_ifp->mroute_vif_index = -1;
+
+ if (old_vif_index == qpim_mroute_oif_highest_vif_index) {
+ qpim_mroute_oif_highest_vif_index = iflist_find_highest_vif_index();
+ }
+
+ return 0;
+}
+
+void pim_if_add_vif_all()
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct interface *ifp;
+
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ if (!ifp->info)
+ continue;
+
+ pim_if_add_vif(ifp);
+ }
+}
+
+void pim_if_del_vif_all()
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct interface *ifp;
+
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ if (!ifp->info)
+ continue;
+
+ pim_if_del_vif(ifp);
+ }
+}
+
+struct interface *pim_if_find_by_vif_index(int vif_index)
+{
+ struct listnode *ifnode;
+ struct interface *ifp;
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, ifnode, ifp)) {
+ if (ifp->info) {
+ struct pim_interface *pim_ifp;
+ pim_ifp = ifp->info;
+ if (vif_index == pim_ifp->mroute_vif_index)
+ return ifp;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ pim_if_add_vif() uses ifindex as vif_index
+ */
+int pim_if_find_vifindex_by_ifindex(int ifindex)
+{
+ return ifindex;
+}
+
+int pim_if_lan_delay_enabled(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+ zassert(pim_ifp->pim_number_of_nonlandelay_neighbors >= 0);
+
+ return pim_ifp->pim_number_of_nonlandelay_neighbors == 0;
+}
+
+uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp)
+{
+ if (pim_if_lan_delay_enabled(ifp)) {
+ struct pim_interface *pim_ifp;
+ pim_ifp = ifp->info;
+ return pim_ifp->pim_neighbors_highest_propagation_delay_msec;
+ }
+ else {
+ return PIM_DEFAULT_PROPAGATION_DELAY_MSEC;
+ }
+}
+
+uint16_t pim_if_effective_override_interval_msec(struct interface *ifp)
+{
+ if (pim_if_lan_delay_enabled(ifp)) {
+ struct pim_interface *pim_ifp;
+ pim_ifp = ifp->info;
+ return pim_ifp->pim_neighbors_highest_override_interval_msec;
+ }
+ else {
+ return PIM_DEFAULT_OVERRIDE_INTERVAL_MSEC;
+ }
+}
+
+int pim_if_t_override_msec(struct interface *ifp)
+{
+ int effective_override_interval_msec;
+ int t_override_msec;
+
+ effective_override_interval_msec =
+ pim_if_effective_override_interval_msec(ifp);
+
+ t_override_msec = pim_rand_next(0, effective_override_interval_msec);
+
+ return t_override_msec;
+}
+
+uint16_t pim_if_jp_override_interval_msec(struct interface *ifp)
+{
+ return pim_if_effective_propagation_delay_msec(ifp) +
+ pim_if_effective_override_interval_msec(ifp);
+}
+
+/*
+ RFC 4601: 4.1.6. State Summarization Macros
+
+ The function NBR( I, A ) uses information gathered through PIM Hello
+ messages to map the IP address A of a directly connected PIM
+ neighbor router on interface I to the primary IP address of the same
+ router (Section 4.3.4). The primary IP address of a neighbor is the
+ address that it uses as the source of its PIM Hello messages.
+*/
+struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp,
+ struct in_addr addr)
+{
+ struct listnode *neighnode;
+ struct pim_neighbor *neigh;
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ zlog_warn("%s: multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ return 0;
+ }
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) {
+
+ /* primary address ? */
+ if (neigh->source_addr.s_addr == addr.s_addr)
+ return neigh;
+
+ /* secondary address ? */
+ if (pim_neighbor_find_secondary(neigh, addr))
+ return neigh;
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s: neighbor not found for address %s on interface %s",
+ __PRETTY_FUNCTION__,
+ addr_str, ifp->name);
+ }
+
+ return 0;
+}
+
+long pim_if_t_suppressed_msec(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ long t_suppressed_msec;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ /* join suppression disabled ? */
+ if (PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options))
+ return 0;
+
+ /* t_suppressed = t_periodic * rand(1.1, 1.4) */
+
+ t_suppressed_msec = qpim_t_periodic * pim_rand_next(1100, 1400);
+
+ return t_suppressed_msec;
+}
+
+static void igmp_join_free(struct igmp_join *ij)
+{
+ XFREE(MTYPE_PIM_IGMP_JOIN, ij);
+}
+
+static struct igmp_join *igmp_join_find(struct list *join_list,
+ struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ struct listnode *node;
+ struct igmp_join *ij;
+
+ zassert(join_list);
+
+ for (ALL_LIST_ELEMENTS_RO(join_list, node, ij)) {
+ if ((group_addr.s_addr == ij->group_addr.s_addr) &&
+ (source_addr.s_addr == ij->source_addr.s_addr))
+ return ij;
+ }
+
+ return 0;
+}
+
+static int igmp_join_sock(const char *ifname,
+ int ifindex,
+ struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ int join_fd;
+
+ join_fd = pim_socket_raw(IPPROTO_IGMP);
+ if (join_fd < 0) {
+ return -1;
+ }
+
+ if (pim_socket_join_source(join_fd, ifindex, group_addr, source_addr, ifname)) {
+ close(join_fd);
+ return -2;
+ }
+
+ return join_fd;
+}
+
+static struct igmp_join *igmp_join_new(struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct igmp_join *ij;
+ int join_fd;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ join_fd = igmp_join_sock(ifp->name, ifp->ifindex, group_addr, source_addr);
+ if (join_fd < 0) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: igmp_join_sock() failure for IGMP group %s source %s on interface %s",
+ __PRETTY_FUNCTION__,
+ group_str, source_str, ifp->name);
+ return 0;
+ }
+
+ ij = XMALLOC(MTYPE_PIM_IGMP_JOIN, sizeof(*ij));
+ if (!ij) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_err("%s: XMALLOC(%d) failure for IGMP group %s source %s on interface %s",
+ __PRETTY_FUNCTION__,
+ sizeof(*ij), group_str, source_str, ifp->name);
+ close(join_fd);
+ return 0;
+ }
+
+ ij->sock_fd = join_fd;
+ ij->group_addr = group_addr;
+ ij->source_addr = source_addr;
+
+ listnode_add(pim_ifp->igmp_join_list, ij);
+
+ return ij;
+}
+
+int pim_if_igmp_join_add(struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct igmp_join *ij;
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ zlog_warn("%s: multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ return -1;
+ }
+
+ if (!pim_ifp->igmp_join_list) {
+ pim_ifp->igmp_join_list = list_new();
+ if (!pim_ifp->igmp_join_list) {
+ zlog_err("%s %s: failure: igmp_join_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return -2;
+ }
+ pim_ifp->igmp_join_list->del = (void (*)(void *)) igmp_join_free;
+ }
+
+ ij = igmp_join_find(pim_ifp->igmp_join_list, group_addr, source_addr);
+ if (ij) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: can't re-join existing IGMP group %s source %s on interface %s",
+ __PRETTY_FUNCTION__,
+ group_str, source_str, ifp->name);
+ return -3;
+ }
+
+ ij = igmp_join_new(ifp, group_addr, source_addr);
+ if (!ij) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: igmp_join_new() failure for IGMP group %s source %s on interface %s",
+ __PRETTY_FUNCTION__,
+ group_str, source_str, ifp->name);
+ return -4;
+ }
+
+ return 0;
+}
+
+
+
+int pim_if_igmp_join_del(struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct igmp_join *ij;
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ zlog_warn("%s: multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ return -1;
+ }
+
+ if (!pim_ifp->igmp_join_list) {
+ zlog_warn("%s: no IGMP join on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ return -2;
+ }
+
+ ij = igmp_join_find(pim_ifp->igmp_join_list, group_addr, source_addr);
+ if (!ij) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: could not find IGMP group %s source %s on interface %s",
+ __PRETTY_FUNCTION__,
+ group_str, source_str, ifp->name);
+ return -3;
+ }
+
+ if (close(ij->sock_fd)) {
+ int e = errno;
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: failure closing sock_fd=%d for IGMP group %s source %s on interface %s: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ ij->sock_fd, group_str, source_str, ifp->name, e, safe_strerror(e));
+ /* warning only */
+ }
+ listnode_delete(pim_ifp->igmp_join_list, ij);
+ igmp_join_free(ij);
+ if (listcount(pim_ifp->igmp_join_list) < 1) {
+ list_delete(pim_ifp->igmp_join_list);
+ pim_ifp->igmp_join_list = 0;
+ }
+
+ return 0;
+}
+
+static void pim_if_igmp_join_del_all(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct listnode *nextnode;
+ struct igmp_join *ij;
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ zlog_warn("%s: multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ return;
+ }
+
+ if (!pim_ifp->igmp_join_list)
+ return;
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->igmp_join_list, node, nextnode, ij))
+ pim_if_igmp_join_del(ifp, ij->group_addr, ij->source_addr);
+}
+
+/*
+ RFC 4601
+
+ Transitions from "I am Assert Loser" State
+
+ Current Winner's GenID Changes or NLT Expires
+
+ The Neighbor Liveness Timer associated with the current winner
+ expires or we receive a Hello message from the current winner
+ reporting a different GenID from the one it previously reported.
+ This indicates that the current winner's interface or router has
+ gone down (and may have come back up), and so we must assume it no
+ longer knows it was the winner.
+ */
+void pim_if_assert_on_neighbor_down(struct interface *ifp,
+ struct in_addr neigh_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct listnode *next_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, node, next_node, ch)) {
+ /* Is (S,G,I) assert loser ? */
+ if (ch->ifassert_state != PIM_IFASSERT_I_AM_LOSER)
+ continue;
+ /* Dead neighbor was winner ? */
+ if (ch->ifassert_winner.s_addr != neigh_addr.s_addr)
+ continue;
+
+ assert_action_a5(ch);
+ }
+}
+
+void pim_if_update_join_desired(struct pim_interface *pim_ifp)
+{
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ /* clear off flag from interface's upstreams */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED_UPDATED(ch->upstream->flags);
+ }
+
+ /* scan per-interface (S,G,I) state on this I interface */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ struct pim_upstream *up = ch->upstream;
+
+ if (PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED_UPDATED(up->flags))
+ continue;
+
+ /* update join_desired for the global (S,G) state */
+ pim_upstream_update_join_desired(up);
+ PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED_UPDATED(up->flags);
+ }
+}
+
+void pim_if_update_assert_tracking_desired(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct listnode *next_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return;
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, node, next_node, ch)) {
+ pim_ifchannel_update_assert_tracking_desired(ch);
+ }
+}
diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h
new file mode 100644
index 00000000..0a702c27
--- /dev/null
+++ b/pimd/pim_iface.h
@@ -0,0 +1,160 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_IFACE_H
+#define PIM_IFACE_H
+
+#include <zebra.h>
+
+#include "if.h"
+#include "vty.h"
+
+#include "pim_igmp.h"
+#include "pim_upstream.h"
+
+#define PIM_IF_MASK_PIM (1 << 0)
+#define PIM_IF_MASK_IGMP (1 << 1)
+#define PIM_IF_MASK_IGMP_LISTEN_ALLROUTERS (1 << 2)
+#define PIM_IF_MASK_PIM_CAN_DISABLE_JOIN_SUPRESSION (1 << 3)
+
+#define PIM_IF_IS_DELETED(ifp) ((ifp)->ifindex == IFINDEX_INTERNAL)
+
+#define PIM_IF_TEST_PIM(options) (PIM_IF_MASK_PIM & (options))
+#define PIM_IF_TEST_IGMP(options) (PIM_IF_MASK_IGMP & (options))
+#define PIM_IF_TEST_IGMP_LISTEN_ALLROUTERS(options) (PIM_IF_MASK_IGMP_LISTEN_ALLROUTERS & (options))
+#define PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(options) (PIM_IF_MASK_PIM_CAN_DISABLE_JOIN_SUPRESSION & (options))
+
+#define PIM_IF_DO_PIM(options) ((options) |= PIM_IF_MASK_PIM)
+#define PIM_IF_DO_IGMP(options) ((options) |= PIM_IF_MASK_IGMP)
+#define PIM_IF_DO_IGMP_LISTEN_ALLROUTERS(options) ((options) |= PIM_IF_MASK_IGMP_LISTEN_ALLROUTERS)
+#define PIM_IF_DO_PIM_CAN_DISABLE_JOIN_SUPRESSION(options) ((options) |= PIM_IF_MASK_PIM_CAN_DISABLE_JOIN_SUPRESSION)
+
+#define PIM_IF_DONT_PIM(options) ((options) &= ~PIM_IF_MASK_PIM)
+#define PIM_IF_DONT_IGMP(options) ((options) &= ~PIM_IF_MASK_IGMP)
+#define PIM_IF_DONT_IGMP_LISTEN_ALLROUTERS(options) ((options) &= ~PIM_IF_MASK_IGMP_LISTEN_ALLROUTERS)
+#define PIM_IF_DONT_PIM_CAN_DISABLE_JOIN_SUPRESSION(options) ((options) &= ~PIM_IF_MASK_PIM_CAN_DISABLE_JOIN_SUPRESSION)
+
+struct pim_interface {
+ uint32_t options; /* bit vector */
+ int mroute_vif_index;
+ struct in_addr primary_address; /* remember addr to detect change */
+
+ int igmp_default_robustness_variable; /* IGMPv3 QRV */
+ int igmp_default_query_interval; /* IGMPv3 secs between general queries */
+ int igmp_query_max_response_time_dsec; /* IGMPv3 Max Response Time in dsecs for general queries */
+ int igmp_specific_query_max_response_time_dsec; /* IGMPv3 Max Response Time in dsecs for specific queries */
+ struct list *igmp_socket_list; /* list of struct igmp_sock */
+ struct list *igmp_join_list; /* list of struct igmp_join */
+
+ int pim_sock_fd; /* PIM socket file descriptor */
+ struct thread *t_pim_sock_read; /* thread for reading PIM socket */
+ int64_t pim_sock_creation; /* timestamp of PIM socket creation */
+
+ struct thread *t_pim_hello_timer;
+ int pim_hello_period;
+ int pim_default_holdtime;
+ int pim_triggered_hello_delay;
+ uint32_t pim_generation_id;
+ uint16_t pim_propagation_delay_msec; /* config */
+ uint16_t pim_override_interval_msec; /* config */
+ struct list *pim_neighbor_list; /* list of struct pim_neighbor */
+ struct list *pim_ifchannel_list; /* list of struct pim_ifchannel */
+
+ /* neighbors without lan_delay */
+ int pim_number_of_nonlandelay_neighbors;
+ uint16_t pim_neighbors_highest_propagation_delay_msec;
+ uint16_t pim_neighbors_highest_override_interval_msec;
+
+ /* DR Election */
+ int64_t pim_dr_election_last; /* timestamp */
+ int pim_dr_election_count;
+ struct in_addr pim_dr_addr;
+ uint32_t pim_dr_priority; /* config */
+ int pim_dr_num_nondrpri_neighbors; /* neighbors without dr_pri */
+
+ int64_t pim_ifstat_start; /* start timestamp for stats */
+ uint32_t pim_ifstat_hello_sent;
+ uint32_t pim_ifstat_hello_sendfail;
+ uint32_t pim_ifstat_hello_recv;
+ uint32_t pim_ifstat_hello_recvfail;
+};
+
+/*
+ if default_holdtime is set (>= 0), use it;
+ otherwise default_holdtime is 3.5 * hello_period
+ */
+#define PIM_IF_DEFAULT_HOLDTIME(pim_ifp) \
+ (((pim_ifp)->pim_default_holdtime < 0) ? \
+ ((pim_ifp)->pim_hello_period * 7 / 2) : \
+ ((pim_ifp)->pim_default_holdtime))
+
+void pim_if_init(void);
+
+struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim);
+void pim_if_delete(struct interface *ifp);
+void pim_if_addr_add(struct connected *ifc);
+void pim_if_addr_del(struct connected *ifc);
+void pim_if_addr_add_all(struct interface *ifp);
+void pim_if_addr_del_all(struct interface *ifp);
+void pim_if_addr_del_all_igmp(struct interface *ifp);
+void pim_if_addr_del_all_pim(struct interface *ifp);
+
+int pim_if_add_vif(struct interface *ifp);
+int pim_if_del_vif(struct interface *ifp);
+void pim_if_add_vif_all(void);
+void pim_if_del_vif_all(void);
+
+struct interface *pim_if_find_by_vif_index(int vif_index);
+int pim_if_find_vifindex_by_ifindex(int ifindex);
+
+int pim_if_lan_delay_enabled(struct interface *ifp);
+uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp);
+uint16_t pim_if_effective_override_interval_msec(struct interface *ifp);
+uint16_t pim_if_jp_override_interval_msec(struct interface *ifp);
+struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp,
+ struct in_addr addr);
+
+long pim_if_t_suppressed_msec(struct interface *ifp);
+int pim_if_t_override_msec(struct interface *ifp);
+
+struct in_addr pim_find_primary_addr(struct interface *ifp);
+
+int pim_if_igmp_join_add(struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr);
+int pim_if_igmp_join_del(struct interface *ifp,
+ struct in_addr group_addr,
+ struct in_addr source_addr);
+
+void pim_if_update_could_assert(struct interface *ifp);
+
+void pim_if_assert_on_neighbor_down(struct interface *ifp,
+ struct in_addr neigh_addr);
+
+void pim_if_rpf_interface_changed(struct interface *old_rpf_ifp,
+ struct pim_upstream *up);
+
+void pim_if_update_join_desired(struct pim_interface *pim_ifp);
+
+void pim_if_update_assert_tracking_desired(struct interface *ifp);
+
+#endif /* PIM_IFACE_H */
diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c
new file mode 100644
index 00000000..7f946cfd
--- /dev/null
+++ b/pimd/pim_ifchannel.c
@@ -0,0 +1,893 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "linklist.h"
+#include "thread.h"
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_str.h"
+#include "pim_iface.h"
+#include "pim_ifchannel.h"
+#include "pim_zebra.h"
+#include "pim_time.h"
+#include "pim_msg.h"
+#include "pim_pim.h"
+#include "pim_join.h"
+#include "pim_rpf.h"
+#include "pim_macro.h"
+
+void pim_ifchannel_free(struct pim_ifchannel *ch)
+{
+ zassert(!ch->t_ifjoin_expiry_timer);
+ zassert(!ch->t_ifjoin_prune_pending_timer);
+ zassert(!ch->t_ifassert_timer);
+
+ XFREE(MTYPE_PIM_IFCHANNEL, ch);
+}
+
+void pim_ifchannel_delete(struct pim_ifchannel *ch)
+{
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ch->interface->info;
+ zassert(pim_ifp);
+
+ if (ch->ifjoin_state != PIM_IFJOIN_NOINFO) {
+ pim_upstream_update_join_desired(ch->upstream);
+ }
+
+ pim_upstream_del(ch->upstream);
+
+ THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
+ THREAD_OFF(ch->t_ifassert_timer);
+
+ /*
+ notice that listnode_delete() can't be moved
+ into pim_ifchannel_free() because the later is
+ called by list_delete_all_node()
+ */
+ listnode_delete(pim_ifp->pim_ifchannel_list, ch);
+
+ pim_ifchannel_free(ch);
+}
+
+#define IFCHANNEL_NOINFO(ch) \
+ ( \
+ ((ch)->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO) \
+ && \
+ ((ch)->ifjoin_state == PIM_IFJOIN_NOINFO) \
+ && \
+ ((ch)->ifassert_state == PIM_IFASSERT_NOINFO) \
+ )
+
+static void delete_on_noinfo(struct pim_ifchannel *ch)
+{
+ if (IFCHANNEL_NOINFO(ch)) {
+
+ /* In NOINFO state, timers should have been cleared */
+ zassert(!ch->t_ifjoin_expiry_timer);
+ zassert(!ch->t_ifjoin_prune_pending_timer);
+ zassert(!ch->t_ifassert_timer);
+
+ pim_ifchannel_delete(ch);
+ }
+}
+
+void pim_ifchannel_ifjoin_switch(const char *caller,
+ struct pim_ifchannel *ch,
+ enum pim_ifjoin_state new_state)
+{
+ enum pim_ifjoin_state old_state = ch->ifjoin_state;
+
+ if (old_state == new_state) {
+ zlog_debug("%s calledby %s: non-transition on state %d (%s)",
+ __PRETTY_FUNCTION__, caller, new_state,
+ pim_ifchannel_ifjoin_name(new_state));
+ return;
+ }
+
+ zassert(old_state != new_state);
+
+ ch->ifjoin_state = new_state;
+
+ /* Transition to/from NOINFO ? */
+ if (
+ (old_state == PIM_IFJOIN_NOINFO)
+ ||
+ (new_state == PIM_IFJOIN_NOINFO)
+ ) {
+
+ if (PIM_DEBUG_PIM_EVENTS) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("PIM_IFCHANNEL_%s: (S,G)=(%s,%s) on interface %s",
+ ((new_state == PIM_IFJOIN_NOINFO) ? "DOWN" : "UP"),
+ src_str, grp_str, ch->interface->name);
+ }
+
+ /*
+ Record uptime of state transition to/from NOINFO
+ */
+ ch->ifjoin_creation = pim_time_monotonic_sec();
+
+ pim_upstream_update_join_desired(ch->upstream);
+ pim_ifchannel_update_could_assert(ch);
+ pim_ifchannel_update_assert_tracking_desired(ch);
+ }
+}
+
+const char *pim_ifchannel_ifjoin_name(enum pim_ifjoin_state ifjoin_state)
+{
+ switch (ifjoin_state) {
+ case PIM_IFJOIN_NOINFO: return "NOINFO";
+ case PIM_IFJOIN_JOIN: return "JOIN";
+ case PIM_IFJOIN_PRUNE_PENDING: return "PRUNEP";
+ }
+
+ return "ifjoin_bad_state";
+}
+
+const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state)
+{
+ switch (ifassert_state) {
+ case PIM_IFASSERT_NOINFO: return "NOINFO";
+ case PIM_IFASSERT_I_AM_WINNER: return "WINNER";
+ case PIM_IFASSERT_I_AM_LOSER: return "LOSER";
+ }
+
+ return "ifassert_bad_state";
+}
+
+/*
+ RFC 4601: 4.6.5. Assert State Macros
+
+ AssertWinner(S,G,I) defaults to NULL and AssertWinnerMetric(S,G,I)
+ defaults to Infinity when in the NoInfo state.
+*/
+void reset_ifassert_state(struct pim_ifchannel *ch)
+{
+ THREAD_OFF(ch->t_ifassert_timer);
+
+ pim_ifassert_winner_set(ch,
+ PIM_IFASSERT_NOINFO,
+ qpim_inaddr_any,
+ qpim_infinite_assert_metric);
+}
+
+static struct pim_ifchannel *pim_ifchannel_new(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_ifchannel *ch;
+ struct pim_interface *pim_ifp;
+ struct pim_upstream *up;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ up = pim_upstream_add(source_addr, group_addr);
+ if (!up) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ zlog_err("%s: could not attach upstream (S,G)=(%s,%s) on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return 0;
+ }
+
+ ch = XMALLOC(MTYPE_PIM_IFCHANNEL, sizeof(*ch));
+ if (!ch) {
+ zlog_err("%s: PIM XMALLOC(%d) failure",
+ __PRETTY_FUNCTION__, sizeof(*ch));
+ return 0;
+ }
+
+ ch->flags = 0;
+ ch->upstream = up;
+ ch->interface = ifp;
+ ch->source_addr = source_addr;
+ ch->group_addr = group_addr;
+ ch->local_ifmembership = PIM_IFMEMBERSHIP_NOINFO;
+
+ ch->ifjoin_state = PIM_IFJOIN_NOINFO;
+ ch->t_ifjoin_expiry_timer = 0;
+ ch->t_ifjoin_prune_pending_timer = 0;
+ ch->ifjoin_creation = 0;
+
+ /* Assert state */
+ ch->t_ifassert_timer = 0;
+ reset_ifassert_state(ch);
+ if (pim_macro_ch_could_assert_eval(ch))
+ PIM_IF_FLAG_SET_COULD_ASSERT(ch->flags);
+ else
+ PIM_IF_FLAG_UNSET_COULD_ASSERT(ch->flags);
+
+ if (pim_macro_assert_tracking_desired_eval(ch))
+ PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(ch->flags);
+ else
+ PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch->flags);
+
+ ch->ifassert_my_metric = pim_macro_ch_my_assert_metric_eval(ch);
+
+ /* Attach to list */
+ listnode_add(pim_ifp->pim_ifchannel_list, ch);
+
+ zassert(IFCHANNEL_NOINFO(ch));
+
+ return ch;
+}
+
+struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ ifp->name);
+ return 0;
+ }
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ if (
+ (source_addr.s_addr == ch->source_addr.s_addr) &&
+ (group_addr.s_addr == ch->group_addr.s_addr)
+ ) {
+ return ch;
+ }
+ }
+
+ return 0;
+}
+
+static void ifmembership_set(struct pim_ifchannel *ch,
+ enum pim_ifmembership membership)
+{
+ if (ch->local_ifmembership == membership)
+ return;
+
+ {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_info("%s: (S,G)=(%s,%s) membership now is %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ membership == PIM_IFMEMBERSHIP_INCLUDE ? "INCLUDE" : "NOINFO",
+ ch->interface->name);
+ }
+
+ ch->local_ifmembership = membership;
+
+ pim_upstream_update_join_desired(ch->upstream);
+ pim_ifchannel_update_could_assert(ch);
+ pim_ifchannel_update_assert_tracking_desired(ch);
+}
+
+
+void pim_ifchannel_membership_clear(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *ch_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) {
+ ifmembership_set(ch, PIM_IFMEMBERSHIP_NOINFO);
+ }
+}
+
+void pim_ifchannel_delete_on_noinfo(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct listnode *next_node;
+ struct pim_ifchannel *ch;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, node, next_node, ch)) {
+ delete_on_noinfo(ch);
+ }
+}
+
+struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_ifchannel *ch;
+ char src_str[100];
+ char grp_str[100];
+
+ ch = pim_ifchannel_find(ifp, source_addr, group_addr);
+ if (ch)
+ return ch;
+
+ ch = pim_ifchannel_new(ifp, source_addr, group_addr);
+ if (ch)
+ return ch;
+
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: pim_ifchannel_new() failure for (S,G)=(%s,%s) on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+
+ return 0;
+}
+
+static void ifjoin_to_noinfo(struct pim_ifchannel *ch)
+{
+ pim_forward_stop(ch);
+ pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_NOINFO);
+ delete_on_noinfo(ch);
+}
+
+static int on_ifjoin_expiry_timer(struct thread *t)
+{
+ struct pim_ifchannel *ch;
+
+ zassert(t);
+ ch = THREAD_ARG(t);
+ zassert(ch);
+
+ ch->t_ifjoin_expiry_timer = 0;
+
+ zassert(ch->ifjoin_state == PIM_IFJOIN_JOIN);
+
+ ifjoin_to_noinfo(ch);
+ /* ch may have been deleted */
+
+ return 0;
+}
+
+static void prune_echo(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct in_addr neigh_dst_addr;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ neigh_dst_addr = pim_ifp->primary_address;
+
+ if (PIM_DEBUG_PIM_EVENTS) {
+ char source_str[100];
+ char group_str[100];
+ char neigh_dst_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<neigh?>", neigh_dst_addr, neigh_dst_str, sizeof(neigh_dst_str));
+ zlog_debug("%s: sending PruneEcho(S,G)=(%s,%s) to upstream=%s on interface %s",
+ __PRETTY_FUNCTION__, source_str, group_str, neigh_dst_str, ifp->name);
+ }
+
+ pim_joinprune_send(ifp, neigh_dst_addr, source_addr, group_addr,
+ 0 /* boolean: send_join=false (prune) */);
+}
+
+static int on_ifjoin_prune_pending_timer(struct thread *t)
+{
+ struct pim_ifchannel *ch;
+ int send_prune_echo; /* boolean */
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct in_addr ch_source;
+ struct in_addr ch_group;
+
+ zassert(t);
+ ch = THREAD_ARG(t);
+ zassert(ch);
+
+ ch->t_ifjoin_prune_pending_timer = 0;
+
+ zassert(ch->ifjoin_state == PIM_IFJOIN_PRUNE_PENDING);
+
+ /* Send PruneEcho(S,G) ? */
+ ifp = ch->interface;
+ pim_ifp = ifp->info;
+ send_prune_echo = (listcount(pim_ifp->pim_neighbor_list) > 1);
+
+ /* Save (S,G) */
+ ch_source = ch->source_addr;
+ ch_group = ch->group_addr;
+
+ ifjoin_to_noinfo(ch);
+ /* from here ch may have been deleted */
+
+ if (send_prune_echo)
+ prune_echo(ifp, ch_source, ch_group);
+
+ return 0;
+}
+
+static void check_recv_upstream(int is_join,
+ struct interface *recv_ifp,
+ struct in_addr upstream,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ uint8_t source_flags,
+ int holdtime)
+{
+ struct pim_upstream *up;
+
+ /* Upstream (S,G) in Joined state ? */
+ up = pim_upstream_find(source_addr, group_addr);
+ if (!up)
+ return;
+ if (up->join_state != PIM_UPSTREAM_JOINED)
+ return;
+
+ /* Upstream (S,G) in Joined state */
+
+ if (PIM_INADDR_IS_ANY(up->rpf.rpf_addr)) {
+ /* RPF'(S,G) not found */
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s %s: RPF'(%s,%s) not found",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str);
+ return;
+ }
+
+ /* upstream directed to RPF'(S,G) ? */
+ if (upstream.s_addr != up->rpf.rpf_addr.s_addr) {
+ char src_str[100];
+ char grp_str[100];
+ char up_str[100];
+ char rpf_str[100];
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<up?>", upstream, up_str, sizeof(up_str));
+ pim_inet4_dump("<rpf?>", up->rpf.rpf_addr, rpf_str, sizeof(rpf_str));
+ zlog_warn("%s %s: (S,G)=(%s,%s) upstream=%s not directed to RPF'(S,G)=%s on interface %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ up_str, rpf_str, recv_ifp->name);
+ return;
+ }
+ /* upstream directed to RPF'(S,G) */
+
+ if (is_join) {
+ /* Join(S,G) to RPF'(S,G) */
+ pim_upstream_join_suppress(up, up->rpf.rpf_addr, holdtime);
+ return;
+ }
+
+ /* Prune to RPF'(S,G) */
+
+ if (source_flags & PIM_RPT_BIT_MASK) {
+ if (source_flags & PIM_WILDCARD_BIT_MASK) {
+ /* Prune(*,G) to RPF'(S,G) */
+ pim_upstream_join_timer_decrease_to_t_override("Prune(*,G)",
+ up, up->rpf.rpf_addr);
+ return;
+ }
+
+ /* Prune(S,G,rpt) to RPF'(S,G) */
+ pim_upstream_join_timer_decrease_to_t_override("Prune(S,G,rpt)",
+ up, up->rpf.rpf_addr);
+ return;
+ }
+
+ /* Prune(S,G) to RPF'(S,G) */
+ pim_upstream_join_timer_decrease_to_t_override("Prune(S,G)", up,
+ up->rpf.rpf_addr);
+}
+
+static int nonlocal_upstream(int is_join,
+ struct interface *recv_ifp,
+ struct in_addr upstream,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ uint8_t source_flags,
+ uint16_t holdtime)
+{
+ struct pim_interface *recv_pim_ifp;
+ int is_local; /* boolean */
+
+ recv_pim_ifp = recv_ifp->info;
+ zassert(recv_pim_ifp);
+
+ is_local = (upstream.s_addr == recv_pim_ifp->primary_address.s_addr);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char up_str[100];
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<upstream?>", upstream, up_str, sizeof(up_str));
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: recv %s (S,G)=(%s,%s) to %s upstream=%s on %s",
+ __PRETTY_FUNCTION__,
+ is_join ? "join" : "prune",
+ src_str, grp_str,
+ is_local ? "local" : "non-local",
+ up_str, recv_ifp->name);
+ }
+
+ if (is_local)
+ return 0;
+
+ /*
+ Since recv upstream addr was not directed to our primary
+ address, check if we should react to it in any way.
+ */
+ check_recv_upstream(is_join, recv_ifp, upstream, source_addr, group_addr,
+ source_flags, holdtime);
+
+ return 1; /* non-local */
+}
+
+void pim_ifchannel_join_add(struct interface *ifp,
+ struct in_addr neigh_addr,
+ struct in_addr upstream,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ uint8_t source_flags,
+ uint16_t holdtime)
+{
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+
+ if (nonlocal_upstream(1 /* join */, ifp, upstream,
+ source_addr, group_addr, source_flags, holdtime)) {
+ return;
+ }
+
+ ch = pim_ifchannel_add(ifp, source_addr, group_addr);
+ if (!ch)
+ return;
+
+ /*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ Transitions from "I am Assert Loser" State
+
+ Receive Join(S,G) on Interface I
+
+ We receive a Join(S,G) that has the Upstream Neighbor Address
+ field set to my primary IP address on interface I. The action is
+ to transition to NoInfo state, delete this (S,G) assert state
+ (Actions A5 below), and allow the normal PIM Join/Prune mechanisms
+ to operate.
+
+ Notice: The nonlocal_upstream() test above ensures the upstream
+ address of the join message is our primary address.
+ */
+ if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
+ char src_str[100];
+ char grp_str[100];
+ char neigh_str[100];
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<neigh?>", neigh_addr, neigh_str, sizeof(neigh_str));
+ zlog_warn("%s: Assert Loser recv Join(%s,%s) from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, neigh_str, ifp->name);
+
+ assert_action_a5(ch);
+ }
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ switch (ch->ifjoin_state) {
+ case PIM_IFJOIN_NOINFO:
+ pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_JOIN);
+ if (pim_macro_chisin_oiflist(ch)) {
+ pim_forward_start(ch);
+ }
+ break;
+ case PIM_IFJOIN_JOIN:
+ zassert(!ch->t_ifjoin_prune_pending_timer);
+
+ /*
+ In the JOIN state ch->t_ifjoin_expiry_timer may be NULL due to a
+ previously received join message with holdtime=0xFFFF.
+ */
+ if (ch->t_ifjoin_expiry_timer) {
+ unsigned long remain =
+ thread_timer_remain_second(ch->t_ifjoin_expiry_timer);
+ if (remain > holdtime) {
+ /*
+ RFC 4601: 4.5.3. Receiving (S,G) Join/Prune Messages
+
+ Transitions from Join State
+
+ The (S,G) downstream state machine on interface I remains in
+ Join state, and the Expiry Timer (ET) is restarted, set to
+ maximum of its current value and the HoldTime from the
+ triggering Join/Prune message.
+
+ Conclusion: Do not change the ET if the current value is
+ higher than the received join holdtime.
+ */
+ return;
+ }
+ }
+ THREAD_OFF(ch->t_ifjoin_expiry_timer);
+ break;
+ case PIM_IFJOIN_PRUNE_PENDING:
+ zassert(!ch->t_ifjoin_expiry_timer);
+ zassert(ch->t_ifjoin_prune_pending_timer);
+ THREAD_OFF(ch->t_ifjoin_prune_pending_timer);
+ pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_JOIN);
+ break;
+ }
+
+ zassert(!IFCHANNEL_NOINFO(ch));
+
+ if (holdtime != 0xFFFF) {
+ THREAD_TIMER_ON(master, ch->t_ifjoin_expiry_timer,
+ on_ifjoin_expiry_timer,
+ ch, holdtime);
+ }
+}
+
+void pim_ifchannel_prune(struct interface *ifp,
+ struct in_addr upstream,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ uint8_t source_flags,
+ uint16_t holdtime)
+{
+ struct pim_ifchannel *ch;
+ int jp_override_interval_msec;
+
+ if (nonlocal_upstream(0 /* prune */, ifp, upstream,
+ source_addr, group_addr, source_flags, holdtime)) {
+ return;
+ }
+
+ ch = pim_ifchannel_add(ifp, source_addr, group_addr);
+ if (!ch)
+ return;
+
+ switch (ch->ifjoin_state) {
+ case PIM_IFJOIN_NOINFO:
+ case PIM_IFJOIN_PRUNE_PENDING:
+ /* nothing to do */
+ break;
+ case PIM_IFJOIN_JOIN:
+ {
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ifp->info;
+
+ zassert(ch->t_ifjoin_expiry_timer);
+ zassert(!ch->t_ifjoin_prune_pending_timer);
+
+ THREAD_OFF(ch->t_ifjoin_expiry_timer);
+
+ pim_ifchannel_ifjoin_switch(__PRETTY_FUNCTION__, ch, PIM_IFJOIN_PRUNE_PENDING);
+
+ if (listcount(pim_ifp->pim_neighbor_list) > 1) {
+ jp_override_interval_msec = pim_if_jp_override_interval_msec(ifp);
+ }
+ else {
+ jp_override_interval_msec = 0; /* schedule to expire immediately */
+ /* If we called ifjoin_prune() directly instead, care should
+ be taken not to use "ch" afterwards since it would be
+ deleted. */
+ }
+
+ THREAD_TIMER_MSEC_ON(master, ch->t_ifjoin_prune_pending_timer,
+ on_ifjoin_prune_pending_timer,
+ ch, jp_override_interval_msec);
+
+ zassert(!ch->t_ifjoin_expiry_timer);
+ zassert(ch->t_ifjoin_prune_pending_timer);
+ }
+ break;
+ }
+
+}
+
+void pim_ifchannel_local_membership_add(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_ifchannel *ch;
+ struct pim_interface *pim_ifp;
+
+ /* PIM enabled on interface? */
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return;
+ if (!PIM_IF_TEST_PIM(pim_ifp->options))
+ return;
+
+ ch = pim_ifchannel_add(ifp, source_addr, group_addr);
+ if (!ch) {
+ return;
+ }
+
+ ifmembership_set(ch, PIM_IFMEMBERSHIP_INCLUDE);
+
+ zassert(!IFCHANNEL_NOINFO(ch));
+}
+
+void pim_ifchannel_local_membership_del(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_ifchannel *ch;
+ struct pim_interface *pim_ifp;
+
+ /* PIM enabled on interface? */
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ return;
+ if (!PIM_IF_TEST_PIM(pim_ifp->options))
+ return;
+
+ ch = pim_ifchannel_find(ifp, source_addr, group_addr);
+ if (!ch)
+ return;
+
+ ifmembership_set(ch, PIM_IFMEMBERSHIP_NOINFO);
+
+ delete_on_noinfo(ch);
+}
+
+void pim_ifchannel_update_could_assert(struct pim_ifchannel *ch)
+{
+ int old_couldassert = PIM_FORCE_BOOLEAN(PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags));
+ int new_couldassert = PIM_FORCE_BOOLEAN(pim_macro_ch_could_assert_eval(ch));
+
+ if (new_couldassert == old_couldassert)
+ return;
+
+ {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_info("%s: CouldAssert(%s,%s,%s) changed from %d to %d",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name,
+ old_couldassert, new_couldassert);
+ }
+
+ if (new_couldassert) {
+ /* CouldAssert(S,G,I) switched from FALSE to TRUE */
+ PIM_IF_FLAG_SET_COULD_ASSERT(ch->flags);
+ }
+ else {
+ /* CouldAssert(S,G,I) switched from TRUE to FALSE */
+ PIM_IF_FLAG_UNSET_COULD_ASSERT(ch->flags);
+
+ if (ch->ifassert_state == PIM_IFASSERT_I_AM_WINNER) {
+ assert_action_a4(ch);
+ }
+ }
+
+ pim_ifchannel_update_my_assert_metric(ch);
+}
+
+/*
+ my_assert_metric may be affected by:
+
+ CouldAssert(S,G)
+ pim_ifp->primary_address
+ rpf->source_nexthop.mrib_metric_preference;
+ rpf->source_nexthop.mrib_route_metric;
+ */
+void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel *ch)
+{
+ struct pim_assert_metric my_metric_new = pim_macro_ch_my_assert_metric_eval(ch);
+
+ if (pim_assert_metric_match(&my_metric_new, &ch->ifassert_my_metric))
+ return;
+
+ {
+ char src_str[100];
+ char grp_str[100];
+ char old_addr_str[100];
+ char new_addr_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<old_addr?>", ch->ifassert_my_metric.ip_address, old_addr_str, sizeof(old_addr_str));
+ pim_inet4_dump("<new_addr?>", my_metric_new.ip_address, new_addr_str, sizeof(new_addr_str));
+ zlog_info("%s: my_assert_metric(%s,%s,%s) changed from %u,%u,%u,%s to %u,%u,%u,%s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name,
+ ch->ifassert_my_metric.rpt_bit_flag,
+ ch->ifassert_my_metric.metric_preference,
+ ch->ifassert_my_metric.route_metric,
+ old_addr_str,
+ my_metric_new.rpt_bit_flag,
+ my_metric_new.metric_preference,
+ my_metric_new.route_metric,
+ new_addr_str);
+ }
+
+ ch->ifassert_my_metric = my_metric_new;
+
+ if (pim_assert_metric_better(&ch->ifassert_my_metric,
+ &ch->ifassert_winner_metric)) {
+ assert_action_a5(ch);
+ }
+}
+
+void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel *ch)
+{
+ int old_atd = PIM_FORCE_BOOLEAN(PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch->flags));
+ int new_atd = PIM_FORCE_BOOLEAN(pim_macro_assert_tracking_desired_eval(ch));
+
+ if (new_atd == old_atd)
+ return;
+
+ {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_info("%s: AssertTrackingDesired(%s,%s,%s) changed from %d to %d",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name,
+ old_atd, new_atd);
+ }
+
+ if (new_atd) {
+ /* AssertTrackingDesired(S,G,I) switched from FALSE to TRUE */
+ PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(ch->flags);
+ }
+ else {
+ /* AssertTrackingDesired(S,G,I) switched from TRUE to FALSE */
+ PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(ch->flags);
+
+ if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
+ assert_action_a5(ch);
+ }
+ }
+}
diff --git a/pimd/pim_ifchannel.h b/pimd/pim_ifchannel.h
new file mode 100644
index 00000000..e6f1c294
--- /dev/null
+++ b/pimd/pim_ifchannel.h
@@ -0,0 +1,145 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_IFCHANNEL_H
+#define PIM_IFCHANNEL_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+#include "pim_upstream.h"
+
+enum pim_ifmembership {
+ PIM_IFMEMBERSHIP_NOINFO,
+ PIM_IFMEMBERSHIP_INCLUDE
+};
+
+enum pim_ifjoin_state {
+ PIM_IFJOIN_NOINFO,
+ PIM_IFJOIN_JOIN,
+ PIM_IFJOIN_PRUNE_PENDING
+};
+
+enum pim_ifassert_state {
+ PIM_IFASSERT_NOINFO,
+ PIM_IFASSERT_I_AM_WINNER,
+ PIM_IFASSERT_I_AM_LOSER
+};
+
+struct pim_assert_metric {
+ uint32_t rpt_bit_flag;
+ uint32_t metric_preference;
+ uint32_t route_metric;
+ struct in_addr ip_address; /* neighbor router that sourced the Assert message */
+};
+
+/*
+ Flag to detect change in CouldAssert(S,G,I)
+*/
+#define PIM_IF_FLAG_MASK_COULD_ASSERT (1 << 0)
+#define PIM_IF_FLAG_TEST_COULD_ASSERT(flags) ((flags) & PIM_IF_FLAG_MASK_COULD_ASSERT)
+#define PIM_IF_FLAG_SET_COULD_ASSERT(flags) ((flags) |= PIM_IF_FLAG_MASK_COULD_ASSERT)
+#define PIM_IF_FLAG_UNSET_COULD_ASSERT(flags) ((flags) &= ~PIM_IF_FLAG_MASK_COULD_ASSERT)
+/*
+ Flag to detect change in AssertTrackingDesired(S,G,I)
+*/
+#define PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED (1 << 1)
+#define PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(flags) ((flags) & PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
+#define PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(flags) ((flags) |= PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
+#define PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(flags) ((flags) &= ~PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
+
+/*
+ Per-interface (S,G) state
+*/
+struct pim_ifchannel {
+ struct in_addr source_addr; /* (S,G) source key */
+ struct in_addr group_addr; /* (S,G) group key */
+ struct interface *interface; /* backpointer to interface */
+ uint32_t flags;
+
+ /* IGMPv3 determined interface has local members for (S,G) ? */
+ enum pim_ifmembership local_ifmembership;
+
+ /* Per-interface (S,G) Join/Prune State (Section 4.1.4 of RFC4601) */
+ enum pim_ifjoin_state ifjoin_state;
+ struct thread *t_ifjoin_expiry_timer;
+ struct thread *t_ifjoin_prune_pending_timer;
+ int64_t ifjoin_creation; /* Record uptime of ifjoin state */
+
+ /* Per-interface (S,G) Assert State (Section 4.6.1 of RFC4601) */
+ enum pim_ifassert_state ifassert_state;
+ struct thread *t_ifassert_timer;
+ struct in_addr ifassert_winner;
+ struct pim_assert_metric ifassert_winner_metric;
+ int64_t ifassert_creation; /* Record uptime of ifassert state */
+ struct pim_assert_metric ifassert_my_metric;
+
+ /* Upstream (S,G) state */
+ struct pim_upstream *upstream;
+};
+
+void pim_ifchannel_free(struct pim_ifchannel *ch);
+void pim_ifchannel_delete(struct pim_ifchannel *ch);
+void pim_ifchannel_membership_clear(struct interface *ifp);
+void pim_ifchannel_delete_on_noinfo(struct interface *ifp);
+struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr);
+struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr);
+void pim_ifchannel_join_add(struct interface *ifp,
+ struct in_addr neigh_addr,
+ struct in_addr upstream,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ uint8_t source_flags,
+ uint16_t holdtime);
+void pim_ifchannel_prune(struct interface *ifp,
+ struct in_addr upstream,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ uint8_t source_flags,
+ uint16_t holdtime);
+void pim_ifchannel_local_membership_add(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr);
+void pim_ifchannel_local_membership_del(struct interface *ifp,
+ struct in_addr source_addr,
+ struct in_addr group_addr);
+
+void pim_ifchannel_ifjoin_switch(const char *caller,
+ struct pim_ifchannel *ch,
+ enum pim_ifjoin_state new_state);
+const char *pim_ifchannel_ifjoin_name(enum pim_ifjoin_state ifjoin_state);
+const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state);
+
+int pim_ifchannel_isin_oiflist(struct pim_ifchannel *ch);
+
+void reset_ifassert_state(struct pim_ifchannel *ch);
+
+void pim_ifchannel_update_could_assert(struct pim_ifchannel *ch);
+void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel *ch);
+void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel *ch);
+
+#endif /* PIM_IFCHANNEL_H */
diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c
new file mode 100644
index 00000000..a0a4aa81
--- /dev/null
+++ b/pimd/pim_igmp.c
@@ -0,0 +1,1413 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_igmp.h"
+#include "pim_igmpv3.h"
+#include "pim_iface.h"
+#include "pim_sock.h"
+#include "pim_mroute.h"
+#include "pim_str.h"
+#include "pim_util.h"
+#include "pim_time.h"
+#include "pim_zebra.h"
+
+#define IGMP_GRP_REC_TYPE_MODE_IS_INCLUDE (1)
+#define IGMP_GRP_REC_TYPE_MODE_IS_EXCLUDE (2)
+#define IGMP_GRP_REC_TYPE_CHANGE_TO_INCLUDE_MODE (3)
+#define IGMP_GRP_REC_TYPE_CHANGE_TO_EXCLUDE_MODE (4)
+#define IGMP_GRP_REC_TYPE_ALLOW_NEW_SOURCES (5)
+#define IGMP_GRP_REC_TYPE_BLOCK_OLD_SOURCES (6)
+
+static void group_timer_off(struct igmp_group *group);
+
+static struct igmp_group *find_group_by_addr(struct igmp_sock *igmp,
+ struct in_addr group_addr);
+
+static int igmp_sock_open(struct in_addr ifaddr, int ifindex, uint32_t pim_options)
+{
+ int fd;
+ int join = 0;
+ struct in_addr group;
+
+ fd = pim_socket_mcast(IPPROTO_IGMP, ifaddr, 1 /* loop=true */);
+ if (fd < 0)
+ return -1;
+
+ if (PIM_IF_TEST_IGMP_LISTEN_ALLROUTERS(pim_options)) {
+ if (inet_aton(PIM_ALL_ROUTERS, &group)) {
+ if (!pim_socket_join(fd, group, ifaddr, ifindex))
+ ++join;
+ }
+ else {
+ zlog_warn("%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr),
+ PIM_ALL_ROUTERS, errno, safe_strerror(errno));
+ }
+ }
+
+ /*
+ IGMP routers periodically send IGMP general queries to AllSystems=224.0.0.1
+ IGMP routers must receive general queries for querier election.
+ */
+ if (inet_aton(PIM_ALL_SYSTEMS, &group)) {
+ if (!pim_socket_join(fd, group, ifaddr, ifindex))
+ ++join;
+ }
+ else {
+ zlog_warn("%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr),
+ PIM_ALL_SYSTEMS, errno, safe_strerror(errno));
+ }
+
+ if (inet_aton(PIM_ALL_IGMP_ROUTERS, &group)) {
+ if (!pim_socket_join(fd, group, ifaddr, ifindex)) {
+ ++join;
+ }
+ }
+ else {
+ zlog_warn("%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr),
+ PIM_ALL_IGMP_ROUTERS, errno, safe_strerror(errno));
+ }
+
+ if (!join) {
+ zlog_err("IGMP socket fd=%d could not join any group on interface address %s",
+ fd, inet_ntoa(ifaddr));
+ close(fd);
+ fd = -1;
+ }
+
+ return fd;
+}
+
+#undef IGMP_SOCK_DUMP
+
+#ifdef IGMP_SOCK_DUMP
+static void igmp_sock_dump(array_t *igmp_sock_array)
+{
+ int size = array_size(igmp_sock_array);
+ for (int i = 0; i < size; ++i) {
+
+ struct igmp_sock *igmp = array_get(igmp_sock_array, i);
+
+ zlog_debug("%s %s: [%d/%d] igmp_addr=%s fd=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ i, size,
+ inet_ntoa(igmp->ifaddr),
+ igmp->fd);
+ }
+}
+#endif
+
+struct igmp_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
+ struct in_addr ifaddr)
+{
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+#ifdef IGMP_SOCK_DUMP
+ igmp_sock_dump(igmp_sock_list);
+#endif
+
+ for (ALL_LIST_ELEMENTS_RO(igmp_sock_list, sock_node, igmp))
+ if (ifaddr.s_addr == igmp->ifaddr.s_addr)
+ return igmp;
+
+ return 0;
+}
+
+struct igmp_sock *igmp_sock_lookup_by_fd(struct list *igmp_sock_list,
+ int fd)
+{
+ struct listnode *sock_node;
+ struct igmp_sock *igmp;
+
+ for (ALL_LIST_ELEMENTS_RO(igmp_sock_list, sock_node, igmp))
+ if (fd == igmp->fd)
+ return igmp;
+
+ return 0;
+}
+
+static int pim_igmp_other_querier_expire(struct thread *t)
+{
+ struct igmp_sock *igmp;
+
+ zassert(t);
+ igmp = THREAD_ARG(t);
+ zassert(igmp);
+
+ zassert(igmp->t_other_querier_timer);
+ zassert(!igmp->t_igmp_query_timer);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("%s: Querier %s resuming",
+ __PRETTY_FUNCTION__,
+ ifaddr_str);
+ }
+
+ igmp->t_other_querier_timer = 0;
+
+ /*
+ We are the current querier, then
+ re-start sending general queries.
+ */
+ pim_igmp_general_query_on(igmp);
+
+ return 0;
+}
+
+void pim_igmp_other_querier_timer_on(struct igmp_sock *igmp)
+{
+ long other_querier_present_interval_msec;
+ struct pim_interface *pim_ifp;
+
+ zassert(igmp);
+ zassert(igmp->interface);
+ zassert(igmp->interface->info);
+
+ pim_ifp = igmp->interface->info;
+
+ if (igmp->t_other_querier_timer) {
+ /*
+ There is other querier present already,
+ then reset the other-querier-present timer.
+ */
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("Querier %s resetting TIMER event for Other-Querier-Present",
+ ifaddr_str);
+ }
+
+ THREAD_OFF(igmp->t_other_querier_timer);
+ zassert(!igmp->t_other_querier_timer);
+ }
+ else {
+ /*
+ We are the current querier, then stop sending general queries:
+ igmp->t_igmp_query_timer = 0;
+ */
+ pim_igmp_general_query_off(igmp);
+ }
+
+ /*
+ Since this socket is starting the other-querier-present timer,
+ there should not be periodic query timer for this socket.
+ */
+ zassert(!igmp->t_igmp_query_timer);
+
+ /*
+ RFC 3376: 8.5. Other Querier Present Interval
+
+ The Other Querier Present Interval is the length of time that must
+ pass before a multicast router decides that there is no longer
+ another multicast router which should be the querier. This value
+ MUST be ((the Robustness Variable) times (the Query Interval)) plus
+ (one half of one Query Response Interval).
+
+ other_querier_present_interval_msec = \
+ igmp->querier_robustness_variable * \
+ 1000 * igmp->querier_query_interval + \
+ 100 * (pim_ifp->query_max_response_time_dsec >> 1);
+ */
+ other_querier_present_interval_msec =
+ PIM_IGMP_OQPI_MSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("Querier %s scheduling %ld.%03ld sec TIMER event for Other-Querier-Present",
+ ifaddr_str,
+ other_querier_present_interval_msec / 1000,
+ other_querier_present_interval_msec % 1000);
+ }
+
+ THREAD_TIMER_MSEC_ON(master, igmp->t_other_querier_timer,
+ pim_igmp_other_querier_expire,
+ igmp, other_querier_present_interval_msec);
+}
+
+void pim_igmp_other_querier_timer_off(struct igmp_sock *igmp)
+{
+ zassert(igmp);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ if (igmp->t_other_querier_timer) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("IGMP querier %s fd=%d cancelling other-querier-present TIMER event on %s",
+ ifaddr_str, igmp->fd, igmp->interface->name);
+ }
+ }
+ THREAD_OFF(igmp->t_other_querier_timer);
+ zassert(!igmp->t_other_querier_timer);
+}
+
+static int recv_igmp_query(struct igmp_sock *igmp, int query_version,
+ int max_resp_code,
+ struct in_addr from, const char *from_str,
+ char *igmp_msg, int igmp_msg_len)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ uint8_t resv_s_qrv;
+ uint8_t s_flag;
+ uint8_t qrv;
+ struct in_addr group_addr;
+ uint16_t recv_checksum;
+ uint16_t checksum;
+ int i;
+
+ group_addr = *(struct in_addr *)(igmp_msg + 4);
+
+ ifp = igmp->interface;
+ pim_ifp = ifp->info;
+
+ recv_checksum = *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET);
+
+ /* for computing checksum */
+ *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = 0;
+
+ checksum = pim_inet_checksum(igmp_msg, igmp_msg_len);
+ if (checksum != recv_checksum) {
+ zlog_warn("Recv IGMP query v%d from %s on %s: checksum mismatch: received=%x computed=%x",
+ query_version, from_str, ifp->name, recv_checksum, checksum);
+ return -1;
+ }
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+ zlog_debug("Recv IGMP query v%d from %s on %s: size=%d checksum=%x group=%s",
+ query_version, from_str, ifp->name,
+ igmp_msg_len, checksum, group_str);
+ }
+
+ /*
+ RFC 3376: 6.6.2. Querier Election
+
+ When a router receives a query with a lower IP address, it sets
+ the Other-Querier-Present timer to Other Querier Present Interval
+ and ceases to send queries on the network if it was the previously
+ elected querier.
+ */
+ if (ntohl(from.s_addr) < ntohl(igmp->ifaddr.s_addr)) {
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("%s: local address %s (%u) lost querier election to %s (%u)",
+ ifp->name,
+ ifaddr_str, ntohl(igmp->ifaddr.s_addr),
+ from_str, ntohl(from.s_addr));
+ }
+
+ pim_igmp_other_querier_timer_on(igmp);
+ }
+
+ /*
+ RFC 3376: 4.1.6. QRV (Querier's Robustness Variable)
+
+ Routers adopt the QRV value from the most recently received Query
+ as their own [Robustness Variable] value, unless that most
+ recently received QRV was zero, in which case the receivers use
+ the default [Robustness Variable] value specified in section 8.1
+ or a statically configured value.
+ */
+ resv_s_qrv = igmp_msg[8];
+ qrv = 7 & resv_s_qrv;
+ igmp->querier_robustness_variable = qrv ? qrv : pim_ifp->igmp_default_robustness_variable;
+
+ /*
+ RFC 3376: 4.1.7. QQIC (Querier's Query Interval Code)
+
+ Multicast routers that are not the current querier adopt the QQI
+ value from the most recently received Query as their own [Query
+ Interval] value, unless that most recently received QQI was zero,
+ in which case the receiving routers use the default.
+ */
+ if (igmp->t_other_querier_timer) {
+ /* other querier present */
+ uint8_t qqic;
+ uint16_t qqi;
+ qqic = igmp_msg[9];
+ qqi = igmp_msg_decode8to16(qqic);
+ igmp->querier_query_interval = qqi ? qqi : pim_ifp->igmp_default_query_interval;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("Querier %s new query interval is %s QQI=%u sec (recv QQIC=%02x from %s)",
+ ifaddr_str,
+ qqi ? "recv-non-default" : "default",
+ igmp->querier_query_interval,
+ qqic,
+ from_str);
+ }
+ }
+
+ /*
+ RFC 3376: 6.6.1. Timer Updates
+
+ When a router sends or receives a query with a clear Suppress
+ Router-Side Processing flag, it must update its timers to reflect
+ the correct timeout values for the group or sources being queried.
+
+ General queries don't trigger timer update.
+ */
+ s_flag = (1 << 3) & resv_s_qrv;
+ if (!s_flag) {
+ /* s_flag is clear */
+
+ if (PIM_INADDR_IS_ANY(group_addr)) {
+ /* this is a general query */
+
+ /* log that general query should have the s_flag set */
+ zlog_warn("General IGMP query v%d from %s on %s: Suppress Router-Side Processing flag is clear",
+ query_version, from_str, ifp->name);
+ }
+ else {
+ struct igmp_group *group;
+
+ /* this is a non-general query: perform timer updates */
+
+ group = find_group_by_addr(igmp, group_addr);
+ if (group) {
+ int recv_num_sources = ntohs(*(uint16_t *)(igmp_msg + IGMP_V3_NUMSOURCES_OFFSET));
+
+ /*
+ RFC 3376: 6.6.1. Timer Updates
+ Query Q(G,A): Source Timer for sources in A are lowered to LMQT
+ Query Q(G): Group Timer is lowered to LMQT
+ */
+ if (recv_num_sources < 1) {
+ /* Query Q(G): Group Timer is lowered to LMQT */
+
+ igmp_group_timer_lower_to_lmqt(group);
+ }
+ else {
+ /* Query Q(G,A): Source Timer for sources in A are lowered to LMQT */
+
+ /* Scan sources in query and lower their timers to LMQT */
+ struct in_addr *sources = (struct in_addr *)(igmp_msg + IGMP_V3_SOURCES_OFFSET);
+ for (i = 0; i < recv_num_sources; ++i) {
+ struct in_addr src_addr = sources[i];
+ struct igmp_source *src = igmp_find_source_by_addr(group, src_addr);
+ if (src) {
+ igmp_source_timer_lower_to_lmqt(src);
+ }
+ }
+ }
+
+ }
+ else {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+ zlog_warn("IGMP query v%d from %s on %s: could not find group %s for timer update",
+ query_version, from_str, ifp->name, group_str);
+ }
+ }
+ } /* s_flag is clear: timer updates */
+
+ return 0;
+}
+
+static int igmp_v3_report(struct igmp_sock *igmp,
+ struct in_addr from, const char *from_str,
+ char *igmp_msg, int igmp_msg_len)
+{
+ uint16_t recv_checksum;
+ uint16_t checksum;
+ int num_groups;
+ uint8_t *group_record;
+ uint8_t *report_pastend = (uint8_t *) igmp_msg + igmp_msg_len;
+ struct interface *ifp = igmp->interface;
+ int i;
+
+ if (igmp_msg_len < IGMP_V3_MSG_MIN_SIZE) {
+ zlog_warn("Recv IGMP report v3 from %s on %s: size=%d shorter than minimum=%d",
+ from_str, ifp->name, igmp_msg_len, IGMP_V3_MSG_MIN_SIZE);
+ return -1;
+ }
+
+ recv_checksum = *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET);
+
+ /* for computing checksum */
+ *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = 0;
+
+ checksum = pim_inet_checksum(igmp_msg, igmp_msg_len);
+ if (checksum != recv_checksum) {
+ zlog_warn("Recv IGMP report v3 from %s on %s: checksum mismatch: received=%x computed=%x",
+ from_str, ifp->name, recv_checksum, checksum);
+ return -1;
+ }
+
+ num_groups = ntohs(*(uint16_t *) (igmp_msg + IGMP_V3_REPORT_NUMGROUPS_OFFSET));
+ if (num_groups < 1) {
+ zlog_warn("Recv IGMP report v3 from %s on %s: missing group records",
+ from_str, ifp->name);
+ return -1;
+ }
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ zlog_debug("Recv IGMP report v3 from %s on %s: size=%d checksum=%x groups=%d",
+ from_str, ifp->name, igmp_msg_len, checksum, num_groups);
+ }
+
+ group_record = (uint8_t *) igmp_msg + IGMP_V3_REPORT_GROUPPRECORD_OFFSET;
+
+ /* Scan groups */
+ for (i = 0; i < num_groups; ++i) {
+ struct in_addr rec_group;
+ uint8_t *sources;
+ uint8_t *src;
+ int rec_type;
+ int rec_auxdatalen;
+ int rec_num_sources;
+ int j;
+
+ if ((group_record + IGMP_V3_GROUP_RECORD_MIN_SIZE) > report_pastend) {
+ zlog_warn("Recv IGMP report v3 from %s on %s: group record beyond report end",
+ from_str, ifp->name);
+ return -1;
+ }
+
+ rec_type = group_record[IGMP_V3_GROUP_RECORD_TYPE_OFFSET];
+ rec_auxdatalen = group_record[IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET];
+ rec_num_sources = ntohs(* (uint16_t *) (group_record + IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET));
+
+ rec_group = *(struct in_addr *)(group_record + IGMP_V3_GROUP_RECORD_GROUP_OFFSET);
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ zlog_debug("Recv IGMP report v3 from %s on %s: record=%d type=%d auxdatalen=%d sources=%d group=%s",
+ from_str, ifp->name, i, rec_type, rec_auxdatalen, rec_num_sources, inet_ntoa(rec_group));
+ }
+
+ /* Scan sources */
+
+ sources = group_record + IGMP_V3_GROUP_RECORD_SOURCE_OFFSET;
+
+ for (j = 0, src = sources; j < rec_num_sources; ++j, src += 4) {
+
+ if ((src + 4) > report_pastend) {
+ zlog_warn("Recv IGMP report v3 from %s on %s: group source beyond report end",
+ from_str, ifp->name);
+ return -1;
+ }
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ char src_str[200];
+
+ if (!inet_ntop(AF_INET, src, src_str , sizeof(src_str)))
+ sprintf(src_str, "<source?>");
+
+ zlog_debug("Recv IGMP report v3 from %s on %s: record=%d group=%s source=%s",
+ from_str, ifp->name, i, inet_ntoa(rec_group), src_str);
+ }
+ } /* for (sources) */
+
+ switch (rec_type) {
+ case IGMP_GRP_REC_TYPE_MODE_IS_INCLUDE:
+ igmpv3_report_isin(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
+ break;
+ case IGMP_GRP_REC_TYPE_MODE_IS_EXCLUDE:
+ igmpv3_report_isex(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
+ break;
+ case IGMP_GRP_REC_TYPE_CHANGE_TO_INCLUDE_MODE:
+ igmpv3_report_toin(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
+ break;
+ case IGMP_GRP_REC_TYPE_CHANGE_TO_EXCLUDE_MODE:
+ igmpv3_report_toex(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
+ break;
+ case IGMP_GRP_REC_TYPE_ALLOW_NEW_SOURCES:
+ igmpv3_report_allow(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
+ break;
+ case IGMP_GRP_REC_TYPE_BLOCK_OLD_SOURCES:
+ igmpv3_report_block(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
+ break;
+ default:
+ zlog_warn("Recv IGMP report v3 from %s on %s: unknown record type: type=%d",
+ from_str, ifp->name, rec_type);
+ }
+
+ group_record += 8 + (rec_num_sources << 2) + (rec_auxdatalen << 2);
+
+ } /* for (group records) */
+
+ return 0;
+}
+
+static void on_trace(const char *label,
+ struct interface *ifp, struct in_addr from)
+{
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char from_str[100];
+ pim_inet4_dump("<from?>", from, from_str, sizeof(from_str));
+ zlog_debug("%s: from %s on %s",
+ label, from_str, ifp->name);
+ }
+}
+
+static int igmp_v2_report(struct igmp_sock *igmp,
+ struct in_addr from, const char *from_str,
+ char *igmp_msg, int igmp_msg_len)
+{
+ struct interface *ifp = igmp->interface;
+ struct igmp_group *group;
+ struct in_addr group_addr;
+
+ on_trace(__PRETTY_FUNCTION__, igmp->interface, from);
+
+ if (igmp_msg_len != IGMP_V12_MSG_SIZE) {
+ zlog_warn("Recv IGMP report v2 from %s on %s: size=%d other than correct=%d",
+ from_str, ifp->name, igmp_msg_len, IGMP_V12_MSG_SIZE);
+ return -1;
+ }
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_warn("%s %s: FIXME WRITEME",
+ __FILE__, __PRETTY_FUNCTION__);
+ }
+
+ group_addr = *(struct in_addr *)(igmp_msg + 4);
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return -1;
+ }
+
+ group->last_igmp_v2_report_dsec = pim_time_monotonic_dsec();
+
+ return 0;
+}
+
+static int igmp_v2_leave(struct igmp_sock *igmp,
+ struct in_addr from, const char *from_str,
+ char *igmp_msg, int igmp_msg_len)
+{
+ struct interface *ifp = igmp->interface;
+
+ on_trace(__PRETTY_FUNCTION__, igmp->interface, from);
+
+ if (igmp_msg_len != IGMP_V12_MSG_SIZE) {
+ zlog_warn("Recv IGMP leave v2 from %s on %s: size=%d other than correct=%d",
+ from_str, ifp->name, igmp_msg_len, IGMP_V12_MSG_SIZE);
+ return -1;
+ }
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_warn("%s %s: FIXME WRITEME",
+ __FILE__, __PRETTY_FUNCTION__);
+ }
+
+ return 0;
+}
+
+static int igmp_v1_report(struct igmp_sock *igmp,
+ struct in_addr from, const char *from_str,
+ char *igmp_msg, int igmp_msg_len)
+{
+ struct interface *ifp = igmp->interface;
+ struct igmp_group *group;
+ struct in_addr group_addr;
+
+ on_trace(__PRETTY_FUNCTION__, igmp->interface, from);
+
+ if (igmp_msg_len != IGMP_V12_MSG_SIZE) {
+ zlog_warn("Recv IGMP report v1 from %s on %s: size=%d other than correct=%d",
+ from_str, ifp->name, igmp_msg_len, IGMP_V12_MSG_SIZE);
+ return -1;
+ }
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_warn("%s %s: FIXME WRITEME",
+ __FILE__, __PRETTY_FUNCTION__);
+ }
+
+ group_addr = *(struct in_addr *)(igmp_msg + 4);
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return -1;
+ }
+
+ group->last_igmp_v1_report_dsec = pim_time_monotonic_dsec();
+
+ return 0;
+}
+
+int pim_igmp_packet(struct igmp_sock *igmp, char *buf, size_t len)
+{
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ char *igmp_msg;
+ int igmp_msg_len;
+ int msg_type;
+ char from_str[100];
+ char to_str[100];
+
+ if (len < sizeof(*ip_hdr)) {
+ zlog_warn("IGMP packet size=%d shorter than minimum=%d",
+ len, sizeof(*ip_hdr));
+ return -1;
+ }
+
+ ip_hdr = (struct ip *) buf;
+
+ pim_inet4_dump("<src?>", ip_hdr->ip_src, from_str , sizeof(from_str));
+ pim_inet4_dump("<dst?>", ip_hdr->ip_dst, to_str , sizeof(to_str));
+
+ ip_hlen = ip_hdr->ip_hl << 2; /* ip_hl gives length in 4-byte words */
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ zlog_debug("Recv IP packet from %s to %s on %s: size=%d ip_header_size=%d ip_proto=%d",
+ from_str, to_str, igmp->interface->name, len, ip_hlen, ip_hdr->ip_p);
+ }
+
+ if (ip_hdr->ip_p != PIM_IP_PROTO_IGMP) {
+ zlog_warn("IP packet protocol=%d is not IGMP=%d",
+ ip_hdr->ip_p, PIM_IP_PROTO_IGMP);
+ return -1;
+ }
+
+ if (ip_hlen < PIM_IP_HEADER_MIN_LEN) {
+ zlog_warn("IP packet header size=%d shorter than minimum=%d",
+ ip_hlen, PIM_IP_HEADER_MIN_LEN);
+ return -1;
+ }
+ if (ip_hlen > PIM_IP_HEADER_MAX_LEN) {
+ zlog_warn("IP packet header size=%d greater than maximum=%d",
+ ip_hlen, PIM_IP_HEADER_MAX_LEN);
+ return -1;
+ }
+
+ igmp_msg = buf + ip_hlen;
+ msg_type = *igmp_msg;
+ igmp_msg_len = len - ip_hlen;
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ zlog_debug("Recv IGMP packet from %s to %s on %s: ttl=%d msg_type=%d msg_size=%d",
+ from_str, to_str, igmp->interface->name, ip_hdr->ip_ttl, msg_type,
+ igmp_msg_len);
+ }
+
+ if (igmp_msg_len < PIM_IGMP_MIN_LEN) {
+ zlog_warn("IGMP message size=%d shorter than minimum=%d",
+ igmp_msg_len, PIM_IGMP_MIN_LEN);
+ return -1;
+ }
+
+ switch (msg_type) {
+ case PIM_IGMP_MEMBERSHIP_QUERY:
+ {
+ int max_resp_code = igmp_msg[1];
+ int query_version;
+
+ /*
+ RFC 3376: 7.1. Query Version Distinctions
+ IGMPv1 Query: length = 8 octets AND Max Resp Code field is zero
+ IGMPv2 Query: length = 8 octets AND Max Resp Code field is non-zero
+ IGMPv3 Query: length >= 12 octets
+ */
+
+ if (igmp_msg_len == 8) {
+ query_version = max_resp_code ? 2 : 1;
+ }
+ else if (igmp_msg_len >= 12) {
+ query_version = 3;
+ }
+ else {
+ zlog_warn("Unknown IGMP query version");
+ return -1;
+ }
+
+ return recv_igmp_query(igmp, query_version, max_resp_code,
+ ip_hdr->ip_src, from_str,
+ igmp_msg, igmp_msg_len);
+ }
+
+ case PIM_IGMP_V3_MEMBERSHIP_REPORT:
+ return igmp_v3_report(igmp, ip_hdr->ip_src, from_str,
+ igmp_msg, igmp_msg_len);
+
+ case PIM_IGMP_V2_MEMBERSHIP_REPORT:
+ return igmp_v2_report(igmp, ip_hdr->ip_src, from_str,
+ igmp_msg, igmp_msg_len);
+
+ case PIM_IGMP_V1_MEMBERSHIP_REPORT:
+ return igmp_v1_report(igmp, ip_hdr->ip_src, from_str,
+ igmp_msg, igmp_msg_len);
+
+ case PIM_IGMP_V2_LEAVE_GROUP:
+ return igmp_v2_leave(igmp, ip_hdr->ip_src, from_str,
+ igmp_msg, igmp_msg_len);
+ }
+
+ zlog_warn("Ignoring unsupported IGMP message type: %d", msg_type);
+
+ return -1;
+}
+
+static int pim_igmp_general_query(struct thread *t);
+
+void pim_igmp_general_query_on(struct igmp_sock *igmp)
+{
+ struct pim_interface *pim_ifp;
+ int startup_mode;
+ int query_interval;
+
+ zassert(igmp);
+ zassert(igmp->interface);
+
+ /*
+ Since this socket is starting as querier,
+ there should not exist a timer for other-querier-present.
+ */
+ zassert(!igmp->t_other_querier_timer);
+ pim_ifp = igmp->interface->info;
+ zassert(pim_ifp);
+
+ /*
+ RFC 3376: 8.6. Startup Query Interval
+
+ The Startup Query Interval is the interval between General Queries
+ sent by a Querier on startup. Default: 1/4 the Query Interval.
+ */
+ startup_mode = igmp->startup_query_count > 0;
+ if (startup_mode) {
+ --igmp->startup_query_count;
+
+ /* query_interval = pim_ifp->igmp_default_query_interval >> 2; */
+ query_interval = PIM_IGMP_SQI(pim_ifp->igmp_default_query_interval);
+ }
+ else {
+ query_interval = igmp->querier_query_interval;
+ }
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("Querier %s scheduling %d-second (%s) TIMER event for IGMP query on fd=%d",
+ ifaddr_str,
+ query_interval,
+ startup_mode ? "startup" : "non-startup",
+ igmp->fd);
+ }
+ igmp->t_igmp_query_timer = 0;
+ zassert(!igmp->t_igmp_query_timer);
+ THREAD_TIMER_ON(master, igmp->t_igmp_query_timer,
+ pim_igmp_general_query,
+ igmp, query_interval);
+}
+
+void pim_igmp_general_query_off(struct igmp_sock *igmp)
+{
+ zassert(igmp);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ if (igmp->t_igmp_query_timer) {
+ char ifaddr_str[100];
+ pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
+ zlog_debug("IGMP querier %s fd=%d cancelling query TIMER event on %s",
+ ifaddr_str, igmp->fd, igmp->interface->name);
+ }
+ }
+ THREAD_OFF(igmp->t_igmp_query_timer);
+ zassert(!igmp->t_igmp_query_timer);
+}
+
+/* Issue IGMP general query */
+static int pim_igmp_general_query(struct thread *t)
+{
+ char query_buf[PIM_IGMP_BUFSIZE_WRITE];
+ struct igmp_sock *igmp;
+ struct in_addr dst_addr;
+ struct in_addr group_addr;
+ struct pim_interface *pim_ifp;
+
+ zassert(t);
+
+ igmp = THREAD_ARG(t);
+
+ zassert(igmp);
+ zassert(igmp->interface);
+ zassert(igmp->interface->info);
+
+ pim_ifp = igmp->interface->info;
+
+ /*
+ RFC3376: 4.1.12. IP Destination Addresses for Queries
+
+ In IGMPv3, General Queries are sent with an IP destination address
+ of 224.0.0.1, the all-systems multicast address. Group-Specific
+ and Group-and-Source-Specific Queries are sent with an IP
+ destination address equal to the multicast address of interest.
+ */
+
+ dst_addr.s_addr = htonl(INADDR_ALLHOSTS_GROUP);
+ group_addr.s_addr = PIM_NET_INADDR_ANY;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char querier_str[100];
+ char dst_str[100];
+ pim_inet4_dump("<querier?>", igmp->ifaddr, querier_str,
+ sizeof(querier_str));
+ pim_inet4_dump("<dst?>", dst_addr, dst_str, sizeof(dst_str));
+ zlog_debug("Querier %s issuing IGMP general query to %s on %s",
+ querier_str, dst_str, igmp->interface->name);
+ }
+
+ pim_igmp_send_membership_query(0 /* igmp_group */,
+ igmp->fd,
+ igmp->interface->name,
+ query_buf,
+ sizeof(query_buf),
+ 0 /* num_sources */,
+ dst_addr,
+ group_addr,
+ pim_ifp->igmp_query_max_response_time_dsec,
+ 1 /* s_flag: always set for general queries */,
+ igmp->querier_robustness_variable,
+ igmp->querier_query_interval);
+
+ pim_igmp_general_query_on(igmp);
+
+ return 0;
+}
+
+static int pim_igmp_read(struct thread *t);
+
+static void igmp_read_on(struct igmp_sock *igmp)
+{
+ zassert(igmp);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_debug("Scheduling READ event on IGMP socket fd=%d",
+ igmp->fd);
+ }
+ igmp->t_igmp_read = 0;
+ zassert(!igmp->t_igmp_read);
+ THREAD_READ_ON(master, igmp->t_igmp_read, pim_igmp_read, igmp, igmp->fd);
+}
+
+static int pim_igmp_read(struct thread *t)
+{
+ struct igmp_sock *igmp;
+ int fd;
+ struct sockaddr_in from;
+ struct sockaddr_in to;
+ socklen_t fromlen = sizeof(from);
+ socklen_t tolen = sizeof(to);
+ char buf[PIM_IGMP_BUFSIZE_READ];
+ int len;
+ int ifindex = -1;
+ int result = -1; /* defaults to bad */
+
+ zassert(t);
+
+ igmp = THREAD_ARG(t);
+
+ zassert(igmp);
+
+ fd = THREAD_FD(t);
+
+ zassert(fd == igmp->fd);
+
+ len = pim_socket_recvfromto(fd, buf, sizeof(buf),
+ &from, &fromlen,
+ &to, &tolen,
+ &ifindex);
+ if (len < 0) {
+ zlog_warn("Failure receiving IP IGMP packet on fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ goto done;
+ }
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ char from_str[100];
+ char to_str[100];
+
+ if (!inet_ntop(AF_INET, &from.sin_addr, from_str, sizeof(from_str)))
+ sprintf(from_str, "<from?>");
+ if (!inet_ntop(AF_INET, &to.sin_addr, to_str, sizeof(to_str)))
+ sprintf(to_str, "<to?>");
+
+ zlog_debug("Recv IP IGMP pkt size=%d from %s to %s on fd=%d on ifindex=%d (sock_ifindex=%d)",
+ len, from_str, to_str, fd, ifindex, igmp->interface->ifindex);
+ }
+
+#ifdef PIM_CHECK_RECV_IFINDEX_SANITY
+ /* ifindex sanity check */
+ if (ifindex != (int) igmp->interface->ifindex) {
+ char from_str[100];
+ char to_str[100];
+ struct interface *ifp;
+
+ if (!inet_ntop(AF_INET, &from.sin_addr, from_str , sizeof(from_str)))
+ sprintf(from_str, "<from?>");
+ if (!inet_ntop(AF_INET, &to.sin_addr, to_str , sizeof(to_str)))
+ sprintf(to_str, "<to?>");
+
+ ifp = if_lookup_by_index(ifindex);
+ if (ifp) {
+ zassert(ifindex == (int) ifp->ifindex);
+ }
+
+#ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
+ zlog_warn("Interface mismatch: recv IGMP pkt from %s to %s on fd=%d: recv_ifindex=%d (%s) sock_ifindex=%d (%s)",
+ from_str, to_str, fd,
+ ifindex, ifp ? ifp->name : "<if-notfound>",
+ igmp->interface->ifindex, igmp->interface->name);
+#endif
+ goto done;
+ }
+#endif
+
+ if (pim_igmp_packet(igmp, buf, len)) {
+ goto done;
+ }
+
+ result = 0; /* good */
+
+ done:
+ igmp_read_on(igmp);
+
+ return result;
+}
+
+static void sock_close(struct igmp_sock *igmp)
+{
+ pim_igmp_other_querier_timer_off(igmp);
+ pim_igmp_general_query_off(igmp);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ if (igmp->t_igmp_read) {
+ zlog_debug("Cancelling READ event on IGMP socket %s fd=%d on interface %s",
+ inet_ntoa(igmp->ifaddr), igmp->fd,
+ igmp->interface->name);
+ }
+ }
+ THREAD_OFF(igmp->t_igmp_read);
+ zassert(!igmp->t_igmp_read);
+
+ if (close(igmp->fd)) {
+ zlog_err("Failure closing IGMP socket %s fd=%d on interface %s: errno=%d: %s",
+ inet_ntoa(igmp->ifaddr), igmp->fd, igmp->interface->name,
+ errno, safe_strerror(errno));
+ }
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_debug("Deleted IGMP socket %s fd=%d on interface %s",
+ inet_ntoa(igmp->ifaddr), igmp->fd, igmp->interface->name);
+ }
+}
+
+void igmp_startup_mode_on(struct igmp_sock *igmp)
+{
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = igmp->interface->info;
+
+ /*
+ RFC 3376: 8.7. Startup Query Count
+
+ The Startup Query Count is the number of Queries sent out on
+ startup, separated by the Startup Query Interval. Default: the
+ Robustness Variable.
+ */
+ igmp->startup_query_count = igmp->querier_robustness_variable;
+
+ /*
+ Since we're (re)starting, reset QQI to default Query Interval
+ */
+ igmp->querier_query_interval = pim_ifp->igmp_default_query_interval;
+}
+
+static void igmp_group_free(struct igmp_group *group)
+{
+ zassert(!group->t_group_query_retransmit_timer);
+ zassert(!group->t_group_timer);
+ zassert(group->group_source_list);
+ zassert(!listcount(group->group_source_list));
+
+ list_free(group->group_source_list);
+
+ XFREE(MTYPE_PIM_IGMP_GROUP, group);
+}
+
+static void igmp_group_delete(struct igmp_group *group)
+{
+ struct listnode *src_node;
+ struct listnode *src_nextnode;
+ struct igmp_source *src;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("Deleting IGMP group %s from socket %d interface %s",
+ group_str,
+ group->group_igmp_sock->fd,
+ group->group_igmp_sock->interface->name);
+ }
+
+ for (ALL_LIST_ELEMENTS(group->group_source_list, src_node, src_nextnode, src)) {
+ igmp_source_delete(src);
+ }
+
+ if (group->t_group_query_retransmit_timer) {
+ THREAD_OFF(group->t_group_query_retransmit_timer);
+ zassert(!group->t_group_query_retransmit_timer);
+ }
+
+ group_timer_off(group);
+ listnode_delete(group->group_igmp_sock->igmp_group_list, group);
+ igmp_group_free(group);
+}
+
+void igmp_group_delete_empty_include(struct igmp_group *group)
+{
+ zassert(!group->group_filtermode_isexcl);
+ zassert(!listcount(group->group_source_list));
+
+ igmp_group_delete(group);
+}
+
+void igmp_sock_free(struct igmp_sock *igmp)
+{
+ zassert(!igmp->t_igmp_read);
+ zassert(!igmp->t_igmp_query_timer);
+ zassert(!igmp->t_other_querier_timer);
+ zassert(igmp->igmp_group_list);
+ zassert(!listcount(igmp->igmp_group_list));
+
+ list_free(igmp->igmp_group_list);
+
+ XFREE(MTYPE_PIM_IGMP_SOCKET, igmp);
+}
+
+void igmp_sock_delete(struct igmp_sock *igmp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *grp_node;
+ struct listnode *grp_nextnode;
+ struct igmp_group *grp;
+
+ for (ALL_LIST_ELEMENTS(igmp->igmp_group_list, grp_node, grp_nextnode, grp)) {
+ igmp_group_delete(grp);
+ }
+
+ sock_close(igmp);
+
+ pim_ifp = igmp->interface->info;
+
+ listnode_delete(pim_ifp->igmp_socket_list, igmp);
+
+ igmp_sock_free(igmp);
+}
+
+static struct igmp_sock *igmp_sock_new(int fd,
+ struct in_addr ifaddr,
+ struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct igmp_sock *igmp;
+
+ pim_ifp = ifp->info;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_debug("Creating IGMP socket fd=%d for address %s on interface %s",
+ fd, inet_ntoa(ifaddr), ifp->name);
+ }
+
+ igmp = XMALLOC(MTYPE_PIM_IGMP_SOCKET, sizeof(*igmp));
+ if (!igmp) {
+ zlog_warn("%s %s: XMALLOC() failure",
+ __FILE__, __PRETTY_FUNCTION__);
+ return 0;
+ }
+
+ igmp->igmp_group_list = list_new();
+ if (!igmp->igmp_group_list) {
+ zlog_err("%s %s: failure: igmp_group_list = list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return 0;
+ }
+ igmp->igmp_group_list->del = (void (*)(void *)) igmp_group_free;
+
+ igmp->fd = fd;
+ igmp->interface = ifp;
+ igmp->ifaddr = ifaddr;
+ igmp->t_igmp_read = 0;
+ igmp->t_igmp_query_timer = 0;
+ igmp->t_other_querier_timer = 0; /* no other querier present */
+ igmp->querier_robustness_variable = pim_ifp->igmp_default_robustness_variable;
+ igmp->sock_creation = pim_time_monotonic_sec();
+
+ /*
+ igmp_startup_mode_on() will reset QQI:
+
+ igmp->querier_query_interval = pim_ifp->igmp_default_query_interval;
+ */
+ igmp_startup_mode_on(igmp);
+
+ igmp_read_on(igmp);
+ pim_igmp_general_query_on(igmp);
+
+ return igmp;
+}
+
+struct igmp_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
+ struct in_addr ifaddr,
+ struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct igmp_sock *igmp;
+ int fd;
+
+ pim_ifp = ifp->info;
+
+ fd = igmp_sock_open(ifaddr, ifp->ifindex, pim_ifp->options);
+ if (fd < 0) {
+ zlog_warn("Could not open IGMP socket for %s on %s",
+ inet_ntoa(ifaddr), ifp->name);
+ return 0;
+ }
+
+ igmp = igmp_sock_new(fd, ifaddr, ifp);
+ if (!igmp) {
+ zlog_err("%s %s: igmp_sock_new() failure",
+ __FILE__, __PRETTY_FUNCTION__);
+ close(fd);
+ return 0;
+ }
+
+ listnode_add(igmp_sock_list, igmp);
+
+#ifdef IGMP_SOCK_DUMP
+ igmp_sock_dump(igmp_sock_array);
+#endif
+
+ return igmp;
+}
+
+/*
+ RFC 3376: 6.5. Switching Router Filter-Modes
+
+ When a router's filter-mode for a group is EXCLUDE and the group
+ timer expires, the router filter-mode for the group transitions to
+ INCLUDE.
+
+ A router uses source records with running source timers as its state
+ for the switch to a filter-mode of INCLUDE. If there are any source
+ records with source timers greater than zero (i.e., requested to be
+ forwarded), a router switches to filter-mode of INCLUDE using those
+ source records. Source records whose timers are zero (from the
+ previous EXCLUDE mode) are deleted.
+ */
+static int igmp_group_timer(struct thread *t)
+{
+ struct igmp_group *group;
+
+ zassert(t);
+ group = THREAD_ARG(t);
+ zassert(group);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: Timer for group %s on interface %s",
+ __PRETTY_FUNCTION__,
+ group_str, group->group_igmp_sock->interface->name);
+ }
+
+ zassert(group->group_filtermode_isexcl);
+
+ group->t_group_timer = 0;
+ group->group_filtermode_isexcl = 0;
+
+ /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
+ igmp_anysource_forward_stop(group);
+
+ igmp_source_delete_expired(group->group_source_list);
+
+ zassert(!group->t_group_timer);
+ zassert(!group->group_filtermode_isexcl);
+
+ /*
+ RFC 3376: 6.2.2. Definition of Group Timers
+
+ If there are no more source records for the group, delete group
+ record.
+ */
+ if (listcount(group->group_source_list) < 1) {
+ igmp_group_delete_empty_include(group);
+ }
+
+ return 0;
+}
+
+static void group_timer_off(struct igmp_group *group)
+{
+ if (!group->t_group_timer)
+ return;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("Cancelling TIMER event for group %s on %s",
+ group_str, group->group_igmp_sock->interface->name);
+ }
+
+ THREAD_OFF(group->t_group_timer);
+ zassert(!group->t_group_timer);
+}
+
+void igmp_group_timer_on(struct igmp_group *group,
+ long interval_msec, const char *ifname)
+{
+ group_timer_off(group);
+
+ if (PIM_DEBUG_IGMP_EVENTS) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("Scheduling %ld.%03ld sec TIMER event for group %s on %s",
+ interval_msec / 1000,
+ interval_msec % 1000,
+ group_str, ifname);
+ }
+
+ /*
+ RFC 3376: 6.2.2. Definition of Group Timers
+
+ The group timer is only used when a group is in EXCLUDE mode and
+ it represents the time for the *filter-mode* of the group to
+ expire and switch to INCLUDE mode.
+ */
+ zassert(group->group_filtermode_isexcl);
+
+ THREAD_TIMER_MSEC_ON(master, group->t_group_timer,
+ igmp_group_timer,
+ group, interval_msec);
+}
+
+static struct igmp_group *find_group_by_addr(struct igmp_sock *igmp,
+ struct in_addr group_addr)
+{
+ struct igmp_group *group;
+ struct listnode *node;
+
+ for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, node, group))
+ if (group_addr.s_addr == group->group_addr.s_addr)
+ return group;
+
+ return 0;
+}
+
+struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp,
+ struct in_addr group_addr,
+ const char *ifname)
+{
+ struct igmp_group *group;
+
+ group = find_group_by_addr(igmp, group_addr);
+ if (group) {
+ return group;
+ }
+
+ /*
+ Non-existant group is created as INCLUDE {empty}:
+
+ RFC 3376 - 5.1. Action on Change of Interface State
+
+ If no interface state existed for that multicast address before
+ the change (i.e., the change consisted of creating a new
+ per-interface record), or if no state exists after the change
+ (i.e., the change consisted of deleting a per-interface record),
+ then the "non-existent" state is considered to have a filter mode
+ of INCLUDE and an empty source list.
+ */
+
+ group = XMALLOC(MTYPE_PIM_IGMP_GROUP, sizeof(*group));
+ if (!group) {
+ zlog_warn("%s %s: XMALLOC() failure",
+ __FILE__, __PRETTY_FUNCTION__);
+ return 0; /* error, not found, could not create */
+ }
+
+ group->group_source_list = list_new();
+ if (!group->group_source_list) {
+ zlog_warn("%s %s: list_new() failure",
+ __FILE__, __PRETTY_FUNCTION__);
+ XFREE(MTYPE_PIM_IGMP_GROUP, group); /* discard group */
+ return 0; /* error, not found, could not initialize */
+ }
+ group->group_source_list->del = (void (*)(void *)) igmp_source_free;
+
+ group->t_group_timer = 0;
+ group->t_group_query_retransmit_timer = 0;
+ group->group_specific_query_retransmit_count = 0;
+ group->group_addr = group_addr;
+ group->group_igmp_sock = igmp;
+ group->last_igmp_v1_report_dsec = -1;
+ group->last_igmp_v2_report_dsec = -1;
+ group->group_creation = pim_time_monotonic_sec();
+
+ /* initialize new group as INCLUDE {empty} */
+ group->group_filtermode_isexcl = 0; /* 0=INCLUDE, 1=EXCLUDE */
+
+ listnode_add(igmp->igmp_group_list, group);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("Creating new IGMP group %s on socket %d interface %s",
+ group_str, group->group_igmp_sock->fd, ifname);
+ }
+
+ /*
+ RFC 3376: 6.2.2. Definition of Group Timers
+
+ The group timer is only used when a group is in EXCLUDE mode and
+ it represents the time for the *filter-mode* of the group to
+ expire and switch to INCLUDE mode.
+ */
+ zassert(!group->group_filtermode_isexcl); /* INCLUDE mode */
+ zassert(!group->t_group_timer); /* group timer == 0 */
+
+ /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
+ igmp_anysource_forward_stop(group);
+
+ return group;
+}
diff --git a/pimd/pim_igmp.h b/pimd/pim_igmp.h
new file mode 100644
index 00000000..95e60bf2
--- /dev/null
+++ b/pimd/pim_igmp.h
@@ -0,0 +1,175 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_IGMP_H
+#define PIM_IGMP_H
+
+#include <netinet/in.h>
+
+#include <zebra.h>
+#include "vty.h"
+#include "linklist.h"
+
+/*
+ The following sizes are likely to support
+ any message sent within local MTU.
+*/
+#define PIM_IGMP_BUFSIZE_READ (20000)
+#define PIM_IGMP_BUFSIZE_WRITE (20000)
+
+#define PIM_IGMP_MEMBERSHIP_QUERY (0x11)
+#define PIM_IGMP_V1_MEMBERSHIP_REPORT (0x12)
+#define PIM_IGMP_V2_MEMBERSHIP_REPORT (0x16)
+#define PIM_IGMP_V2_LEAVE_GROUP (0x17)
+#define PIM_IGMP_V3_MEMBERSHIP_REPORT (0x22)
+
+#define IGMP_V3_REPORT_HEADER_SIZE (8)
+#define IGMP_V3_GROUP_RECORD_MIN_SIZE (8)
+#define IGMP_V3_MSG_MIN_SIZE (IGMP_V3_REPORT_HEADER_SIZE + \
+ IGMP_V3_GROUP_RECORD_MIN_SIZE)
+#define IGMP_V12_MSG_SIZE (8)
+
+#define IGMP_V3_GROUP_RECORD_TYPE_OFFSET (0)
+#define IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET (1)
+#define IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET (2)
+#define IGMP_V3_GROUP_RECORD_GROUP_OFFSET (4)
+#define IGMP_V3_GROUP_RECORD_SOURCE_OFFSET (8)
+
+/* RFC 3376: 8.1. Robustness Variable - Default: 2 */
+#define IGMP_DEFAULT_ROBUSTNESS_VARIABLE (2)
+
+/* RFC 3376: 8.2. Query Interval - Default: 125 seconds */
+#define IGMP_GENERAL_QUERY_INTERVAL (125)
+
+/* RFC 3376: 8.3. Query Response Interval - Default: 100 deciseconds */
+#define IGMP_QUERY_MAX_RESPONSE_TIME_DSEC (100)
+
+/* RFC 3376: 8.8. Last Member Query Interval - Default: 10 deciseconds */
+#define IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC (10)
+
+struct igmp_join {
+ struct in_addr group_addr;
+ struct in_addr source_addr;
+ int sock_fd;
+};
+
+struct igmp_sock {
+ int fd;
+ struct interface *interface;
+ struct in_addr ifaddr;
+ time_t sock_creation;
+
+ struct thread *t_igmp_read; /* read: IGMP sockets */
+ struct thread *t_igmp_query_timer; /* timer: issue IGMP general queries */
+ struct thread *t_other_querier_timer; /* timer: other querier present */
+
+ int querier_query_interval; /* QQI */
+ int querier_robustness_variable; /* QRV */
+ int startup_query_count;
+
+ struct list *igmp_group_list; /* list of struct igmp_group */
+};
+
+struct igmp_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
+ struct in_addr ifaddr);
+struct igmp_sock *igmp_sock_lookup_by_fd(struct list *igmp_sock_list,
+ int fd);
+struct igmp_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
+ struct in_addr ifaddr,
+ struct interface *ifp);
+void igmp_sock_delete(struct igmp_sock *igmp);
+void igmp_sock_free(struct igmp_sock *igmp);
+
+int pim_igmp_packet(struct igmp_sock *igmp, char *buf, size_t len);
+
+void pim_igmp_general_query_on(struct igmp_sock *igmp);
+void pim_igmp_general_query_off(struct igmp_sock *igmp);
+void pim_igmp_other_querier_timer_on(struct igmp_sock *igmp);
+void pim_igmp_other_querier_timer_off(struct igmp_sock *igmp);
+
+#define IGMP_SOURCE_MASK_FORWARDING (1 << 0)
+#define IGMP_SOURCE_MASK_DELETE (1 << 1)
+#define IGMP_SOURCE_MASK_SEND (1 << 2)
+#define IGMP_SOURCE_TEST_FORWARDING(flags) ((flags) & IGMP_SOURCE_MASK_FORWARDING)
+#define IGMP_SOURCE_TEST_DELETE(flags) ((flags) & IGMP_SOURCE_MASK_DELETE)
+#define IGMP_SOURCE_TEST_SEND(flags) ((flags) & IGMP_SOURCE_MASK_SEND)
+#define IGMP_SOURCE_DO_FORWARDING(flags) ((flags) |= IGMP_SOURCE_MASK_FORWARDING)
+#define IGMP_SOURCE_DO_DELETE(flags) ((flags) |= IGMP_SOURCE_MASK_DELETE)
+#define IGMP_SOURCE_DO_SEND(flags) ((flags) |= IGMP_SOURCE_MASK_SEND)
+#define IGMP_SOURCE_DONT_FORWARDING(flags) ((flags) &= ~IGMP_SOURCE_MASK_FORWARDING)
+#define IGMP_SOURCE_DONT_DELETE(flags) ((flags) &= ~IGMP_SOURCE_MASK_DELETE)
+#define IGMP_SOURCE_DONT_SEND(flags) ((flags) &= ~IGMP_SOURCE_MASK_SEND)
+
+struct igmp_source {
+ struct in_addr source_addr;
+ struct thread *t_source_timer;
+ struct igmp_group *source_group; /* back pointer */
+ time_t source_creation;
+ uint32_t source_flags;
+ struct channel_oil *source_channel_oil;
+
+ /*
+ RFC 3376: 6.6.3.2. Building and Sending Group and Source Specific Queries
+ */
+ int source_query_retransmit_count;
+};
+
+struct igmp_group {
+ /*
+ RFC 3376: 6.2.2. Definition of Group Timers
+
+ The group timer is only used when a group is in EXCLUDE mode and it
+ represents the time for the *filter-mode* of the group to expire and
+ switch to INCLUDE mode.
+ */
+ struct thread *t_group_timer;
+
+ /* Shared between group-specific and
+ group-and-source-specific retransmissions */
+ struct thread *t_group_query_retransmit_timer;
+
+ /* Counter exclusive for group-specific retransmissions
+ (not used by group-and-source-specific retransmissions,
+ since sources have their counters) */
+ int group_specific_query_retransmit_count;
+
+ struct in_addr group_addr;
+ int group_filtermode_isexcl; /* 0=INCLUDE, 1=EXCLUDE */
+ struct list *group_source_list; /* list of struct igmp_source */
+ time_t group_creation;
+ struct igmp_sock *group_igmp_sock; /* back pointer */
+ int64_t last_igmp_v1_report_dsec;
+ int64_t last_igmp_v2_report_dsec;
+};
+
+struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp,
+ struct in_addr group_addr,
+ const char *ifname);
+
+void igmp_group_delete_empty_include(struct igmp_group *group);
+
+void igmp_startup_mode_on(struct igmp_sock *igmp);
+
+void igmp_group_timer_on(struct igmp_group *group,
+ long interval_msec, const char *ifname);
+
+#endif /* PIM_IGMP_H */
diff --git a/pimd/pim_igmp_join.c b/pimd/pim_igmp_join.c
new file mode 100644
index 00000000..ead246c3
--- /dev/null
+++ b/pimd/pim_igmp_join.c
@@ -0,0 +1,65 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "pim_igmp_join.h"
+
+#ifndef MCAST_JOIN_SOURCE_GROUP
+#define MCAST_JOIN_SOURCE_GROUP 46
+struct group_source_req
+{
+ uint32_t gsr_interface;
+ struct sockaddr_storage gsr_group;
+ struct sockaddr_storage gsr_source;
+};
+#endif
+
+int pim_igmp_join_source(int fd, int ifindex,
+ struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ struct group_source_req req;
+ struct sockaddr_in *group_sa = (struct sockaddr_in *) &req.gsr_group;
+ struct sockaddr_in *source_sa = (struct sockaddr_in *) &req.gsr_source;
+
+ memset(group_sa, 0, sizeof(*group_sa));
+ group_sa->sin_family = AF_INET;
+ group_sa->sin_addr = group_addr;
+ group_sa->sin_port = htons(0);
+
+ memset(source_sa, 0, sizeof(*source_sa));
+ source_sa->sin_family = AF_INET;
+ source_sa->sin_addr = source_addr;
+ source_sa->sin_port = htons(0);
+
+ req.gsr_interface = ifindex;
+
+ return setsockopt(fd, IPPROTO_IP, MCAST_JOIN_SOURCE_GROUP,
+ &req, sizeof(req));
+
+ return 0;
+}
diff --git a/pimd/pim_igmp_join.h b/pimd/pim_igmp_join.h
new file mode 100644
index 00000000..1127af12
--- /dev/null
+++ b/pimd/pim_igmp_join.h
@@ -0,0 +1,32 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_IGMP_JOIN_H
+#define PIM_IGMP_JOIN_H
+
+#include <netinet/in.h>
+
+int pim_igmp_join_source(int fd, int ifindex,
+ struct in_addr group_addr,
+ struct in_addr source_addr);
+
+#endif /* PIM_IGMP_JOIN_H */
diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c
new file mode 100644
index 00000000..7e76f442
--- /dev/null
+++ b/pimd/pim_igmpv3.c
@@ -0,0 +1,1728 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+#include "log.h"
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_iface.h"
+#include "pim_igmp.h"
+#include "pim_igmpv3.h"
+#include "pim_str.h"
+#include "pim_util.h"
+#include "pim_time.h"
+#include "pim_zebra.h"
+#include "pim_oil.h"
+
+static void group_retransmit_timer_on(struct igmp_group *group);
+static long igmp_group_timer_remain_msec(struct igmp_group *group);
+static long igmp_source_timer_remain_msec(struct igmp_source *source);
+static void group_query_send(struct igmp_group *group);
+static void source_query_send_by_flag(struct igmp_group *group,
+ int num_sources_tosend);
+
+static void on_trace(const char *label,
+ struct interface *ifp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char from_str[100];
+ char group_str[100];
+
+ pim_inet4_dump("<from?>", from, from_str, sizeof(from_str));
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+
+ zlog_debug("%s: from %s on %s: group=%s sources=%d",
+ label, from_str, ifp->name, group_str, num_sources);
+ }
+}
+
+int igmp_group_compat_mode(const struct igmp_sock *igmp,
+ const struct igmp_group *group)
+{
+ struct pim_interface *pim_ifp;
+ int64_t now_dsec;
+ long older_host_present_interval_dsec;
+
+ zassert(igmp);
+ zassert(igmp->interface);
+ zassert(igmp->interface->info);
+
+ pim_ifp = igmp->interface->info;
+
+ /*
+ RFC 3376: 8.13. Older Host Present Interval
+
+ This value MUST be ((the Robustness Variable) times (the Query
+ Interval)) plus (one Query Response Interval).
+
+ older_host_present_interval_dsec = \
+ igmp->querier_robustness_variable * \
+ 10 * igmp->querier_query_interval + \
+ pim_ifp->query_max_response_time_dsec;
+ */
+ older_host_present_interval_dsec =
+ PIM_IGMP_OHPI_DSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec);
+
+ now_dsec = pim_time_monotonic_dsec();
+ if (now_dsec < 1) {
+ /* broken timer logged by pim_time_monotonic_dsec() */
+ return 3;
+ }
+
+ if ((now_dsec - group->last_igmp_v1_report_dsec) < older_host_present_interval_dsec)
+ return 1; /* IGMPv1 */
+
+ if ((now_dsec - group->last_igmp_v2_report_dsec) < older_host_present_interval_dsec)
+ return 2; /* IGMPv2 */
+
+ return 3; /* IGMPv3 */
+}
+
+void igmp_group_reset_gmi(struct igmp_group *group)
+{
+ long group_membership_interval_msec;
+ struct pim_interface *pim_ifp;
+ struct igmp_sock *igmp;
+ struct interface *ifp;
+
+ igmp = group->group_igmp_sock;
+ ifp = igmp->interface;
+ pim_ifp = ifp->info;
+
+ /*
+ RFC 3376: 8.4. Group Membership Interval
+
+ The Group Membership Interval is the amount of time that must pass
+ before a multicast router decides there are no more members of a
+ group or a particular source on a network.
+
+ This value MUST be ((the Robustness Variable) times (the Query
+ Interval)) plus (one Query Response Interval).
+
+ group_membership_interval_msec = querier_robustness_variable *
+ (1000 * querier_query_interval) +
+ 100 * query_response_interval_dsec;
+ */
+ group_membership_interval_msec =
+ PIM_IGMP_GMI_MSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("Resetting group %s timer to GMI=%ld.%03ld sec on %s",
+ group_str,
+ group_membership_interval_msec / 1000,
+ group_membership_interval_msec % 1000,
+ ifp->name);
+ }
+
+ /*
+ RFC 3376: 6.2.2. Definition of Group Timers
+
+ The group timer is only used when a group is in EXCLUDE mode and
+ it represents the time for the *filter-mode* of the group to
+ expire and switch to INCLUDE mode.
+ */
+ zassert(group->group_filtermode_isexcl);
+
+ igmp_group_timer_on(group, group_membership_interval_msec, ifp->name);
+}
+
+static int igmp_source_timer(struct thread *t)
+{
+ struct igmp_source *source;
+ struct igmp_group *group;
+
+ zassert(t);
+ source = THREAD_ARG(t);
+ zassert(source);
+
+ group = source->source_group;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_debug("%s: Source timer expired for group %s source %s on %s",
+ __PRETTY_FUNCTION__,
+ group_str, source_str,
+ group->group_igmp_sock->interface->name);
+ }
+
+ zassert(source->t_source_timer);
+ source->t_source_timer = 0;
+
+ /*
+ RFC 3376: 6.3. IGMPv3 Source-Specific Forwarding Rules
+
+ Group
+ Filter-Mode Source Timer Value Action
+ ----------- ------------------ ------
+ INCLUDE TIMER == 0 Suggest to stop forwarding
+ traffic from source and
+ remove source record. If
+ there are no more source
+ records for the group, delete
+ group record.
+
+ EXCLUDE TIMER == 0 Suggest to not forward
+ traffic from source
+ (DO NOT remove record)
+
+ Source timer switched from (T > 0) to (T == 0): disable forwarding.
+ */
+
+ zassert(!source->t_source_timer);
+
+ if (group->group_filtermode_isexcl) {
+ /* EXCLUDE mode */
+
+ igmp_source_forward_stop(source);
+ }
+ else {
+ /* INCLUDE mode */
+
+ /* igmp_source_delete() will stop forwarding source */
+ igmp_source_delete(source);
+
+ /*
+ If there are no more source records for the group, delete group
+ record.
+ */
+ if (!listcount(group->group_source_list)) {
+ igmp_group_delete_empty_include(group);
+ }
+ }
+
+ return 0;
+}
+
+static void source_timer_off(struct igmp_group *group,
+ struct igmp_source *source)
+{
+ if (!source->t_source_timer)
+ return;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_debug("Cancelling TIMER event for group %s source %s on %s",
+ group_str, source_str,
+ group->group_igmp_sock->interface->name);
+ }
+
+ THREAD_OFF(source->t_source_timer);
+ zassert(!source->t_source_timer);
+}
+
+static void igmp_source_timer_on(struct igmp_group *group,
+ struct igmp_source *source,
+ long interval_msec)
+{
+ source_timer_off(group, source);
+
+ if (PIM_DEBUG_IGMP_EVENTS) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_debug("Scheduling %ld.%03ld sec TIMER event for group %s source %s on %s",
+ interval_msec / 1000,
+ interval_msec % 1000,
+ group_str, source_str,
+ group->group_igmp_sock->interface->name);
+ }
+
+ THREAD_TIMER_MSEC_ON(master, source->t_source_timer,
+ igmp_source_timer,
+ source, interval_msec);
+ zassert(source->t_source_timer);
+
+ /*
+ RFC 3376: 6.3. IGMPv3 Source-Specific Forwarding Rules
+
+ Source timer switched from (T == 0) to (T > 0): enable forwarding.
+ */
+ igmp_source_forward_start(source);
+}
+
+void igmp_source_reset_gmi(struct igmp_sock *igmp,
+ struct igmp_group *group,
+ struct igmp_source *source)
+{
+ long group_membership_interval_msec;
+ struct pim_interface *pim_ifp;
+ struct interface *ifp;
+
+ ifp = igmp->interface;
+ pim_ifp = ifp->info;
+
+ group_membership_interval_msec =
+ PIM_IGMP_GMI_MSEC(igmp->querier_robustness_variable,
+ igmp->querier_query_interval,
+ pim_ifp->igmp_query_max_response_time_dsec);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ char source_str[100];
+
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+
+ zlog_debug("Resetting source %s timer to GMI=%ld.%03ld sec for group %s on %s",
+ source_str,
+ group_membership_interval_msec / 1000,
+ group_membership_interval_msec % 1000,
+ group_str,
+ ifp->name);
+ }
+
+ igmp_source_timer_on(group, source,
+ group_membership_interval_msec);
+}
+
+static void source_mark_delete_flag(struct list *source_list)
+{
+ struct listnode *src_node;
+ struct igmp_source *src;
+
+ for (ALL_LIST_ELEMENTS_RO(source_list, src_node, src)) {
+ IGMP_SOURCE_DO_DELETE(src->source_flags);
+ }
+}
+
+static void source_mark_send_flag(struct list *source_list)
+{
+ struct listnode *src_node;
+ struct igmp_source *src;
+
+ for (ALL_LIST_ELEMENTS_RO(source_list, src_node, src)) {
+ IGMP_SOURCE_DO_SEND(src->source_flags);
+ }
+}
+
+static int source_mark_send_flag_by_timer(struct list *source_list)
+{
+ struct listnode *src_node;
+ struct igmp_source *src;
+ int num_marked_sources = 0;
+
+ for (ALL_LIST_ELEMENTS_RO(source_list, src_node, src)) {
+ /* Is source timer running? */
+ if (src->t_source_timer) {
+ IGMP_SOURCE_DO_SEND(src->source_flags);
+ ++num_marked_sources;
+ }
+ else {
+ IGMP_SOURCE_DONT_SEND(src->source_flags);
+ }
+ }
+
+ return num_marked_sources;
+}
+
+static void source_clear_send_flag(struct list *source_list)
+{
+ struct listnode *src_node;
+ struct igmp_source *src;
+
+ for (ALL_LIST_ELEMENTS_RO(source_list, src_node, src)) {
+ IGMP_SOURCE_DONT_SEND(src->source_flags);
+ }
+}
+
+/*
+ Any source (*,G) is forwarded only if mode is EXCLUDE {empty}
+*/
+static void group_exclude_fwd_anysrc_ifempty(struct igmp_group *group)
+{
+ zassert(group->group_filtermode_isexcl);
+
+ if (listcount(group->group_source_list) < 1) {
+ igmp_anysource_forward_start(group);
+ }
+}
+
+void igmp_source_free(struct igmp_source *source)
+{
+ /* make sure there is no source timer running */
+ zassert(!source->t_source_timer);
+
+ XFREE(MTYPE_PIM_IGMP_GROUP_SOURCE, source);
+}
+
+static void source_channel_oil_detach(struct igmp_source *source)
+{
+ if (source->source_channel_oil) {
+ pim_channel_oil_del(source->source_channel_oil);
+ source->source_channel_oil = 0;
+ }
+}
+
+void igmp_source_delete(struct igmp_source *source)
+{
+ struct igmp_group *group;
+
+ group = source->source_group;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_debug("Deleting IGMP source %s for group %s from socket %d interface %s",
+ source_str, group_str,
+ group->group_igmp_sock->fd,
+ group->group_igmp_sock->interface->name);
+ }
+
+ source_timer_off(group, source);
+ igmp_source_forward_stop(source);
+
+ /* make sure forwarding is disabled */
+ zassert(!IGMP_SOURCE_TEST_FORWARDING(source->source_flags));
+
+ source_channel_oil_detach(source);
+
+ /*
+ notice that listnode_delete() can't be moved
+ into igmp_source_free() because the later is
+ called by list_delete_all_node()
+ */
+ listnode_delete(group->group_source_list, source);
+
+ igmp_source_free(source);
+
+ if (group->group_filtermode_isexcl) {
+ group_exclude_fwd_anysrc_ifempty(group);
+ }
+}
+
+static void source_delete_by_flag(struct list *source_list)
+{
+ struct listnode *src_node;
+ struct listnode *src_nextnode;
+ struct igmp_source *src;
+
+ for (ALL_LIST_ELEMENTS(source_list, src_node, src_nextnode, src))
+ if (IGMP_SOURCE_TEST_DELETE(src->source_flags))
+ igmp_source_delete(src);
+}
+
+void igmp_source_delete_expired(struct list *source_list)
+{
+ struct listnode *src_node;
+ struct listnode *src_nextnode;
+ struct igmp_source *src;
+
+ for (ALL_LIST_ELEMENTS(source_list, src_node, src_nextnode, src))
+ if (!src->t_source_timer)
+ igmp_source_delete(src);
+}
+
+struct igmp_source *igmp_find_source_by_addr(struct igmp_group *group,
+ struct in_addr src_addr)
+{
+ struct listnode *src_node;
+ struct igmp_source *src;
+
+ for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src))
+ if (src_addr.s_addr == src->source_addr.s_addr)
+ return src;
+
+ return 0;
+}
+
+static struct igmp_source *source_new(struct igmp_group *group,
+ struct in_addr src_addr,
+ const char *ifname)
+{
+ struct igmp_source *src;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", src_addr, source_str, sizeof(source_str));
+ zlog_debug("Creating new IGMP source %s for group %s on socket %d interface %s",
+ source_str, group_str,
+ group->group_igmp_sock->fd,
+ ifname);
+ }
+
+ src = XMALLOC(MTYPE_PIM_IGMP_GROUP_SOURCE, sizeof(*src));
+ if (!src) {
+ zlog_warn("%s %s: XMALLOC() failure",
+ __FILE__, __PRETTY_FUNCTION__);
+ return 0; /* error, not found, could not create */
+ }
+
+ src->t_source_timer = 0;
+ src->source_group = group; /* back pointer */
+ src->source_addr = src_addr;
+ src->source_creation = pim_time_monotonic_sec();
+ src->source_flags = 0;
+ src->source_query_retransmit_count = 0;
+ src->source_channel_oil = 0;
+
+ listnode_add(group->group_source_list, src);
+
+ zassert(!src->t_source_timer); /* source timer == 0 */
+
+ /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
+ igmp_anysource_forward_stop(group);
+
+ return src;
+}
+
+static struct igmp_source *add_source_by_addr(struct igmp_sock *igmp,
+ struct igmp_group *group,
+ struct in_addr src_addr,
+ const char *ifname)
+{
+ struct igmp_source *src;
+
+ src = igmp_find_source_by_addr(group, src_addr);
+ if (src) {
+ return src;
+ }
+
+ src = source_new(group, src_addr, ifname);
+ if (!src) {
+ return 0;
+ }
+
+ return src;
+}
+
+static void allow(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ struct interface *ifp = igmp->interface;
+ struct pim_interface *pim_ifp;
+ struct igmp_group *group;
+ int i;
+
+ pim_ifp = ifp->info;
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return;
+ }
+
+ /* scan received sources */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ source = add_source_by_addr(igmp, group, *src_addr, ifp->name);
+ if (!source) {
+ continue;
+ }
+
+ /*
+ RFC 3376: 6.4.1. Reception of Current-State Records
+
+ When receiving IS_IN reports for groups in EXCLUDE mode is
+ sources should be moved from set with (timers = 0) to set with
+ (timers > 0).
+
+ igmp_source_reset_gmi() below, resetting the source timers to
+ GMI, accomplishes this.
+ */
+ igmp_source_reset_gmi(igmp, group, source);
+
+ } /* scan received sources */
+}
+
+void igmpv3_report_isin(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ on_trace(__PRETTY_FUNCTION__,
+ igmp->interface, from, group_addr, num_sources, sources);
+
+ allow(igmp, from, group_addr, num_sources, sources);
+}
+
+static void isex_excl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ int i;
+
+ /* EXCLUDE mode */
+ zassert(group->group_filtermode_isexcl);
+
+ /* E.1: set deletion flag for known sources (X,Y) */
+ source_mark_delete_flag(group->group_source_list);
+
+ /* scan received sources (A) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* E.2: lookup reported source from (A) in (X,Y) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ /* E.3: if found, clear deletion flag: (X*A) or (Y*A) */
+ IGMP_SOURCE_DONT_DELETE(source->source_flags);
+ }
+ else {
+ /* E.4: if not found, create source with timer=GMI: (A-X-Y) */
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+ zassert(!source->t_source_timer); /* timer == 0 */
+ igmp_source_reset_gmi(group->group_igmp_sock, group, source);
+ zassert(source->t_source_timer); /* (A-X-Y) timer > 0 */
+ }
+
+ } /* scan received sources */
+
+ /* E.5: delete all sources marked with deletion flag: (X-A) and (Y-A) */
+ source_delete_by_flag(group->group_source_list);
+}
+
+static void isex_incl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ int i;
+
+ /* INCLUDE mode */
+ zassert(!group->group_filtermode_isexcl);
+
+ /* I.1: set deletion flag for known sources (A) */
+ source_mark_delete_flag(group->group_source_list);
+
+ /* scan received sources (B) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* I.2: lookup reported source (B) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ /* I.3: if found, clear deletion flag (A*B) */
+ IGMP_SOURCE_DONT_DELETE(source->source_flags);
+ }
+ else {
+ /* I.4: if not found, create source with timer=0 (B-A) */
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+ zassert(!source->t_source_timer); /* (B-A) timer=0 */
+ }
+
+ } /* scan received sources */
+
+ /* I.5: delete all sources marked with deletion flag (A-B) */
+ source_delete_by_flag(group->group_source_list);
+
+ group->group_filtermode_isexcl = 1; /* boolean=true */
+
+ zassert(group->group_filtermode_isexcl);
+
+ group_exclude_fwd_anysrc_ifempty(group);
+}
+
+void igmpv3_report_isex(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ struct interface *ifp = igmp->interface;
+ struct pim_interface *pim_ifp;
+ struct igmp_group *group;
+
+ on_trace(__PRETTY_FUNCTION__,
+ ifp, from, group_addr, num_sources, sources);
+
+ pim_ifp = ifp->info;
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return;
+ }
+
+ if (group->group_filtermode_isexcl) {
+ /* EXCLUDE mode */
+ isex_excl(group, num_sources, sources);
+ }
+ else {
+ /* INCLUDE mode */
+ isex_incl(group, num_sources, sources);
+ zassert(group->group_filtermode_isexcl);
+ }
+
+ zassert(group->group_filtermode_isexcl);
+
+ igmp_group_reset_gmi(group);
+}
+
+static void toin_incl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ struct igmp_sock *igmp = group->group_igmp_sock;
+ int num_sources_tosend = listcount(group->group_source_list);
+ int i;
+
+ /* Set SEND flag for all known sources (A) */
+ source_mark_send_flag(group->group_source_list);
+
+ /* Scan received sources (B) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* Lookup reported source (B) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ /* If found, clear SEND flag (A*B) */
+ IGMP_SOURCE_DONT_SEND(source->source_flags);
+ --num_sources_tosend;
+ }
+ else {
+ /* If not found, create new source */
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+ }
+
+ /* (B)=GMI */
+ igmp_source_reset_gmi(igmp, group, source);
+ }
+
+ /* Send sources marked with SEND flag: Q(G,A-B) */
+ if (num_sources_tosend > 0) {
+ source_query_send_by_flag(group, num_sources_tosend);
+ }
+}
+
+static void toin_excl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ struct igmp_sock *igmp = group->group_igmp_sock;
+ int num_sources_tosend;
+ int i;
+
+ /* Set SEND flag for X (sources with timer > 0) */
+ num_sources_tosend = source_mark_send_flag_by_timer(group->group_source_list);
+
+ /* Scan received sources (A) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* Lookup reported source (A) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ if (source->t_source_timer) {
+ /* If found and timer running, clear SEND flag (X*A) */
+ IGMP_SOURCE_DONT_SEND(source->source_flags);
+ --num_sources_tosend;
+ }
+ }
+ else {
+ /* If not found, create new source */
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+ }
+
+ /* (A)=GMI */
+ igmp_source_reset_gmi(igmp, group, source);
+ }
+
+ /* Send sources marked with SEND flag: Q(G,X-A) */
+ if (num_sources_tosend > 0) {
+ source_query_send_by_flag(group, num_sources_tosend);
+ }
+
+ /* Send Q(G) */
+ group_query_send(group);
+}
+
+void igmpv3_report_toin(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ struct interface *ifp = igmp->interface;
+ struct pim_interface *pim_ifp;
+ struct igmp_group *group;
+
+ on_trace(__PRETTY_FUNCTION__,
+ ifp, from, group_addr, num_sources, sources);
+
+ pim_ifp = ifp->info;
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return;
+ }
+
+ if (group->group_filtermode_isexcl) {
+ /* EXCLUDE mode */
+ toin_excl(group, num_sources, sources);
+ }
+ else {
+ /* INCLUDE mode */
+ toin_incl(group, num_sources, sources);
+ }
+}
+
+static void toex_incl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ int num_sources_tosend = 0;
+ int i;
+
+ zassert(!group->group_filtermode_isexcl);
+
+ /* Set DELETE flag for all known sources (A) */
+ source_mark_delete_flag(group->group_source_list);
+
+ /* Clear off SEND flag from all known sources (A) */
+ source_clear_send_flag(group->group_source_list);
+
+ /* Scan received sources (B) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* Lookup reported source (B) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ /* If found, clear deletion flag: (A*B) */
+ IGMP_SOURCE_DONT_DELETE(source->source_flags);
+ /* and set SEND flag (A*B) */
+ IGMP_SOURCE_DO_SEND(source->source_flags);
+ ++num_sources_tosend;
+ }
+ else {
+ /* If source not found, create source with timer=0: (B-A)=0 */
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+ zassert(!source->t_source_timer); /* (B-A) timer=0 */
+ }
+
+ } /* Scan received sources (B) */
+
+ group->group_filtermode_isexcl = 1; /* boolean=true */
+
+ /* Delete all sources marked with DELETE flag (A-B) */
+ source_delete_by_flag(group->group_source_list);
+
+ /* Send sources marked with SEND flag: Q(G,A*B) */
+ if (num_sources_tosend > 0) {
+ source_query_send_by_flag(group, num_sources_tosend);
+ }
+
+ zassert(group->group_filtermode_isexcl);
+
+ group_exclude_fwd_anysrc_ifempty(group);
+}
+
+static void toex_excl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ int num_sources_tosend = 0;
+ int i;
+
+ /* set DELETE flag for all known sources (X,Y) */
+ source_mark_delete_flag(group->group_source_list);
+
+ /* clear off SEND flag from all known sources (X,Y) */
+ source_clear_send_flag(group->group_source_list);
+
+ /* scan received sources (A) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* lookup reported source (A) in known sources (X,Y) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ /* if found, clear off DELETE flag from reported source (A) */
+ IGMP_SOURCE_DONT_DELETE(source->source_flags);
+ }
+ else {
+ /* if not found, create source with Group Timer: (A-X-Y)=Group Timer */
+ long group_timer_msec;
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+
+ zassert(!source->t_source_timer); /* timer == 0 */
+ group_timer_msec = igmp_group_timer_remain_msec(group);
+ igmp_source_timer_on(group, source, group_timer_msec);
+ zassert(source->t_source_timer); /* (A-X-Y) timer > 0 */
+
+ /* make sure source is created with DELETE flag unset */
+ zassert(!IGMP_SOURCE_TEST_DELETE(source->source_flags));
+ }
+
+ /* make sure reported source has DELETE flag unset */
+ zassert(!IGMP_SOURCE_TEST_DELETE(source->source_flags));
+
+ if (source->t_source_timer) {
+ /* if source timer>0 mark SEND flag: Q(G,A-Y) */
+ IGMP_SOURCE_DO_SEND(source->source_flags);
+ ++num_sources_tosend;
+ }
+
+ } /* scan received sources (A) */
+
+ /*
+ delete all sources marked with DELETE flag:
+ Delete (X-A)
+ Delete (Y-A)
+ */
+ source_delete_by_flag(group->group_source_list);
+
+ /* send sources marked with SEND flag: Q(G,A-Y) */
+ if (num_sources_tosend > 0) {
+ source_query_send_by_flag(group, num_sources_tosend);
+ }
+}
+
+void igmpv3_report_toex(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ struct interface *ifp = igmp->interface;
+ struct pim_interface *pim_ifp;
+ struct igmp_group *group;
+
+ on_trace(__PRETTY_FUNCTION__,
+ ifp, from, group_addr, num_sources, sources);
+
+ pim_ifp = ifp->info;
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return;
+ }
+
+ if (group->group_filtermode_isexcl) {
+ /* EXCLUDE mode */
+ toex_excl(group, num_sources, sources);
+ }
+ else {
+ /* INCLUDE mode */
+ toex_incl(group, num_sources, sources);
+ zassert(group->group_filtermode_isexcl);
+ }
+ zassert(group->group_filtermode_isexcl);
+
+ /* Group Timer=GMI */
+ igmp_group_reset_gmi(group);
+}
+
+void igmpv3_report_allow(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ on_trace(__PRETTY_FUNCTION__,
+ igmp->interface, from, group_addr, num_sources, sources);
+
+ allow(igmp, from, group_addr, num_sources, sources);
+}
+
+/*
+ RFC3376: 6.6.3.1. Building and Sending Group Specific Queries
+
+ When transmitting a group specific query, if the group timer is
+ larger than LMQT, the "Suppress Router-Side Processing" bit is set
+ in the query message.
+*/
+static void group_retransmit_group(struct igmp_group *group)
+{
+ char query_buf[PIM_IGMP_BUFSIZE_WRITE];
+ struct igmp_sock *igmp;
+ struct pim_interface *pim_ifp;
+ long lmqc; /* Last Member Query Count */
+ long lmqi_msec; /* Last Member Query Interval */
+ long lmqt_msec; /* Last Member Query Time */
+ int s_flag;
+
+ igmp = group->group_igmp_sock;
+ pim_ifp = igmp->interface->info;
+
+ lmqc = igmp->querier_robustness_variable;
+ lmqi_msec = 100 * pim_ifp->igmp_specific_query_max_response_time_dsec;
+ lmqt_msec = lmqc * lmqi_msec;
+
+ /*
+ RFC3376: 6.6.3.1. Building and Sending Group Specific Queries
+
+ When transmitting a group specific query, if the group timer is
+ larger than LMQT, the "Suppress Router-Side Processing" bit is set
+ in the query message.
+ */
+ s_flag = igmp_group_timer_remain_msec(group) > lmqt_msec;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("retransmit_group_specific_query: group %s on %s: s_flag=%d count=%d",
+ group_str, igmp->interface->name, s_flag,
+ group->group_specific_query_retransmit_count);
+ }
+
+ /*
+ RFC3376: 4.1.12. IP Destination Addresses for Queries
+
+ Group-Specific and Group-and-Source-Specific Queries are sent with
+ an IP destination address equal to the multicast address of
+ interest.
+ */
+
+ pim_igmp_send_membership_query(group,
+ igmp->fd,
+ igmp->interface->name,
+ query_buf,
+ sizeof(query_buf),
+ 0 /* num_sources_tosend */,
+ group->group_addr /* dst_addr */,
+ group->group_addr /* group_addr */,
+ pim_ifp->igmp_specific_query_max_response_time_dsec,
+ s_flag,
+ igmp->querier_robustness_variable,
+ igmp->querier_query_interval);
+}
+
+/*
+ RFC3376: 6.6.3.2. Building and Sending Group and Source Specific Queries
+
+ When building a group and source specific query for a group G, two
+ separate query messages are sent for the group. The first one has
+ the "Suppress Router-Side Processing" bit set and contains all the
+ sources with retransmission state and timers greater than LMQT. The
+ second has the "Suppress Router-Side Processing" bit clear and
+ contains all the sources with retransmission state and timers lower
+ or equal to LMQT. If either of the two calculated messages does not
+ contain any sources, then its transmission is suppressed.
+ */
+static int group_retransmit_sources(struct igmp_group *group,
+ int send_with_sflag_set)
+{
+ struct igmp_sock *igmp;
+ struct pim_interface *pim_ifp;
+ long lmqc; /* Last Member Query Count */
+ long lmqi_msec; /* Last Member Query Interval */
+ long lmqt_msec; /* Last Member Query Time */
+ char query_buf1[PIM_IGMP_BUFSIZE_WRITE]; /* 1 = with s_flag set */
+ char query_buf2[PIM_IGMP_BUFSIZE_WRITE]; /* 2 = with s_flag clear */
+ int query_buf1_max_sources;
+ int query_buf2_max_sources;
+ struct in_addr *source_addr1;
+ struct in_addr *source_addr2;
+ int num_sources_tosend1;
+ int num_sources_tosend2;
+ struct listnode *src_node;
+ struct igmp_source *src;
+ int num_retransmit_sources_left = 0;
+
+ query_buf1_max_sources = (sizeof(query_buf1) - IGMP_V3_SOURCES_OFFSET) >> 2;
+ query_buf2_max_sources = (sizeof(query_buf2) - IGMP_V3_SOURCES_OFFSET) >> 2;
+
+ source_addr1 = (struct in_addr *)(query_buf1 + IGMP_V3_SOURCES_OFFSET);
+ source_addr2 = (struct in_addr *)(query_buf2 + IGMP_V3_SOURCES_OFFSET);
+
+ igmp = group->group_igmp_sock;
+ pim_ifp = igmp->interface->info;
+
+ lmqc = igmp->querier_robustness_variable;
+ lmqi_msec = 100 * pim_ifp->igmp_specific_query_max_response_time_dsec;
+ lmqt_msec = lmqc * lmqi_msec;
+
+ /* Scan all group sources */
+ for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src)) {
+
+ /* Source has retransmission state? */
+ if (src->source_query_retransmit_count < 1)
+ continue;
+
+ if (--src->source_query_retransmit_count > 0) {
+ ++num_retransmit_sources_left;
+ }
+
+ /* Copy source address into appropriate query buffer */
+ if (igmp_source_timer_remain_msec(src) > lmqt_msec) {
+ *source_addr1 = src->source_addr;
+ ++source_addr1;
+ }
+ else {
+ *source_addr2 = src->source_addr;
+ ++source_addr2;
+ }
+
+ }
+
+ num_sources_tosend1 = source_addr1 - (struct in_addr *)(query_buf1 + IGMP_V3_SOURCES_OFFSET);
+ num_sources_tosend2 = source_addr2 - (struct in_addr *)(query_buf2 + IGMP_V3_SOURCES_OFFSET);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("retransmit_grp&src_specific_query: group %s on %s: srcs_with_sflag=%d srcs_wo_sflag=%d will_send_sflag=%d retransmit_src_left=%d",
+ group_str, igmp->interface->name,
+ num_sources_tosend1,
+ num_sources_tosend2,
+ send_with_sflag_set,
+ num_retransmit_sources_left);
+ }
+
+ if (num_sources_tosend1 > 0) {
+ /*
+ Send group-and-source-specific query with s_flag set and all
+ sources with timers greater than LMQT.
+ */
+
+ if (send_with_sflag_set) {
+
+ query_buf1_max_sources = (sizeof(query_buf1) - IGMP_V3_SOURCES_OFFSET) >> 2;
+ if (num_sources_tosend1 > query_buf1_max_sources) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: group %s on %s: s_flag=1 unable to fit %d sources into buf_size=%d (max_sources=%d)",
+ __PRETTY_FUNCTION__, group_str, igmp->interface->name,
+ num_sources_tosend1, sizeof(query_buf1), query_buf1_max_sources);
+ }
+ else {
+ /*
+ RFC3376: 4.1.12. IP Destination Addresses for Queries
+
+ Group-Specific and Group-and-Source-Specific Queries are sent with
+ an IP destination address equal to the multicast address of
+ interest.
+ */
+
+ pim_igmp_send_membership_query(group,
+ igmp->fd,
+ igmp->interface->name,
+ query_buf1,
+ sizeof(query_buf1),
+ num_sources_tosend1,
+ group->group_addr,
+ group->group_addr,
+ pim_ifp->igmp_specific_query_max_response_time_dsec,
+ 1 /* s_flag */,
+ igmp->querier_robustness_variable,
+ igmp->querier_query_interval);
+
+ }
+
+ } /* send_with_sflag_set */
+
+ }
+
+ if (num_sources_tosend2 > 0) {
+ /*
+ Send group-and-source-specific query with s_flag clear and all
+ sources with timers lower or equal to LMQT.
+ */
+
+ query_buf2_max_sources = (sizeof(query_buf2) - IGMP_V3_SOURCES_OFFSET) >> 2;
+ if (num_sources_tosend2 > query_buf2_max_sources) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: group %s on %s: s_flag=0 unable to fit %d sources into buf_size=%d (max_sources=%d)",
+ __PRETTY_FUNCTION__, group_str, igmp->interface->name,
+ num_sources_tosend2, sizeof(query_buf2), query_buf2_max_sources);
+ }
+ else {
+ /*
+ RFC3376: 4.1.12. IP Destination Addresses for Queries
+
+ Group-Specific and Group-and-Source-Specific Queries are sent with
+ an IP destination address equal to the multicast address of
+ interest.
+ */
+
+ pim_igmp_send_membership_query(group,
+ igmp->fd,
+ igmp->interface->name,
+ query_buf2,
+ sizeof(query_buf2),
+ num_sources_tosend2,
+ group->group_addr,
+ group->group_addr,
+ pim_ifp->igmp_specific_query_max_response_time_dsec,
+ 0 /* s_flag */,
+ igmp->querier_robustness_variable,
+ igmp->querier_query_interval);
+
+ }
+ }
+
+ return num_retransmit_sources_left;
+}
+
+static int igmp_group_retransmit(struct thread *t)
+{
+ struct igmp_group *group;
+ int num_retransmit_sources_left;
+ int send_with_sflag_set; /* boolean */
+
+ zassert(t);
+ group = THREAD_ARG(t);
+ zassert(group);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("group_retransmit_timer: group %s on %s",
+ group_str, group->group_igmp_sock->interface->name);
+ }
+
+ /* Retransmit group-specific queries? (RFC3376: 6.6.3.1) */
+ if (group->group_specific_query_retransmit_count > 0) {
+
+ /* Retransmit group-specific queries (RFC3376: 6.6.3.1) */
+ group_retransmit_group(group);
+ --group->group_specific_query_retransmit_count;
+
+ /*
+ RFC3376: 6.6.3.2
+ If a group specific query is scheduled to be transmitted at the
+ same time as a group and source specific query for the same group,
+ then transmission of the group and source specific message with the
+ "Suppress Router-Side Processing" bit set may be suppressed.
+ */
+ send_with_sflag_set = 0; /* boolean=false */
+ }
+ else {
+ send_with_sflag_set = 1; /* boolean=true */
+ }
+
+ /* Retransmit group-and-source-specific queries (RFC3376: 6.6.3.2) */
+ num_retransmit_sources_left = group_retransmit_sources(group,
+ send_with_sflag_set);
+
+ group->t_group_query_retransmit_timer = 0;
+
+ /*
+ Keep group retransmit timer running if there is any retransmit
+ counter pending
+ */
+ if ((num_retransmit_sources_left > 0) ||
+ (group->group_specific_query_retransmit_count > 0)) {
+ group_retransmit_timer_on(group);
+ }
+
+ return 0;
+}
+
+/*
+ group_retransmit_timer_on:
+ if group retransmit timer isn't running, starts it;
+ otherwise, do nothing
+*/
+static void group_retransmit_timer_on(struct igmp_group *group)
+{
+ struct igmp_sock *igmp;
+ struct pim_interface *pim_ifp;
+ long lmqi_msec; /* Last Member Query Interval */
+
+ /* if group retransmit timer is running, do nothing */
+ if (group->t_group_query_retransmit_timer) {
+ return;
+ }
+
+ igmp = group->group_igmp_sock;
+ pim_ifp = igmp->interface->info;
+
+ lmqi_msec = 100 * pim_ifp->igmp_specific_query_max_response_time_dsec;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("Scheduling %ld.%03ld sec retransmit timer for group %s on %s",
+ lmqi_msec / 1000,
+ lmqi_msec % 1000,
+ group_str,
+ igmp->interface->name);
+ }
+
+ THREAD_TIMER_MSEC_ON(master, group->t_group_query_retransmit_timer,
+ igmp_group_retransmit,
+ group, lmqi_msec);
+}
+
+static long igmp_group_timer_remain_msec(struct igmp_group *group)
+{
+ return pim_time_timer_remain_msec(group->t_group_timer);
+}
+
+static long igmp_source_timer_remain_msec(struct igmp_source *source)
+{
+ return pim_time_timer_remain_msec(source->t_source_timer);
+}
+
+/*
+ RFC3376: 6.6.3.1. Building and Sending Group Specific Queries
+*/
+static void group_query_send(struct igmp_group *group)
+{
+ long lmqc; /* Last Member Query Count */
+
+ lmqc = group->group_igmp_sock->querier_robustness_variable;
+
+ /* lower group timer to lmqt */
+ igmp_group_timer_lower_to_lmqt(group);
+
+ /* reset retransmission counter */
+ group->group_specific_query_retransmit_count = lmqc;
+
+ /* immediately send group specific query (decrease retransmit counter by 1)*/
+ group_retransmit_group(group);
+
+ /* make sure group retransmit timer is running */
+ group_retransmit_timer_on(group);
+}
+
+/*
+ RFC3376: 6.6.3.2. Building and Sending Group and Source Specific Queries
+*/
+static void source_query_send_by_flag(struct igmp_group *group,
+ int num_sources_tosend)
+{
+ struct igmp_sock *igmp;
+ struct pim_interface *pim_ifp;
+ struct listnode *src_node;
+ struct igmp_source *src;
+ long lmqc; /* Last Member Query Count */
+ long lmqi_msec; /* Last Member Query Interval */
+ long lmqt_msec; /* Last Member Query Time */
+
+ zassert(num_sources_tosend > 0);
+
+ igmp = group->group_igmp_sock;
+ pim_ifp = igmp->interface->info;
+
+ lmqc = igmp->querier_robustness_variable;
+ lmqi_msec = 100 * pim_ifp->igmp_specific_query_max_response_time_dsec;
+ lmqt_msec = lmqc * lmqi_msec;
+
+ /*
+ RFC3376: 6.6.3.2. Building and Sending Group and Source Specific Queries
+
+ (...) for each of the sources in X of group G, with source timer larger
+ than LMQT:
+ o Set number of retransmissions for each source to [Last Member
+ Query Count].
+ o Lower source timer to LMQT.
+ */
+ for (ALL_LIST_ELEMENTS_RO(group->group_source_list, src_node, src)) {
+ if (IGMP_SOURCE_TEST_SEND(src->source_flags)) {
+ /* source "src" in X of group G */
+ if (igmp_source_timer_remain_msec(src) > lmqt_msec) {
+ src->source_query_retransmit_count = lmqc;
+ igmp_source_timer_lower_to_lmqt(src);
+ }
+ }
+ }
+
+ /* send group-and-source specific queries */
+ group_retransmit_sources(group, 1 /* send_with_sflag_set=true */);
+
+ /* make sure group retransmit timer is running */
+ group_retransmit_timer_on(group);
+}
+
+static void block_excl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ int num_sources_tosend = 0;
+ int i;
+
+ /* 1. clear off SEND flag from all known sources (X,Y) */
+ source_clear_send_flag(group->group_source_list);
+
+ /* 2. scan received sources (A) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* lookup reported source (A) in known sources (X,Y) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (!source) {
+ /* 3: if not found, create source with Group Timer: (A-X-Y)=Group Timer */
+ long group_timer_msec;
+ source = source_new(group, *src_addr,
+ group->group_igmp_sock->interface->name);
+ if (!source) {
+ /* ugh, internal malloc failure, skip source */
+ continue;
+ }
+
+ zassert(!source->t_source_timer); /* timer == 0 */
+ group_timer_msec = igmp_group_timer_remain_msec(group);
+ igmp_source_timer_on(group, source, group_timer_msec);
+ zassert(source->t_source_timer); /* (A-X-Y) timer > 0 */
+ }
+
+ if (source->t_source_timer) {
+ /* 4. if source timer>0 mark SEND flag: Q(G,A-Y) */
+ IGMP_SOURCE_DO_SEND(source->source_flags);
+ ++num_sources_tosend;
+ }
+ }
+
+ /* 5. send sources marked with SEND flag: Q(G,A-Y) */
+ if (num_sources_tosend > 0) {
+ source_query_send_by_flag(group, num_sources_tosend);
+ }
+}
+
+static void block_incl(struct igmp_group *group,
+ int num_sources, struct in_addr *sources)
+{
+ int num_sources_tosend = 0;
+ int i;
+
+ /* 1. clear off SEND flag from all known sources (B) */
+ source_clear_send_flag(group->group_source_list);
+
+ /* 2. scan received sources (A) */
+ for (i = 0; i < num_sources; ++i) {
+ struct igmp_source *source;
+ struct in_addr *src_addr;
+
+ src_addr = sources + i;
+
+ /* lookup reported source (A) in known sources (B) */
+ source = igmp_find_source_by_addr(group, *src_addr);
+ if (source) {
+ /* 3. if found (A*B), mark SEND flag: Q(G,A*B) */
+ IGMP_SOURCE_DO_SEND(source->source_flags);
+ ++num_sources_tosend;
+ }
+ }
+
+ /* 4. send sources marked with SEND flag: Q(G,A*B) */
+ if (num_sources_tosend > 0) {
+ source_query_send_by_flag(group, num_sources_tosend);
+ }
+}
+
+void igmpv3_report_block(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources)
+{
+ struct interface *ifp = igmp->interface;
+ struct pim_interface *pim_ifp;
+ struct igmp_group *group;
+
+ on_trace(__PRETTY_FUNCTION__,
+ ifp, from, group_addr, num_sources, sources);
+
+ pim_ifp = ifp->info;
+
+ /* non-existant group is created as INCLUDE {empty} */
+ group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
+ if (!group) {
+ return;
+ }
+
+ if (group->group_filtermode_isexcl) {
+ /* EXCLUDE mode */
+ block_excl(group, num_sources, sources);
+ }
+ else {
+ /* INCLUDE mode */
+ block_incl(group, num_sources, sources);
+ }
+}
+
+void igmp_group_timer_lower_to_lmqt(struct igmp_group *group)
+{
+ struct igmp_sock *igmp;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ char *ifname;
+ int lmqi_dsec; /* Last Member Query Interval */
+ int lmqc; /* Last Member Query Count */
+ int lmqt_msec; /* Last Member Query Time */
+
+ /*
+ RFC 3376: 6.2.2. Definition of Group Timers
+
+ The group timer is only used when a group is in EXCLUDE mode and
+ it represents the time for the *filter-mode* of the group to
+ expire and switch to INCLUDE mode.
+ */
+ if (!group->group_filtermode_isexcl) {
+ return;
+ }
+
+ igmp = group->group_igmp_sock;
+ ifp = igmp->interface;
+ pim_ifp = ifp->info;
+ ifname = ifp->name;
+
+ lmqi_dsec = pim_ifp->igmp_specific_query_max_response_time_dsec;
+ lmqc = igmp->querier_robustness_variable;
+ lmqt_msec = PIM_IGMP_LMQT_MSEC(lmqi_dsec, lmqc); /* lmqt_msec = (100 * lmqi_dsec) * lmqc */
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: group %s on %s: LMQC=%d LMQI=%d dsec LMQT=%d msec",
+ __PRETTY_FUNCTION__,
+ group_str, ifname,
+ lmqc, lmqi_dsec, lmqt_msec);
+ }
+
+ zassert(group->group_filtermode_isexcl);
+
+ igmp_group_timer_on(group, lmqt_msec, ifname);
+}
+
+void igmp_source_timer_lower_to_lmqt(struct igmp_source *source)
+{
+ struct igmp_group *group;
+ struct igmp_sock *igmp;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ char *ifname;
+ int lmqi_dsec; /* Last Member Query Interval */
+ int lmqc; /* Last Member Query Count */
+ int lmqt_msec; /* Last Member Query Time */
+
+ group = source->source_group;
+ igmp = group->group_igmp_sock;
+ ifp = igmp->interface;
+ pim_ifp = ifp->info;
+ ifname = ifp->name;
+
+ lmqi_dsec = pim_ifp->igmp_specific_query_max_response_time_dsec;
+ lmqc = igmp->querier_robustness_variable;
+ lmqt_msec = PIM_IGMP_LMQT_MSEC(lmqi_dsec, lmqc); /* lmqt_msec = (100 * lmqi_dsec) * lmqc */
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_debug("%s: group %s source %s on %s: LMQC=%d LMQI=%d dsec LMQT=%d msec",
+ __PRETTY_FUNCTION__,
+ group_str, source_str, ifname,
+ lmqc, lmqi_dsec, lmqt_msec);
+ }
+
+ igmp_source_timer_on(group, source, lmqt_msec);
+}
+
+/*
+ Copy sources to message:
+
+ struct in_addr *sources = (struct in_addr *)(query_buf + IGMP_V3_SOURCES_OFFSET);
+ if (num_sources > 0) {
+ struct listnode *node;
+ struct igmp_source *src;
+ int i = 0;
+
+ for (ALL_LIST_ELEMENTS_RO(source_list, node, src)) {
+ sources[i++] = src->source_addr;
+ }
+ }
+*/
+void pim_igmp_send_membership_query(struct igmp_group *group,
+ int fd,
+ const char *ifname,
+ char *query_buf,
+ int query_buf_size,
+ int num_sources,
+ struct in_addr dst_addr,
+ struct in_addr group_addr,
+ int query_max_response_time_dsec,
+ uint8_t s_flag,
+ uint8_t querier_robustness_variable,
+ uint16_t querier_query_interval)
+{
+ ssize_t msg_size;
+ uint8_t max_resp_code;
+ uint8_t qqic;
+ ssize_t sent;
+ struct sockaddr_in to;
+ socklen_t tolen;
+ uint16_t checksum;
+
+ zassert(num_sources >= 0);
+
+ msg_size = IGMP_V3_SOURCES_OFFSET + (num_sources << 2);
+ if (msg_size > query_buf_size) {
+ zlog_err("%s %s: unable to send: msg_size=%d larger than query_buf_size=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ msg_size, query_buf_size);
+ return;
+ }
+
+ s_flag = PIM_FORCE_BOOLEAN(s_flag);
+ zassert((s_flag == 0) || (s_flag == 1));
+
+ max_resp_code = igmp_msg_encode16to8(query_max_response_time_dsec);
+ qqic = igmp_msg_encode16to8(querier_query_interval);
+
+ /*
+ RFC 3376: 4.1.6. QRV (Querier's Robustness Variable)
+
+ If non-zero, the QRV field contains the [Robustness Variable]
+ value used by the querier, i.e., the sender of the Query. If the
+ querier's [Robustness Variable] exceeds 7, the maximum value of
+ the QRV field, the QRV is set to zero.
+ */
+ if (querier_robustness_variable > 7) {
+ querier_robustness_variable = 0;
+ }
+
+ query_buf[0] = PIM_IGMP_MEMBERSHIP_QUERY;
+ query_buf[1] = max_resp_code;
+ *(uint16_t *)(query_buf + IGMP_V3_CHECKSUM_OFFSET) = 0; /* for computing checksum */
+ *(struct in_addr *)(query_buf + 4) = group_addr;
+ query_buf[8] = (s_flag << 3) | querier_robustness_variable;
+ query_buf[9] = qqic;
+ *(uint16_t *)(query_buf + IGMP_V3_NUMSOURCES_OFFSET) = htons(num_sources);
+
+ checksum = pim_inet_checksum(query_buf, msg_size);
+ *(uint16_t *)(query_buf + IGMP_V3_CHECKSUM_OFFSET) = checksum;
+
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ char dst_str[100];
+ char group_str[100];
+ pim_inet4_dump("<dst?>", dst_addr, dst_str, sizeof(dst_str));
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: to %s on %s: group=%s sources=%d msg_size=%d s_flag=%x QRV=%u QQI=%u QQIC=%02x checksum=%x",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, group_str, num_sources,
+ msg_size, s_flag, querier_robustness_variable,
+ querier_query_interval, qqic, checksum);
+ }
+
+#if 0
+ memset(&to, 0, sizeof(to));
+#endif
+ to.sin_family = AF_INET;
+ to.sin_addr = dst_addr;
+#if 0
+ to.sin_port = htons(0);
+#endif
+ tolen = sizeof(to);
+
+ sent = sendto(fd, query_buf, msg_size, MSG_DONTWAIT, &to, tolen);
+ if (sent != (ssize_t) msg_size) {
+ int e = errno;
+ char dst_str[100];
+ char group_str[100];
+ pim_inet4_dump("<dst?>", dst_addr, dst_str, sizeof(dst_str));
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+ if (sent < 0) {
+ zlog_warn("%s: sendto() failure to %s on %s: group=%s msg_size=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, group_str, msg_size,
+ e, safe_strerror(e));
+ }
+ else {
+ zlog_warn("%s: sendto() partial to %s on %s: group=%s msg_size=%d: sent=%d",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, group_str,
+ msg_size, sent);
+ }
+ return;
+ }
+
+ /*
+ s_flag sanity test: s_flag must be set for general queries
+
+ RFC 3376: 6.6.1. Timer Updates
+
+ When a router sends or receives a query with a clear Suppress
+ Router-Side Processing flag, it must update its timers to reflect
+ the correct timeout values for the group or sources being queried.
+
+ General queries don't trigger timer update.
+ */
+ if (!s_flag) {
+ /* general query? */
+ if (PIM_INADDR_IS_ANY(group_addr)) {
+ char dst_str[100];
+ char group_str[100];
+ pim_inet4_dump("<dst?>", dst_addr, dst_str, sizeof(dst_str));
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: to %s on %s: group=%s sources=%d: s_flag is clear for general query!",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, group_str, num_sources);
+ }
+ }
+
+}
diff --git a/pimd/pim_igmpv3.h b/pimd/pim_igmpv3.h
new file mode 100644
index 00000000..bb7e9267
--- /dev/null
+++ b/pimd/pim_igmpv3.h
@@ -0,0 +1,100 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_IGMPV3_H
+#define PIM_IGMPV3_H
+
+#include <zebra.h>
+#include "if.h"
+
+#define IGMP_V3_CHECKSUM_OFFSET (2)
+#define IGMP_V3_REPORT_NUMGROUPS_OFFSET (6)
+#define IGMP_V3_REPORT_GROUPPRECORD_OFFSET (8)
+#define IGMP_V3_NUMSOURCES_OFFSET (10)
+#define IGMP_V3_SOURCES_OFFSET (12)
+
+/* GMI: Group Membership Interval */
+#define PIM_IGMP_GMI_MSEC(qrv,qqi,qri_dsec) ((qrv) * (1000 * (qqi)) + 100 * (qri_dsec))
+
+/* OQPI: Other Querier Present Interval */
+#define PIM_IGMP_OQPI_MSEC(qrv,qqi,qri_dsec) ((qrv) * (1000 * (qqi)) + 100 * ((qri_dsec) >> 1))
+
+/* SQI: Startup Query Interval */
+#define PIM_IGMP_SQI(qi) (((qi) < 4) ? 1 : ((qi) >> 2))
+
+/* LMQT: Last Member Query Time */
+#define PIM_IGMP_LMQT_MSEC(lmqi_dsec, lmqc) ((lmqc) * (100 * (lmqi_dsec)))
+
+/* OHPI: Older Host Present Interval */
+#define PIM_IGMP_OHPI_DSEC(qrv,qqi,qri_dsec) ((qrv) * (10 * (qqi)) + (qri_dsec))
+
+void igmp_group_reset_gmi(struct igmp_group *group);
+void igmp_source_reset_gmi(struct igmp_sock *igmp,
+ struct igmp_group *group,
+ struct igmp_source *source);
+
+void igmp_source_free(struct igmp_source *source);
+void igmp_source_delete(struct igmp_source *source);
+void igmp_source_delete_expired(struct list *source_list);
+
+int igmp_group_compat_mode(const struct igmp_sock *igmp,
+ const struct igmp_group *group);
+
+void igmpv3_report_isin(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources);
+void igmpv3_report_isex(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources);
+void igmpv3_report_toin(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources);
+void igmpv3_report_toex(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources);
+void igmpv3_report_allow(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources);
+void igmpv3_report_block(struct igmp_sock *igmp, struct in_addr from,
+ struct in_addr group_addr,
+ int num_sources, struct in_addr *sources);
+
+void igmp_group_timer_lower_to_lmqt(struct igmp_group *group);
+void igmp_source_timer_lower_to_lmqt(struct igmp_source *source);
+
+struct igmp_source *igmp_find_source_by_addr(struct igmp_group *group,
+ struct in_addr src_addr);
+
+void pim_igmp_send_membership_query(struct igmp_group *group,
+ int fd,
+ const char *ifname,
+ char *query_buf,
+ int query_buf_size,
+ int num_sources,
+ struct in_addr dst_addr,
+ struct in_addr group_addr,
+ int query_max_response_time_dsec,
+ uint8_t s_flag,
+ uint8_t querier_robustness_variable,
+ uint16_t querier_query_interval);
+
+#endif /* PIM_IGMPV3_H */
diff --git a/pimd/pim_int.c b/pimd/pim_int.c
new file mode 100644
index 00000000..2ff1a116
--- /dev/null
+++ b/pimd/pim_int.c
@@ -0,0 +1,44 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <string.h>
+#include <netinet/in.h>
+
+#include "pim_int.h"
+
+uint32_t pim_read_uint32_host(const uint8_t *buf)
+{
+ uint32_t val;
+ memcpy(&val, buf, sizeof(val));
+ /* val is in netorder */
+ val = ntohl(val);
+ /* val is in hostorder */
+ return val;
+}
+
+void pim_write_uint32(uint8_t *buf, uint32_t val_host)
+{
+ /* val_host is in host order */
+ val_host = htonl(val_host);
+ /* val_host is in netorder */
+ memcpy(buf, &val_host, sizeof(val_host));
+}
diff --git a/pimd/pim_int.h b/pimd/pim_int.h
new file mode 100644
index 00000000..d64b1032
--- /dev/null
+++ b/pimd/pim_int.h
@@ -0,0 +1,31 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_INT_H
+#define PIM_INT_H
+
+#include <stdint.h>
+
+uint32_t pim_read_uint32_host(const uint8_t *buf);
+void pim_write_uint32(uint8_t *buf, uint32_t val_host);
+
+#endif /* PIM_INT_H */
diff --git a/pimd/pim_join.c b/pimd/pim_join.c
new file mode 100644
index 00000000..aa3aa789
--- /dev/null
+++ b/pimd/pim_join.c
@@ -0,0 +1,430 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "prefix.h"
+
+#include "pimd.h"
+#include "pim_str.h"
+#include "pim_tlv.h"
+#include "pim_msg.h"
+#include "pim_pim.h"
+#include "pim_join.h"
+#include "pim_iface.h"
+#include "pim_hello.h"
+#include "pim_ifchannel.h"
+
+static void on_trace(const char *label,
+ struct interface *ifp, struct in_addr src)
+{
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src, src_str, sizeof(src_str));
+ zlog_debug("%s: from %s on %s",
+ label, src_str, ifp->name);
+ }
+}
+
+static void recv_join(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ uint16_t holdtime,
+ struct in_addr upstream,
+ struct in_addr group,
+ struct in_addr source,
+ uint8_t source_flags)
+{
+ if (PIM_DEBUG_PIM_TRACE) {
+ char up_str[100];
+ char src_str[100];
+ char grp_str[100];
+ char neigh_str[100];
+ pim_inet4_dump("<upstream?>", upstream, up_str, sizeof(up_str));
+ pim_inet4_dump("<src?>", source, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<neigh?>", neigh->source_addr, neigh_str, sizeof(neigh_str));
+ zlog_warn("%s: join (S,G)=(%s,%s) rpt=%d wc=%d upstream=%s holdtime=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ source_flags & PIM_RPT_BIT_MASK,
+ source_flags & PIM_WILDCARD_BIT_MASK,
+ up_str, holdtime, neigh_str, ifp->name);
+ }
+
+ /* Restart join expiry timer */
+ pim_ifchannel_join_add(ifp, neigh->source_addr, upstream,
+ source, group, source_flags, holdtime);
+}
+
+static void recv_prune(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ uint16_t holdtime,
+ struct in_addr upstream,
+ struct in_addr group,
+ struct in_addr source,
+ uint8_t source_flags)
+{
+ if (PIM_DEBUG_PIM_TRACE) {
+ char up_str[100];
+ char src_str[100];
+ char grp_str[100];
+ char neigh_str[100];
+ pim_inet4_dump("<upstream?>", upstream, up_str, sizeof(up_str));
+ pim_inet4_dump("<src?>", source, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", group, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<neigh?>", neigh->source_addr, neigh_str, sizeof(neigh_str));
+ zlog_warn("%s: prune (S,G)=(%s,%s) rpt=%d wc=%d upstream=%s holdtime=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ source_flags & PIM_RPT_BIT_MASK,
+ source_flags & PIM_WILDCARD_BIT_MASK,
+ up_str, holdtime, neigh_str, ifp->name);
+ }
+
+ pim_ifchannel_prune(ifp, upstream, source, group, source_flags, holdtime);
+}
+
+int pim_joinprune_recv(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ struct in_addr src_addr,
+ char *tlv_buf, int tlv_buf_size)
+{
+ struct prefix msg_upstream_addr;
+ uint8_t msg_num_groups;
+ uint16_t msg_holdtime;
+ int addr_offset;
+ char *buf;
+ char *pastend;
+ int remain;
+ int group;
+
+ on_trace(__PRETTY_FUNCTION__, ifp, src_addr);
+
+ buf = tlv_buf;
+ pastend = tlv_buf + tlv_buf_size;
+
+ /*
+ Parse ucast addr
+ */
+ addr_offset = pim_parse_addr_ucast(ifp->name, src_addr,
+ &msg_upstream_addr,
+ buf, pastend - buf);
+ if (addr_offset < 1) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ return -1;
+ }
+ buf += addr_offset;
+
+ /*
+ Check upstream address family
+ */
+ if (msg_upstream_addr.family != AF_INET) {
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: ignoring join/prune directed to unexpected addr family=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ msg_upstream_addr.family, src_str, ifp->name);
+ }
+ return -2;
+ }
+
+ remain = pastend - buf;
+ if (remain < 4) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: short join/prune message buffer for group list: size=%d minimum=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ remain, 4, src_str, ifp->name);
+ return -4;
+ }
+
+ ++buf; /* skip reserved byte */
+ msg_num_groups = *(const uint8_t *) buf;
+ ++buf;
+ msg_holdtime = ntohs(*(const uint16_t *) buf);
+ ++buf;
+ ++buf;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char upstream_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<addr?>", msg_upstream_addr.u.prefix4,
+ upstream_str, sizeof(upstream_str));
+ zlog_warn("%s: join/prune upstream=%s groups=%d holdtime=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ upstream_str, msg_num_groups, msg_holdtime,
+ src_str, ifp->name);
+ }
+
+ /* Scan groups */
+ for (group = 0; group < msg_num_groups; ++group) {
+ struct prefix msg_group_addr;
+ struct prefix msg_source_addr;
+ uint8_t msg_source_flags;
+ uint16_t msg_num_joined_sources;
+ uint16_t msg_num_pruned_sources;
+ int source;
+
+ addr_offset = pim_parse_addr_group(ifp->name, src_addr,
+ &msg_group_addr,
+ buf, pastend - buf);
+ if (addr_offset < 1) {
+ return -5;
+ }
+ buf += addr_offset;
+
+ remain = pastend - buf;
+ if (remain < 4) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: short join/prune buffer for source list: size=%d minimum=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ remain, 4, src_str, ifp->name);
+ return -6;
+ }
+
+ msg_num_joined_sources = ntohs(*(const uint16_t *) buf);
+ buf += 2;
+ msg_num_pruned_sources = ntohs(*(const uint16_t *) buf);
+ buf += 2;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char upstream_str[100];
+ char group_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<addr?>", msg_upstream_addr.u.prefix4,
+ upstream_str, sizeof(upstream_str));
+ pim_inet4_dump("<grp?>", msg_group_addr.u.prefix4,
+ group_str, sizeof(group_str));
+ zlog_warn("%s: join/prune upstream=%s group=%s/%d join_src=%d prune_src=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ upstream_str, group_str, msg_group_addr.prefixlen,
+ msg_num_joined_sources, msg_num_pruned_sources,
+ src_str, ifp->name);
+ }
+
+ /* Scan joined sources */
+ for (source = 0; source < msg_num_joined_sources; ++source) {
+ addr_offset = pim_parse_addr_source(ifp->name, src_addr,
+ &msg_source_addr,
+ &msg_source_flags,
+ buf, pastend - buf);
+ if (addr_offset < 1) {
+ return -7;
+ }
+
+ buf += addr_offset;
+
+ recv_join(ifp, neigh, msg_holdtime,
+ msg_upstream_addr.u.prefix4,
+ msg_group_addr.u.prefix4,
+ msg_source_addr.u.prefix4,
+ msg_source_flags);
+ }
+
+ /* Scan pruned sources */
+ for (source = 0; source < msg_num_pruned_sources; ++source) {
+ addr_offset = pim_parse_addr_source(ifp->name, src_addr,
+ &msg_source_addr,
+ &msg_source_flags,
+ buf, pastend - buf);
+ if (addr_offset < 1) {
+ return -8;
+ }
+
+ buf += addr_offset;
+
+ recv_prune(ifp, neigh, msg_holdtime,
+ msg_upstream_addr.u.prefix4,
+ msg_group_addr.u.prefix4,
+ msg_source_addr.u.prefix4,
+ msg_source_flags);
+ }
+
+ } /* scan groups */
+
+ return 0;
+}
+
+int pim_joinprune_send(struct interface *ifp,
+ struct in_addr upstream_addr,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ int send_join)
+{
+ struct pim_interface *pim_ifp;
+ char pim_msg[1000];
+ const char *pastend = pim_msg + sizeof(pim_msg);
+ char *pim_msg_curr = pim_msg + PIM_MSG_HEADER_LEN; /* room for pim header */
+ int pim_msg_size;
+ int remain;
+
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+
+ if (!pim_ifp) {
+ zlog_warn("%s: multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ return -1;
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ char dst_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<dst?>", upstream_addr, dst_str, sizeof(dst_str));
+ zlog_debug("%s: sending %s(S,G)=(%s,%s) to upstream=%s on interface %s",
+ __PRETTY_FUNCTION__,
+ send_join ? "Join" : "Prune",
+ source_str, group_str, dst_str, ifp->name);
+ }
+
+ if (PIM_INADDR_IS_ANY(upstream_addr)) {
+ if (PIM_DEBUG_PIM_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ char dst_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<dst?>", upstream_addr, dst_str, sizeof(dst_str));
+ zlog_debug("%s: %s(S,G)=(%s,%s): upstream=%s is myself on interface %s",
+ __PRETTY_FUNCTION__,
+ send_join ? "Join" : "Prune",
+ source_str, group_str, dst_str, ifp->name);
+ }
+ return 0;
+ }
+
+ /*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Thus, if a router needs to send a Join/Prune or Assert message on
+ an interface on which it has not yet sent a Hello message with the
+ currently configured IP address, then it MUST immediately send the
+ relevant Hello message without waiting for the Hello Timer to
+ expire, followed by the Join/Prune or Assert message.
+ */
+ pim_hello_require(ifp);
+
+ /*
+ Build PIM message
+ */
+
+ remain = pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_ucast(pim_msg_curr,
+ remain,
+ upstream_addr);
+ if (!pim_msg_curr) {
+ char dst_str[100];
+ pim_inet4_dump("<dst?>", upstream_addr, dst_str, sizeof(dst_str));
+ zlog_warn("%s: failure encoding destination address %s: space left=%d",
+ __PRETTY_FUNCTION__, dst_str, remain);
+ return -3;
+ }
+
+ remain = pastend - pim_msg_curr;
+ if (remain < 4) {
+ zlog_warn("%s: group will not fit: space left=%d",
+ __PRETTY_FUNCTION__, remain);
+ return -4;
+ }
+
+ *pim_msg_curr = 0; /* reserved */
+ ++pim_msg_curr;
+ *pim_msg_curr = 1; /* number of groups */
+ ++pim_msg_curr;
+ *((uint16_t *) pim_msg_curr) = htons(PIM_JP_HOLDTIME);
+ ++pim_msg_curr;
+ ++pim_msg_curr;
+
+ remain = pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_group(pim_msg_curr,
+ remain,
+ group_addr);
+ if (!pim_msg_curr) {
+ char group_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: failure encoding group address %s: space left=%d",
+ __PRETTY_FUNCTION__, group_str, remain);
+ return -5;
+ }
+
+ remain = pastend - pim_msg_curr;
+ if (remain < 4) {
+ zlog_warn("%s: sources will not fit: space left=%d",
+ __PRETTY_FUNCTION__, remain);
+ return -6;
+ }
+
+ /* number of joined sources */
+ *((uint16_t *) pim_msg_curr) = htons(send_join ? 1 : 0);
+ ++pim_msg_curr;
+ ++pim_msg_curr;
+
+ /* number of pruned sources */
+ *((uint16_t *) pim_msg_curr) = htons(send_join ? 0 : 1);
+ ++pim_msg_curr;
+ ++pim_msg_curr;
+
+ remain = pastend - pim_msg_curr;
+ pim_msg_curr = pim_msg_addr_encode_ipv4_source(pim_msg_curr,
+ remain,
+ source_addr);
+ if (!pim_msg_curr) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: failure encoding source address %s: space left=%d",
+ __PRETTY_FUNCTION__, source_str, remain);
+ return -7;
+ }
+
+ /* Add PIM header */
+
+ pim_msg_size = pim_msg_curr - pim_msg;
+
+ pim_msg_build_header(pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_JOIN_PRUNE);
+
+ if (pim_msg_send(pim_ifp->pim_sock_fd,
+ qpim_all_pim_routers_addr,
+ pim_msg,
+ pim_msg_size,
+ ifp->name)) {
+ zlog_warn("%s: could not send PIM message on interface %s",
+ __PRETTY_FUNCTION__, ifp->name);
+ return -8;
+ }
+
+ return 0;
+}
diff --git a/pimd/pim_join.h b/pimd/pim_join.h
new file mode 100644
index 00000000..4d9407be
--- /dev/null
+++ b/pimd/pim_join.h
@@ -0,0 +1,43 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_JOIN_H
+#define PIM_JOIN_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+#include "pim_neighbor.h"
+
+int pim_joinprune_recv(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ struct in_addr src_addr,
+ char *tlv_buf, int tlv_buf_size);
+
+int pim_joinprune_send(struct interface *ifp,
+ struct in_addr upstream_addr,
+ struct in_addr source_addr,
+ struct in_addr group_addr,
+ int send_join);
+
+#endif /* PIM_JOIN_H */
diff --git a/pimd/pim_macro.c b/pimd/pim_macro.c
new file mode 100644
index 00000000..3f565325
--- /dev/null
+++ b/pimd/pim_macro.c
@@ -0,0 +1,437 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+
+#include "pim_macro.h"
+#include "pimd.h"
+#include "pim_str.h"
+#include "pim_iface.h"
+#include "pim_ifchannel.h"
+
+#define PIM_IFP_I_am_DR(pim_ifp) ((pim_ifp)->pim_dr_addr.s_addr == (pim_ifp)->primary_address.s_addr)
+
+/*
+ DownstreamJPState(S,G,I) is the per-interface state machine for
+ receiving (S,G) Join/Prune messages.
+
+ DownstreamJPState(S,G,I) is either Join or Prune-Pending ?
+*/
+static int downstream_jpstate_isjoined(const struct pim_ifchannel *ch)
+{
+ return ch->ifjoin_state != PIM_IFJOIN_NOINFO;
+}
+
+/*
+ The clause "local_receiver_include(S,G,I)" is true if the IGMP/MLD
+ module or other local membership mechanism has determined that local
+ members on interface I desire to receive traffic sent specifically
+ by S to G.
+*/
+static int local_receiver_include(const struct pim_ifchannel *ch)
+{
+ /* local_receiver_include(S,G,I) ? */
+ return ch->local_ifmembership == PIM_IFMEMBERSHIP_INCLUDE;
+}
+
+/*
+ RFC 4601: 4.1.6. State Summarization Macros
+
+ The set "joins(S,G)" is the set of all interfaces on which the
+ router has received (S,G) Joins:
+
+ joins(S,G) =
+ { all interfaces I such that
+ DownstreamJPState(S,G,I) is either Join or Prune-Pending }
+
+ DownstreamJPState(S,G,I) is either Join or Prune-Pending ?
+*/
+int pim_macro_chisin_joins(const struct pim_ifchannel *ch)
+{
+ return downstream_jpstate_isjoined(ch);
+}
+
+/*
+ RFC 4601: 4.6.5. Assert State Macros
+
+ The set "lost_assert(S,G)" is the set of all interfaces on which the
+ router has received (S,G) joins but has lost an (S,G) assert.
+
+ lost_assert(S,G) =
+ { all interfaces I such that
+ lost_assert(S,G,I) == TRUE }
+
+ bool lost_assert(S,G,I) {
+ if ( RPF_interface(S) == I ) {
+ return FALSE
+ } else {
+ return ( AssertWinner(S,G,I) != NULL AND
+ AssertWinner(S,G,I) != me AND
+ (AssertWinnerMetric(S,G,I) is better
+ than spt_assert_metric(S,I) )
+ }
+ }
+
+ AssertWinner(S,G,I) is the IP source address of the Assert(S,G)
+ packet that won an Assert.
+*/
+int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_assert_metric spt_assert_metric;
+
+ ifp = ch->interface;
+ if (!ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): null interface",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str);
+ return 0; /* false */
+ }
+
+ /* RPF_interface(S) == I ? */
+ if (ch->upstream->rpf.source_nexthop.interface == ifp)
+ return 0; /* false */
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return 0; /* false */
+ }
+
+ if (PIM_INADDR_IS_ANY(ch->ifassert_winner))
+ return 0; /* false */
+
+ /* AssertWinner(S,G,I) == me ? */
+ if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr)
+ return 0; /* false */
+
+ spt_assert_metric = pim_macro_spt_assert_metric(&ch->upstream->rpf,
+ pim_ifp->primary_address);
+
+ return pim_assert_metric_better(&ch->ifassert_winner_metric,
+ &spt_assert_metric);
+}
+
+/*
+ RFC 4601: 4.1.6. State Summarization Macros
+
+ pim_include(S,G) =
+ { all interfaces I such that:
+ ( (I_am_DR( I ) AND lost_assert(S,G,I) == FALSE )
+ OR AssertWinner(S,G,I) == me )
+ AND local_receiver_include(S,G,I) }
+
+ AssertWinner(S,G,I) is the IP source address of the Assert(S,G)
+ packet that won an Assert.
+*/
+int pim_macro_chisin_pim_include(const struct pim_ifchannel *ch)
+{
+ struct pim_interface *pim_ifp = ch->interface->info;
+
+ if (!pim_ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name);
+ return 0; /* false */
+ }
+
+ /* local_receiver_include(S,G,I) ? */
+ if (!local_receiver_include(ch))
+ return 0; /* false */
+
+ /* OR AssertWinner(S,G,I) == me ? */
+ if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr)
+ return 1; /* true */
+
+ return (
+ /* I_am_DR( I ) ? */
+ PIM_IFP_I_am_DR(pim_ifp)
+ &&
+ /* lost_assert(S,G,I) == FALSE ? */
+ (!pim_macro_ch_lost_assert(ch))
+ );
+}
+
+int pim_macro_chisin_joins_or_include(const struct pim_ifchannel *ch)
+{
+ if (pim_macro_chisin_joins(ch))
+ return 1; /* true */
+
+ return pim_macro_chisin_pim_include(ch);
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ CouldAssert(S,G,I) =
+ SPTbit(S,G)==TRUE
+ AND (RPF_interface(S) != I)
+ AND (I in ( ( joins(*,*,RP(G)) (+) joins(*,G) (-) prunes(S,G,rpt) )
+ (+) ( pim_include(*,G) (-) pim_exclude(S,G) )
+ (-) lost_assert(*,G)
+ (+) joins(S,G) (+) pim_include(S,G) ) )
+
+ CouldAssert(S,G,I) is true for downstream interfaces that would be in
+ the inherited_olist(S,G) if (S,G) assert information was not taken
+ into account.
+
+ CouldAssert(S,G,I) may be affected by changes in the following:
+
+ pim_ifp->primary_address
+ pim_ifp->pim_dr_addr
+ ch->ifassert_winner_metric
+ ch->ifassert_winner
+ ch->local_ifmembership
+ ch->ifjoin_state
+ ch->upstream->rpf.source_nexthop.mrib_metric_preference
+ ch->upstream->rpf.source_nexthop.mrib_route_metric
+ ch->upstream->rpf.source_nexthop.interface
+*/
+int pim_macro_ch_could_assert_eval(const struct pim_ifchannel *ch)
+{
+ struct interface *ifp;
+
+ /* SPTbit(S,G) is always true for PIM-SSM-Only Routers */
+
+ ifp = ch->interface;
+ if (!ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): null interface",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str);
+ return 0; /* false */
+ }
+
+ /* RPF_interface(S) != I ? */
+ if (ch->upstream->rpf.source_nexthop.interface == ifp)
+ return 0; /* false */
+
+ /* I in joins(S,G) (+) pim_include(S,G) ? */
+ return pim_macro_chisin_joins_or_include(ch);
+}
+
+/*
+ RFC 4601: 4.6.3. Assert Metrics
+
+ spt_assert_metric(S,I) gives the assert metric we use if we're
+ sending an assert based on active (S,G) forwarding state:
+
+ assert_metric
+ spt_assert_metric(S,I) {
+ return {0,MRIB.pref(S),MRIB.metric(S),my_ip_address(I)}
+ }
+*/
+struct pim_assert_metric pim_macro_spt_assert_metric(const struct pim_rpf *rpf,
+ struct in_addr ifaddr)
+{
+ struct pim_assert_metric metric;
+
+ metric.rpt_bit_flag = 0;
+ metric.metric_preference = rpf->source_nexthop.mrib_metric_preference;
+ metric.route_metric = rpf->source_nexthop.mrib_route_metric;
+ metric.ip_address = ifaddr;
+
+ return metric;
+}
+
+/*
+ RFC 4601: 4.6.3. Assert Metrics
+
+ An assert metric for (S,G) to include in (or compare against) an
+ Assert message sent on interface I should be computed using the
+ following pseudocode:
+
+ assert_metric my_assert_metric(S,G,I) {
+ if( CouldAssert(S,G,I) == TRUE ) {
+ return spt_assert_metric(S,I)
+ } else if( CouldAssert(*,G,I) == TRUE ) {
+ return rpt_assert_metric(G,I)
+ } else {
+ return infinite_assert_metric()
+ }
+ }
+*/
+struct pim_assert_metric pim_macro_ch_my_assert_metric_eval(const struct pim_ifchannel *ch)
+{
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ch->interface->info;
+
+ if (pim_ifp) {
+ if (PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags)) {
+ return pim_macro_spt_assert_metric(&ch->upstream->rpf, pim_ifp->primary_address);
+ }
+ }
+
+ return qpim_infinite_assert_metric;
+}
+
+/*
+ RFC 4601 4.2. Data Packet Forwarding Rules
+ RFC 4601 4.8.2. PIM-SSM-Only Routers
+
+ Macro:
+ inherited_olist(S,G) =
+ joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
+*/
+static int pim_macro_chisin_inherited_olist(const struct pim_ifchannel *ch)
+{
+ if (pim_macro_ch_lost_assert(ch))
+ return 0; /* false */
+
+ return pim_macro_chisin_joins_or_include(ch);
+}
+
+/*
+ RFC 4601 4.2. Data Packet Forwarding Rules
+ RFC 4601 4.8.2. PIM-SSM-Only Routers
+
+ Additionally, the Packet forwarding rules of Section 4.2 can be
+ simplified in a PIM-SSM-only router:
+
+ iif is the incoming interface of the packet.
+ oiflist = NULL
+ if (iif == RPF_interface(S) AND UpstreamJPState(S,G) == Joined) {
+ oiflist = inherited_olist(S,G)
+ } else if (iif is in inherited_olist(S,G)) {
+ send Assert(S,G) on iif
+ }
+ oiflist = oiflist (-) iif
+ forward packet on all interfaces in oiflist
+
+ Macro:
+ inherited_olist(S,G) =
+ joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
+
+ Note:
+ - The following test is performed as response to WRONGVIF kernel
+ upcall:
+ if (iif is in inherited_olist(S,G)) {
+ send Assert(S,G) on iif
+ }
+ See pim_mroute.c mroute_msg().
+*/
+int pim_macro_chisin_oiflist(const struct pim_ifchannel *ch)
+{
+ if (ch->upstream->join_state != PIM_UPSTREAM_JOINED) {
+ /* oiflist is NULL */
+ return 0; /* false */
+ }
+
+ /* oiflist = oiflist (-) iif */
+ if (ch->interface == ch->upstream->rpf.source_nexthop.interface)
+ return 0; /* false */
+
+ return pim_macro_chisin_inherited_olist(ch);
+}
+
+/*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ AssertTrackingDesired(S,G,I) =
+ (I in ( ( joins(*,*,RP(G)) (+) joins(*,G) (-) prunes(S,G,rpt) )
+ (+) ( pim_include(*,G) (-) pim_exclude(S,G) )
+ (-) lost_assert(*,G)
+ (+) joins(S,G) ) )
+ OR (local_receiver_include(S,G,I) == TRUE
+ AND (I_am_DR(I) OR (AssertWinner(S,G,I) == me)))
+ OR ((RPF_interface(S) == I) AND (JoinDesired(S,G) == TRUE))
+ OR ((RPF_interface(RP(G)) == I) AND (JoinDesired(*,G) == TRUE)
+ AND (SPTbit(S,G) == FALSE))
+
+ AssertTrackingDesired(S,G,I) is true on any interface in which an
+ (S,G) assert might affect our behavior.
+*/
+int pim_macro_assert_tracking_desired_eval(const struct pim_ifchannel *ch)
+{
+ struct pim_interface *pim_ifp;
+ struct interface *ifp;
+
+ ifp = ch->interface;
+ if (!ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): null interface",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str);
+ return 0; /* false */
+ }
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ch->interface->name);
+ return 0; /* false */
+ }
+
+ /* I in joins(S,G) ? */
+ if (pim_macro_chisin_joins(ch))
+ return 1; /* true */
+
+ /* local_receiver_include(S,G,I) ? */
+ if (local_receiver_include(ch)) {
+ /* I_am_DR(I) ? */
+ if (PIM_IFP_I_am_DR(pim_ifp))
+ return 1; /* true */
+
+ /* AssertWinner(S,G,I) == me ? */
+ if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr)
+ return 1; /* true */
+ }
+
+ /* RPF_interface(S) == I ? */
+ if (ch->upstream->rpf.source_nexthop.interface == ifp) {
+ /* JoinDesired(S,G) ? */
+ if (PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(ch->upstream->flags))
+ return 1; /* true */
+ }
+
+ return 0; /* false */
+}
+
diff --git a/pimd/pim_macro.h b/pimd/pim_macro.h
new file mode 100644
index 00000000..472fa9b4
--- /dev/null
+++ b/pimd/pim_macro.h
@@ -0,0 +1,44 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_MACRO_H
+#define PIM_MACRO_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+#include "pim_upstream.h"
+#include "pim_ifchannel.h"
+
+int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch);
+int pim_macro_chisin_joins(const struct pim_ifchannel *ch);
+int pim_macro_chisin_pim_include(const struct pim_ifchannel *ch);
+int pim_macro_chisin_joins_or_include(const struct pim_ifchannel *ch);
+int pim_macro_ch_could_assert_eval(const struct pim_ifchannel *ch);
+struct pim_assert_metric pim_macro_spt_assert_metric(const struct pim_rpf *rpf,
+ struct in_addr ifaddr);
+struct pim_assert_metric pim_macro_ch_my_assert_metric_eval(const struct pim_ifchannel *ch);
+int pim_macro_chisin_oiflist(const struct pim_ifchannel *ch);
+int pim_macro_assert_tracking_desired_eval(const struct pim_ifchannel *ch);
+
+#endif /* PIM_MACRO_H */
diff --git a/pimd/pim_main.c b/pimd/pim_main.c
new file mode 100644
index 00000000..71749303
--- /dev/null
+++ b/pimd/pim_main.c
@@ -0,0 +1,298 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "privs.h"
+#include "version.h"
+#include <getopt.h>
+#include "command.h"
+#include "thread.h"
+#include <signal.h>
+
+#include "memory.h"
+#include "filter.h"
+#include "vty.h"
+#include "sigevent.h"
+#include "version.h"
+#include "paths.h"
+
+#include "pimd.h"
+#include "pim_version.h"
+#include "pim_signals.h"
+#include "pim_zebra.h"
+
+#ifdef PIM_ZCLIENT_DEBUG
+extern int zclient_debug;
+#endif
+
+extern struct host host;
+
+char config_default[MAXPATHLEN];
+
+struct option longopts[] = {
+ { "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
+ { "config_file", required_argument, NULL, 'f'},
+ { "pid_file", required_argument, NULL, 'i'},
+ { "vty_addr", required_argument, NULL, 'A'},
+ { "vty_port", required_argument, NULL, 'P'},
+ { "version", no_argument, NULL, 'v'},
+ { "debug_zclient", no_argument, NULL, 'Z'},
+ { "help", no_argument, NULL, 'h'},
+ { 0 }
+};
+
+/* pimd privileges */
+zebra_capabilities_t _caps_p [] =
+{
+ ZCAP_NET_ADMIN,
+ ZCAP_SYS_ADMIN,
+ ZCAP_NET_RAW,
+};
+
+/* pimd privileges to run with */
+struct zebra_privs_t pimd_privs =
+{
+#if defined(QUAGGA_USER) && defined(QUAGGA_GROUP)
+ .user = QUAGGA_USER,
+ .group = QUAGGA_GROUP,
+#endif
+#ifdef VTY_GROUP
+ .vty_group = VTY_GROUP,
+#endif
+ .caps_p = _caps_p,
+ .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
+ .cap_num_i = 0
+};
+
+char* progname;
+static char pid_file_default[MAXPATHLEN];
+const char *pid_file = pid_file_default;
+
+static void usage(int status)
+{
+ if (status != 0)
+ fprintf (stderr, "Try `%s --help' for more information.\n", progname);
+ else {
+ printf ("Usage : %s [OPTION...]\n\
+Daemon which manages PIM.\n\n\
+-d, --daemon Run in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
+-f, --config_file Set configuration file name\n\
+-i, --pid_file Set process identifier file name\n\
+-A, --vty_addr Set vty's bind address\n\
+-P, --vty_port Set vty's port number\n\
+-v, --version Print program version\n\
+"
+
+#ifdef PIM_ZCLIENT_DEBUG
+"\
+-Z, --debug_zclient Enable zclient debugging\n\
+"
+#endif
+
+"\
+-h, --help Display this help and exit\n\
+\n\
+Report bugs to %s\n", progname, PIMD_BUG_ADDRESS);
+ }
+
+ exit (status);
+}
+
+
+int main(int argc, char** argv, char** envp) {
+ char *p;
+ char *vty_addr = NULL;
+ int vty_port = -1;
+ int daemon_mode = 0;
+ char *config_file = NULL;
+ struct thread thread;
+
+ umask(0027);
+
+ progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
+
+ zlog_default = openzlog(progname, ZLOG_PIM,
+ LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
+
+ /* this while just reads the options */
+ while (1) {
+ int opt;
+
+ opt = getopt_long (argc, argv, "dN:f:i:A:P:vZh", longopts, 0);
+
+ if (opt == EOF)
+ break;
+
+ switch (opt) {
+ case 0:
+ break;
+ case 'd':
+ daemon_mode = 1;
+ break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
+ case 'f':
+ config_file = optarg;
+ break;
+ case 'i':
+ pid_file = optarg;
+ break;
+ case 'A':
+ vty_addr = optarg;
+ break;
+ case 'P':
+ vty_port = atoi (optarg);
+ break;
+ case 'v':
+ printf(PIMD_PROGNAME " version %s\n", PIMD_VERSION);
+ print_version(QUAGGA_PROGNAME);
+ exit (0);
+ break;
+#ifdef PIM_ZCLIENT_DEBUG
+ case 'Z':
+ zclient_debug = 1;
+ break;
+#endif
+ case 'h':
+ usage (0);
+ break;
+ default:
+ usage (1);
+ break;
+ }
+ }
+
+ strcpy (config_default, path_config ("pimd.conf"));
+ strcpy (pid_file_default, path_state ("pimd.pid"));
+
+ master = thread_master_create();
+
+ /*
+ * Temporarily send zlog to stdout
+ */
+ zlog_default->maxlvl[ZLOG_DEST_STDOUT] = zlog_default->default_lvl;
+ zlog_notice("Boot logging temporarily directed to stdout - begin");
+
+ zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting",
+ QUAGGA_VERSION, PIMD_VERSION);
+
+ /*
+ * Initializations
+ */
+ zprivs_init (&pimd_privs);
+ pim_signals_init();
+ cmd_init(1);
+ vty_init(master);
+ memory_init();
+ access_list_init();
+ pim_init();
+ sort_node();
+
+ /*
+ * reset zlog default, then will obey configuration file
+ */
+ zlog_notice("Boot logging temporarily directed to stdout - end");
+#if 0
+ /* this would disable logging to stdout, but config has not been
+ loaded yet to reconfig the logging output */
+ zlog_default->maxlvl[ZLOG_DEST_STDOUT] = ZLOG_DISABLED;
+#endif
+
+ zlog_notice("Loading configuration - begin");
+
+ /* Get configuration file. */
+ vty_read_config(config_file, config_default);
+
+ /*
+ Starting from here zlog_* functions will log according configuration
+ */
+
+ zlog_notice("Loading configuration - end");
+
+ /* Change to the daemon program. */
+ if (daemon_mode) {
+ if (daemon(0, 0)) {
+ zlog_warn("failed to daemonize");
+ }
+ }
+
+ /* Process ID file creation. */
+ pid_output(pid_file);
+
+ /* Create pimd VTY socket */
+ if (vty_port < 0)
+ vty_port = PIMD_VTY_PORT;
+ vty_serv_sock(vty_addr, vty_port, path_state ("pimd.vty"));
+
+ zlog_notice("Quagga %s " PIMD_PROGNAME " %s starting, VTY interface at port TCP %d",
+ QUAGGA_VERSION, PIMD_VERSION, vty_port);
+
+#ifdef PIM_DEBUG_BYDEFAULT
+ zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
+ PIM_DO_DEBUG_PIM_EVENTS;
+ PIM_DO_DEBUG_PIM_PACKETS;
+ PIM_DO_DEBUG_PIM_TRACE;
+ PIM_DO_DEBUG_IGMP_EVENTS;
+ PIM_DO_DEBUG_IGMP_PACKETS;
+ PIM_DO_DEBUG_IGMP_TRACE;
+ PIM_DO_DEBUG_ZEBRA;
+#endif
+
+#ifdef PIM_ZCLIENT_DEBUG
+ zlog_notice("PIM_ZCLIENT_DEBUG: zclient debugging is supported, mode is %s (see option -Z)",
+ zclient_debug ? "ON" : "OFF");
+#endif
+
+#ifdef PIM_CHECK_RECV_IFINDEX_SANITY
+ zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex");
+#ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
+ zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch");
+#endif
+#endif
+
+#ifdef PIM_USE_QUAGGA_INET_CHECKSUM
+ zlog_notice("PIM_USE_QUAGGA_INET_CHECKSUM: using Quagga's builtin checksum");
+#endif
+
+#ifdef PIM_UNEXPECTED_KERNEL_UPCALL
+ zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
+#endif
+
+ /*
+ Initialize zclient "update" and "lookup" sockets
+ */
+ pim_zebra_init();
+
+ while (thread_fetch(master, &thread))
+ thread_call(&thread);
+
+ zlog_err("%s %s: thread_fetch() returned NULL, exiting",
+ __FILE__, __PRETTY_FUNCTION__);
+
+ /* never reached */
+ return 0;
+}
diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c
new file mode 100644
index 00000000..f9c291dd
--- /dev/null
+++ b/pimd/pim_mroute.c
@@ -0,0 +1,448 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+#include "log.h"
+#include "privs.h"
+
+#include "pimd.h"
+#include "pim_mroute.h"
+#include "pim_str.h"
+#include "pim_time.h"
+#include "pim_iface.h"
+#include "pim_macro.h"
+
+/* GLOBAL VARS */
+extern struct zebra_privs_t pimd_privs;
+
+static void mroute_read_on(void);
+
+static int pim_mroute_set(int fd, int enable)
+{
+ int err;
+ int opt = enable ? MRT_INIT : MRT_DONE;
+ socklen_t opt_len = sizeof(opt);
+
+ err = setsockopt(fd, IPPROTO_IP, opt, &opt, opt_len);
+ if (err) {
+ int e = errno;
+ zlog_warn("%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,%s=%d): errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ fd, enable ? "MRT_INIT" : "MRT_DONE", opt, e, safe_strerror(e));
+ errno = e;
+ return -1;
+ }
+
+#if 0
+ zlog_info("%s %s: setsockopt(fd=%d,IPPROTO_IP,MRT_INIT,opt=%d): ok",
+ __FILE__, __PRETTY_FUNCTION__,
+ fd, opt);
+#endif
+
+ return 0;
+}
+
+int pim_mroute_msg(int fd, const char *buf, int buf_size)
+{
+ struct interface *ifp;
+ const struct ip *ip_hdr;
+ const struct igmpmsg *msg;
+ const char *upcall;
+ char src_str[100];
+ char grp_str[100];
+
+ ip_hdr = (const struct ip *) buf;
+
+ /* kernel upcall must have protocol=0 */
+ if (ip_hdr->ip_p) {
+ /* this is not a kernel upcall */
+#ifdef PIM_UNEXPECTED_KERNEL_UPCALL
+ zlog_warn("%s: not a kernel upcall proto=%d msg_size=%d",
+ __PRETTY_FUNCTION__, ip_hdr->ip_p, buf_size);
+#endif
+ return 0;
+ }
+
+ msg = (const struct igmpmsg *) buf;
+
+ switch (msg->im_msgtype) {
+ case IGMPMSG_NOCACHE: upcall = "NOCACHE"; break;
+ case IGMPMSG_WRONGVIF: upcall = "WRONGVIF"; break;
+ case IGMPMSG_WHOLEPKT: upcall = "WHOLEPKT"; break;
+ default: upcall = "<unknown_upcall?>";
+ }
+ ifp = pim_if_find_by_vif_index(msg->im_vif);
+ pim_inet4_dump("<src?>", msg->im_src, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", msg->im_dst, grp_str, sizeof(grp_str));
+
+ if (msg->im_msgtype == IGMPMSG_WRONGVIF) {
+ struct pim_ifchannel *ch;
+ struct pim_interface *pim_ifp;
+
+ /*
+ Send Assert(S,G) on iif as response to WRONGVIF kernel upcall.
+
+ RFC 4601 4.8.2. PIM-SSM-Only Routers
+
+ iif is the incoming interface of the packet.
+ if (iif is in inherited_olist(S,G)) {
+ send Assert(S,G) on iif
+ }
+ */
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("%s: WRONGVIF from fd=%d for (S,G)=(%s,%s) on %s vifi=%d",
+ __PRETTY_FUNCTION__,
+ fd,
+ src_str,
+ grp_str,
+ ifp ? ifp->name : "<ifname?>",
+ msg->im_vif);
+ }
+
+ if (!ifp) {
+ zlog_warn("%s: WRONGVIF (S,G)=(%s,%s) could not find input interface for input_vif_index=%d",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, msg->im_vif);
+ return -1;
+ }
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ zlog_warn("%s: WRONGVIF (S,G)=(%s,%s) multicast not enabled on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return -2;
+ }
+
+ ch = pim_ifchannel_find(ifp, msg->im_src, msg->im_dst);
+ if (!ch) {
+ zlog_warn("%s: WRONGVIF (S,G)=(%s,%s) could not find channel on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return -3;
+ }
+
+ /*
+ RFC 4601: 4.6.1. (S,G) Assert Message State Machine
+
+ Transitions from NoInfo State
+
+ An (S,G) data packet arrives on interface I, AND
+ CouldAssert(S,G,I)==TRUE An (S,G) data packet arrived on an
+ downstream interface that is in our (S,G) outgoing interface
+ list. We optimistically assume that we will be the assert
+ winner for this (S,G), and so we transition to the "I am Assert
+ Winner" state and perform Actions A1 (below), which will
+ initiate the assert negotiation for (S,G).
+ */
+
+ if (ch->ifassert_state != PIM_IFASSERT_NOINFO) {
+ zlog_warn("%s: WRONGVIF (S,G)=(%s,%s) channel is not on Assert NoInfo state for interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return -4;
+ }
+
+ if (!PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags)) {
+ zlog_warn("%s: WRONGVIF (S,G)=(%s,%s) interface %s is not downstream for channel",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return -5;
+ }
+
+ if (assert_action_a1(ch)) {
+ zlog_warn("%s: WRONGVIF (S,G)=(%s,%s) assert_action_a1 failure on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, ifp->name);
+ return -6;
+ }
+
+ return 0;
+ } /* IGMPMSG_WRONGVIF */
+
+ zlog_warn("%s: kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%s,%s) on %s vifi=%d",
+ __PRETTY_FUNCTION__,
+ upcall,
+ msg->im_msgtype,
+ ip_hdr->ip_p,
+ fd,
+ src_str,
+ grp_str,
+ ifp ? ifp->name : "<ifname?>",
+ msg->im_vif);
+
+ return 0;
+}
+
+static int mroute_read_msg(int fd)
+{
+ const int msg_min_size = MAX(sizeof(struct ip), sizeof(struct igmpmsg));
+ char buf[1000];
+ int rd;
+
+ if (((int) sizeof(buf)) < msg_min_size) {
+ zlog_err("%s: fd=%d: buf size=%d lower than msg_min=%d",
+ __PRETTY_FUNCTION__, fd, sizeof(buf), msg_min_size);
+ return -1;
+ }
+
+ rd = read(fd, buf, sizeof(buf));
+ if (rd < 0) {
+ zlog_warn("%s: failure reading fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ return -2;
+ }
+
+ if (rd < msg_min_size) {
+ zlog_warn("%s: short message reading fd=%d: read=%d msg_min=%d",
+ __PRETTY_FUNCTION__, fd, rd, msg_min_size);
+ return -3;
+ }
+
+ return pim_mroute_msg(fd, buf, rd);
+}
+
+static int mroute_read(struct thread *t)
+{
+ int fd;
+ int result;
+
+ zassert(t);
+ zassert(!THREAD_ARG(t));
+
+ fd = THREAD_FD(t);
+ zassert(fd == qpim_mroute_socket_fd);
+
+ result = mroute_read_msg(fd);
+
+ /* Keep reading */
+ qpim_mroute_socket_reader = 0;
+ mroute_read_on();
+
+ return result;
+}
+
+static void mroute_read_on()
+{
+ zassert(!qpim_mroute_socket_reader);
+ zassert(PIM_MROUTE_IS_ENABLED);
+
+ THREAD_READ_ON(master, qpim_mroute_socket_reader,
+ mroute_read, 0, qpim_mroute_socket_fd);
+}
+
+static void mroute_read_off()
+{
+ THREAD_OFF(qpim_mroute_socket_reader);
+}
+
+int pim_mroute_socket_enable()
+{
+ int fd;
+
+ if (PIM_MROUTE_IS_ENABLED)
+ return -1;
+
+ if ( pimd_privs.change (ZPRIVS_RAISE) )
+ zlog_err ("pim_mroute_socket_enable: could not raise privs, %s",
+ safe_strerror (errno) );
+
+ fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
+
+ if ( pimd_privs.change (ZPRIVS_LOWER) )
+ zlog_err ("pim_mroute_socket_enable: could not lower privs, %s",
+ safe_strerror (errno) );
+
+ if (fd < 0) {
+ zlog_warn("Could not create mroute socket: errno=%d: %s",
+ errno, safe_strerror(errno));
+ return -2;
+ }
+
+ if (pim_mroute_set(fd, 1)) {
+ zlog_warn("Could not enable mroute on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return -3;
+ }
+
+ qpim_mroute_socket_fd = fd;
+ qpim_mroute_socket_creation = pim_time_monotonic_sec();
+ mroute_read_on();
+
+ zassert(PIM_MROUTE_IS_ENABLED);
+
+ return 0;
+}
+
+int pim_mroute_socket_disable()
+{
+ if (PIM_MROUTE_IS_DISABLED)
+ return -1;
+
+ if (pim_mroute_set(qpim_mroute_socket_fd, 0)) {
+ zlog_warn("Could not disable mroute on socket fd=%d: errno=%d: %s",
+ qpim_mroute_socket_fd, errno, safe_strerror(errno));
+ return -2;
+ }
+
+ if (close(qpim_mroute_socket_fd)) {
+ zlog_warn("Failure closing mroute socket: fd=%d errno=%d: %s",
+ qpim_mroute_socket_fd, errno, safe_strerror(errno));
+ return -3;
+ }
+
+ mroute_read_off();
+ qpim_mroute_socket_fd = -1;
+
+ zassert(PIM_MROUTE_IS_DISABLED);
+
+ return 0;
+}
+
+/*
+ For each network interface (e.g., physical or a virtual tunnel) that
+ would be used for multicast forwarding, a corresponding multicast
+ interface must be added to the kernel.
+ */
+int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr)
+{
+ struct vifctl_ext vc;
+ int err;
+
+ if (PIM_MROUTE_IS_DISABLED) {
+ zlog_warn("%s: global multicast is disabled",
+ __PRETTY_FUNCTION__);
+ return -1;
+ }
+
+ memset(&vc, 0, sizeof(vc));
+ vc.vc.vifc_vifi = vif_index;
+ vc.vc.vifc_flags = 0;
+ vc.vc.vifc_threshold = PIM_MROUTE_MIN_TTL;
+ vc.vc.vifc_rate_limit = 0;
+ vc.ifindex = vif_index;
+ memcpy(&vc.vc.vifc_lcl_addr, &ifaddr, sizeof(vc.vc.vifc_lcl_addr));
+
+#ifdef PIM_DVMRP_TUNNEL
+ if (vc.vifc_flags & VIFF_TUNNEL) {
+ memcpy(&vc.vifc_rmt_addr, &vif_remote_addr, sizeof(vc.vifc_rmt_addr));
+ }
+#endif
+
+ err = setsockopt(qpim_mroute_socket_fd, IPPROTO_IP, MRT_ADD_VIF, (void*) &vc, sizeof(vc));
+ if (err)
+ err = setsockopt(qpim_mroute_socket_fd, IPPROTO_IP, MRT_ADD_VIF, (void*) &vc, sizeof(vc.vc));
+ if (err) {
+ char ifaddr_str[100];
+ int e = errno;
+
+ pim_inet4_dump("<ifaddr?>", ifaddr, ifaddr_str, sizeof(ifaddr_str));
+
+ zlog_warn("%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%s): errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ qpim_mroute_socket_fd, vif_index, ifaddr_str,
+ e, safe_strerror(e));
+ errno = e;
+ return -2;
+ }
+
+ return 0;
+}
+
+int pim_mroute_del_vif(int vif_index)
+{
+ struct vifctl vc;
+ int err;
+
+ if (PIM_MROUTE_IS_DISABLED) {
+ zlog_warn("%s: global multicast is disabled",
+ __PRETTY_FUNCTION__);
+ return -1;
+ }
+
+ memset(&vc, 0, sizeof(vc));
+ vc.vifc_vifi = vif_index;
+
+ err = setsockopt(qpim_mroute_socket_fd, IPPROTO_IP, MRT_DEL_VIF, (void*) &vc, sizeof(vc));
+ if (err) {
+ int e = errno;
+ zlog_warn("%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_VIF,vif_index=%d): errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ qpim_mroute_socket_fd, vif_index,
+ e, safe_strerror(e));
+ errno = e;
+ return -2;
+ }
+
+ return 0;
+}
+
+int pim_mroute_add(struct mfcctl *mc)
+{
+ int err;
+
+ if (PIM_MROUTE_IS_DISABLED) {
+ zlog_warn("%s: global multicast is disabled",
+ __PRETTY_FUNCTION__);
+ return -1;
+ }
+
+ err = setsockopt(qpim_mroute_socket_fd, IPPROTO_IP, MRT_ADD_MFC,
+ mc, sizeof(*mc));
+ if (err) {
+ int e = errno;
+ zlog_warn("%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_MFC): errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ qpim_mroute_socket_fd,
+ e, safe_strerror(e));
+ errno = e;
+ return -2;
+ }
+
+ return 0;
+}
+
+int pim_mroute_del(struct mfcctl *mc)
+{
+ int err;
+
+ if (PIM_MROUTE_IS_DISABLED) {
+ zlog_warn("%s: global multicast is disabled",
+ __PRETTY_FUNCTION__);
+ return -1;
+ }
+
+ err = setsockopt(qpim_mroute_socket_fd, IPPROTO_IP, MRT_DEL_MFC, mc, sizeof(*mc));
+ if (err) {
+ int e = errno;
+ zlog_warn("%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_MFC): errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ qpim_mroute_socket_fd,
+ e, safe_strerror(e));
+ errno = e;
+ return -2;
+ }
+
+ return 0;
+}
diff --git a/pimd/pim_mroute.h b/pimd/pim_mroute.h
new file mode 100644
index 00000000..9aa48a43
--- /dev/null
+++ b/pimd/pim_mroute.h
@@ -0,0 +1,178 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_MROUTE_H
+#define PIM_MROUTE_H
+
+/*
+ For msghdr.msg_control in Solaris 10
+*/
+#ifndef _XPG4_2
+#define _XPG4_2
+#endif
+#ifndef __EXTENSIONS__
+#define __EXTENSIONS__
+#endif
+
+#include <netinet/in.h>
+#ifdef HAVE_NETINET_IP_MROUTE_H
+#include <netinet/ip_mroute.h>
+#endif
+
+#define PIM_MROUTE_MIN_TTL (1)
+
+/*
+ Below: from <linux/mroute.h>
+*/
+
+#ifndef MAXVIFS
+#define MAXVIFS (32)
+#endif
+
+#ifndef SIOCGETVIFCNT
+#define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */
+#define SIOCGETSGCNT (SIOCPROTOPRIVATE+1)
+#define SIOCGETRPF (SIOCPROTOPRIVATE+2)
+#endif
+
+#ifndef MRT_INIT
+#define MRT_BASE 200
+#define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */
+#define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */
+#define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */
+#define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */
+#define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */
+#define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */
+#define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */
+#define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */
+#define MRT_PIM (MRT_BASE+8) /* enable PIM code */
+#endif
+
+#ifndef HAVE_VIFI_T
+typedef unsigned short vifi_t;
+#endif
+
+#ifndef HAVE_STRUCT_VIFCTL
+struct vifctl {
+ vifi_t vifc_vifi; /* Index of VIF */
+ unsigned char vifc_flags; /* VIFF_ flags */
+ unsigned char vifc_threshold; /* ttl limit */
+ unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
+ struct in_addr vifc_lcl_addr; /* Our address */
+ struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
+};
+#endif
+
+struct vifctl_ext {
+ struct vifctl vc; /* vifctl */
+ int ifindex; /* interface index */
+};
+
+#ifndef HAVE_STRUCT_MFCCTL
+struct mfcctl {
+ struct in_addr mfcc_origin; /* Origin of mcast */
+ struct in_addr mfcc_mcastgrp; /* Group in question */
+ vifi_t mfcc_parent; /* Where it arrived */
+ unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */
+ unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */
+ unsigned int mfcc_byte_cnt;
+ unsigned int mfcc_wrong_if;
+ int mfcc_expire;
+};
+#endif
+
+/*
+ * Group count retrieval for mrouted
+ */
+/*
+ struct sioc_sg_req sgreq;
+ memset(&sgreq, 0, sizeof(sgreq));
+ memcpy(&sgreq.src, &source_addr, sizeof(sgreq.src));
+ memcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp));
+ ioctl(mrouter_s4, SIOCGETSGCNT, &sgreq);
+ */
+#ifndef HAVE_STRUCT_SIOC_SG_REQ
+struct sioc_sg_req {
+ struct in_addr src;
+ struct in_addr grp;
+ unsigned long pktcnt;
+ unsigned long bytecnt;
+ unsigned long wrong_if;
+};
+#endif
+
+/*
+ * To get vif packet counts
+ */
+/*
+ struct sioc_vif_req vreq;
+ memset(&vreq, 0, sizeof(vreq));
+ vreq.vifi = vif_index;
+ ioctl(mrouter_s4, SIOCGETVIFCNT, &vreq);
+ */
+#ifndef HAVE_STRUCT_SIOC_VIF_REQ
+struct sioc_vif_req {
+ vifi_t vifi; /* Which iface */
+ unsigned long icount; /* In packets */
+ unsigned long ocount; /* Out packets */
+ unsigned long ibytes; /* In bytes */
+ unsigned long obytes; /* Out bytes */
+};
+#endif
+
+/*
+ * Pseudo messages used by mrouted
+ */
+#ifndef IGMPMSG_NOCACHE
+#define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */
+#define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */
+#define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */
+#endif
+
+#ifndef HAVE_STRUCT_IGMPMSG
+struct igmpmsg
+{
+ uint32_t unused1,unused2;
+ unsigned char im_msgtype; /* What is this */
+ unsigned char im_mbz; /* Must be zero */
+ unsigned char im_vif; /* Interface (this ought to be a vifi_t!) */
+ unsigned char unused3;
+ struct in_addr im_src,im_dst;
+};
+#endif
+
+/*
+ Above: from <linux/mroute.h>
+*/
+
+int pim_mroute_socket_enable(void);
+int pim_mroute_socket_disable(void);
+
+int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr);
+int pim_mroute_del_vif(int vif_index);
+
+int pim_mroute_add(struct mfcctl *mc);
+int pim_mroute_del(struct mfcctl *mc);
+
+int pim_mroute_msg(int fd, const char *buf, int buf_size);
+
+#endif /* PIM_MROUTE_H */
diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c
new file mode 100644
index 00000000..1105eaca
--- /dev/null
+++ b/pimd/pim_msg.c
@@ -0,0 +1,106 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "pimd.h"
+#include "pim_pim.h"
+#include "pim_msg.h"
+#include "pim_util.h"
+
+void pim_msg_build_header(char *pim_msg, int pim_msg_size,
+ uint8_t pim_msg_type)
+{
+ uint16_t checksum;
+
+ zassert(pim_msg_size >= PIM_PIM_MIN_LEN);
+
+ /*
+ * Write header
+ */
+
+ *(uint8_t *) PIM_MSG_HDR_OFFSET_VERSION(pim_msg) = (PIM_PROTO_VERSION << 4) | pim_msg_type;
+ *(uint8_t *) PIM_MSG_HDR_OFFSET_RESERVED(pim_msg) = 0;
+
+ /*
+ * Compute checksum
+ */
+
+ *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) = 0;
+ checksum = pim_inet_checksum(pim_msg, pim_msg_size);
+ *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) = checksum;
+}
+
+char *pim_msg_addr_encode_ipv4_ucast(char *buf,
+ int buf_size,
+ struct in_addr addr)
+{
+ const int ENCODED_IPV4_UCAST_SIZE = 6;
+
+ if (buf_size < ENCODED_IPV4_UCAST_SIZE) {
+ return 0;
+ }
+
+ buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */
+ buf[1] = '\0'; /* native encoding */
+ *(struct in_addr *)(buf + 2) = addr;
+
+ return buf + ENCODED_IPV4_UCAST_SIZE;
+}
+
+char *pim_msg_addr_encode_ipv4_group(char *buf,
+ int buf_size,
+ struct in_addr addr)
+{
+ const int ENCODED_IPV4_GROUP_SIZE = 8;
+
+ if (buf_size < ENCODED_IPV4_GROUP_SIZE) {
+ return 0;
+ }
+
+ buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */
+ buf[1] = '\0'; /* native encoding */
+ buf[2] = '\0'; /* reserved */
+ buf[3] = 32; /* mask len */
+ *(struct in_addr *)(buf + 4) = addr;
+
+ return buf + ENCODED_IPV4_GROUP_SIZE;
+}
+
+char *pim_msg_addr_encode_ipv4_source(char *buf,
+ int buf_size,
+ struct in_addr addr)
+{
+ const int ENCODED_IPV4_SOURCE_SIZE = 8;
+
+ if (buf_size < ENCODED_IPV4_SOURCE_SIZE) {
+ return 0;
+ }
+
+ buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */
+ buf[1] = '\0'; /* native encoding */
+ buf[2] = 4; /* reserved = 0 | S bit = 1 | W bit = 0 | R bit = 0 */
+ buf[3] = 32; /* mask len */
+ *(struct in_addr *)(buf + 4) = addr;
+
+ return buf + ENCODED_IPV4_SOURCE_SIZE;
+}
diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h
new file mode 100644
index 00000000..228d6a85
--- /dev/null
+++ b/pimd/pim_msg.h
@@ -0,0 +1,52 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_MSG_H
+#define PIM_MSG_H
+
+#include <netinet/in.h>
+
+/*
+ Number Description
+ ---------- ------------------
+ 0 Reserved
+ 1 IP (IP version 4)
+ 2 IP6 (IP version 6)
+
+ From:
+ http://www.iana.org/assignments/address-family-numbers
+*/
+#define PIM_MSG_ADDRESS_FAMILY_IPV4 (1)
+
+void pim_msg_build_header(char *pim_msg, int pim_msg_size,
+ uint8_t pim_msg_type);
+char *pim_msg_addr_encode_ipv4_ucast(char *buf,
+ int buf_size,
+ struct in_addr addr);
+char *pim_msg_addr_encode_ipv4_group(char *buf,
+ int buf_size,
+ struct in_addr addr);
+char *pim_msg_addr_encode_ipv4_source(char *buf,
+ int buf_size,
+ struct in_addr addr);
+
+#endif /* PIM_MSG_H */
diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c
new file mode 100644
index 00000000..9013b50c
--- /dev/null
+++ b/pimd/pim_neighbor.c
@@ -0,0 +1,715 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "prefix.h"
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_neighbor.h"
+#include "pim_time.h"
+#include "pim_str.h"
+#include "pim_iface.h"
+#include "pim_pim.h"
+#include "pim_upstream.h"
+#include "pim_ifchannel.h"
+
+static void dr_election_by_addr(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct pim_neighbor *neigh;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ pim_ifp->pim_dr_addr = pim_ifp->primary_address;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("%s: on interface %s",
+ __PRETTY_FUNCTION__,
+ ifp->name);
+ }
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
+ if (ntohl(neigh->source_addr.s_addr) > ntohl(pim_ifp->pim_dr_addr.s_addr)) {
+ pim_ifp->pim_dr_addr = neigh->source_addr;
+ }
+ }
+}
+
+static void dr_election_by_pri(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct pim_neighbor *neigh;
+ uint32_t dr_pri;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ pim_ifp->pim_dr_addr = pim_ifp->primary_address;
+ dr_pri = pim_ifp->pim_dr_priority;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("%s: dr pri %u on interface %s",
+ __PRETTY_FUNCTION__,
+ dr_pri, ifp->name);
+ }
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_info("%s: neigh pri %u addr %x if dr addr %x",
+ __PRETTY_FUNCTION__,
+ neigh->dr_priority,
+ ntohl(neigh->source_addr.s_addr),
+ ntohl(pim_ifp->pim_dr_addr.s_addr));
+ }
+ if (
+ (neigh->dr_priority > dr_pri) ||
+ (
+ (neigh->dr_priority == dr_pri) &&
+ (ntohl(neigh->source_addr.s_addr) > ntohl(pim_ifp->pim_dr_addr.s_addr))
+ )
+ ) {
+ pim_ifp->pim_dr_addr = neigh->source_addr;
+ dr_pri = neigh->dr_priority;
+ }
+ }
+}
+
+/*
+ RFC 4601: 4.3.2. DR Election
+
+ A router's idea of the current DR on an interface can change when a
+ PIM Hello message is received, when a neighbor times out, or when a
+ router's own DR Priority changes.
+ */
+void pim_if_dr_election(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp = ifp->info;
+ struct in_addr old_dr_addr;
+
+ pim_ifp->pim_dr_election_last = pim_time_monotonic_sec(); /* timestamp */
+ ++pim_ifp->pim_dr_election_count;
+
+ old_dr_addr = pim_ifp->pim_dr_addr;
+
+ if (pim_ifp->pim_dr_num_nondrpri_neighbors) {
+ dr_election_by_addr(ifp);
+ }
+ else {
+ dr_election_by_pri(ifp);
+ }
+
+ /* DR changed ? */
+ if (old_dr_addr.s_addr != pim_ifp->pim_dr_addr.s_addr) {
+ char dr_old_str[100];
+ char dr_new_str[100];
+ pim_inet4_dump("<old_dr?>", old_dr_addr, dr_old_str, sizeof(dr_old_str));
+ pim_inet4_dump("<new_dr?>", pim_ifp->pim_dr_addr, dr_new_str, sizeof(dr_new_str));
+ zlog_info("%s: DR was %s now is %s on interface %s",
+ __PRETTY_FUNCTION__,
+ dr_old_str, dr_new_str, ifp->name);
+
+ pim_if_update_join_desired(pim_ifp);
+ pim_if_update_could_assert(ifp);
+ pim_if_update_assert_tracking_desired(ifp);
+ }
+}
+
+static void update_dr_priority(struct pim_neighbor *neigh,
+ pim_hello_options hello_options,
+ uint32_t dr_priority)
+{
+ pim_hello_options will_set_pri; /* boolean */
+ pim_hello_options bit_flip; /* boolean */
+ pim_hello_options pri_change; /* boolean */
+
+ will_set_pri = PIM_OPTION_IS_SET(hello_options,
+ PIM_OPTION_MASK_DR_PRIORITY);
+
+ bit_flip =
+ (
+ will_set_pri !=
+ PIM_OPTION_IS_SET(neigh->hello_options, PIM_OPTION_MASK_DR_PRIORITY)
+ );
+
+ if (bit_flip) {
+ struct pim_interface *pim_ifp = neigh->interface->info;
+
+ /* update num. of neighbors without dr_pri */
+
+ if (will_set_pri) {
+ --pim_ifp->pim_dr_num_nondrpri_neighbors;
+ }
+ else {
+ ++pim_ifp->pim_dr_num_nondrpri_neighbors;
+ }
+ }
+
+ pri_change =
+ (
+ bit_flip
+ ||
+ (neigh->dr_priority != dr_priority)
+ );
+
+ if (will_set_pri) {
+ neigh->dr_priority = dr_priority;
+ }
+ else {
+ neigh->dr_priority = 0; /* cosmetic unset */
+ }
+
+ if (pri_change) {
+ /*
+ RFC 4601: 4.3.2. DR Election
+
+ A router's idea of the current DR on an interface can change when a
+ PIM Hello message is received, when a neighbor times out, or when a
+ router's own DR Priority changes.
+ */
+ pim_if_dr_election(neigh->interface);
+ }
+}
+
+static int on_neighbor_timer(struct thread *t)
+{
+ struct pim_neighbor *neigh;
+ struct interface *ifp;
+ char msg[100];
+
+ zassert(t);
+ neigh = THREAD_ARG(t);
+ zassert(neigh);
+
+ ifp = neigh->interface;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str));
+ zlog_debug("Expired %d sec holdtime for neighbor %s on interface %s",
+ neigh->holdtime, src_str, ifp->name);
+ }
+
+ neigh->t_expire_timer = 0;
+
+ snprintf(msg, sizeof(msg), "%d-sec holdtime expired", neigh->holdtime);
+ pim_neighbor_delete(ifp, neigh, msg);
+
+ /*
+ RFC 4601: 4.3.2. DR Election
+
+ A router's idea of the current DR on an interface can change when a
+ PIM Hello message is received, when a neighbor times out, or when a
+ router's own DR Priority changes.
+ */
+ pim_if_dr_election(ifp);
+
+ return 0;
+}
+
+static void neighbor_timer_off(struct pim_neighbor *neigh)
+{
+ if (PIM_DEBUG_PIM_TRACE) {
+ if (neigh->t_expire_timer) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: cancelling timer for neighbor %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, neigh->interface->name);
+ }
+ }
+ THREAD_OFF(neigh->t_expire_timer);
+ zassert(!neigh->t_expire_timer);
+}
+
+void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime)
+{
+ neigh->holdtime = holdtime;
+
+ neighbor_timer_off(neigh);
+
+ /*
+ 0xFFFF is request for no holdtime
+ */
+ if (neigh->holdtime == 0xFFFF) {
+ return;
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: starting %u sec timer for neighbor %s on %s",
+ __PRETTY_FUNCTION__,
+ neigh->holdtime, src_str, neigh->interface->name);
+ }
+
+ THREAD_TIMER_ON(master, neigh->t_expire_timer,
+ on_neighbor_timer,
+ neigh, neigh->holdtime);
+}
+
+static struct pim_neighbor *pim_neighbor_new(struct interface *ifp,
+ struct in_addr source_addr,
+ pim_hello_options hello_options,
+ uint16_t holdtime,
+ uint16_t propagation_delay,
+ uint16_t override_interval,
+ uint32_t dr_priority,
+ uint32_t generation_id,
+ struct list *addr_list)
+{
+ struct pim_interface *pim_ifp;
+ struct pim_neighbor *neigh;
+ char src_str[100];
+
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ neigh = XMALLOC(MTYPE_PIM_NEIGHBOR, sizeof(*neigh));
+ if (!neigh) {
+ zlog_err("%s: PIM XMALLOC(%d) failure",
+ __PRETTY_FUNCTION__, sizeof(*neigh));
+ return 0;
+ }
+
+ neigh->creation = pim_time_monotonic_sec();
+ neigh->source_addr = source_addr;
+ neigh->hello_options = hello_options;
+ neigh->propagation_delay_msec = propagation_delay;
+ neigh->override_interval_msec = override_interval;
+ neigh->dr_priority = dr_priority;
+ neigh->generation_id = generation_id;
+ neigh->prefix_list = addr_list;
+ neigh->t_expire_timer = 0;
+ neigh->interface = ifp;
+
+ pim_neighbor_timer_reset(neigh, holdtime);
+
+ pim_inet4_dump("<src?>", source_addr, src_str, sizeof(src_str));
+
+ if (PIM_DEBUG_PIM_EVENTS) {
+ zlog_debug("%s: creating PIM neighbor %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ }
+
+ zlog_info("PIM NEIGHBOR UP: neighbor %s on interface %s",
+ src_str, ifp->name);
+
+ if (neigh->propagation_delay_msec > pim_ifp->pim_neighbors_highest_propagation_delay_msec) {
+ pim_ifp->pim_neighbors_highest_propagation_delay_msec = neigh->propagation_delay_msec;
+ }
+ if (neigh->override_interval_msec > pim_ifp->pim_neighbors_highest_override_interval_msec) {
+ pim_ifp->pim_neighbors_highest_override_interval_msec = neigh->override_interval_msec;
+ }
+
+ if (!PIM_OPTION_IS_SET(neigh->hello_options,
+ PIM_OPTION_MASK_LAN_PRUNE_DELAY)) {
+ /* update num. of neighbors without hello option lan_delay */
+ ++pim_ifp->pim_number_of_nonlandelay_neighbors;
+ }
+
+ if (!PIM_OPTION_IS_SET(neigh->hello_options,
+ PIM_OPTION_MASK_DR_PRIORITY)) {
+ /* update num. of neighbors without hello option dr_pri */
+ ++pim_ifp->pim_dr_num_nondrpri_neighbors;
+ }
+
+ /*
+ RFC 4601: 4.3.2. DR Election
+
+ A router's idea of the current DR on an interface can change when a
+ PIM Hello message is received, when a neighbor times out, or when a
+ router's own DR Priority changes.
+ */
+ pim_if_dr_election(neigh->interface);
+
+ /*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ To allow new or rebooting routers to learn of PIM neighbors quickly,
+ when a Hello message is received from a new neighbor, or a Hello
+ message with a new GenID is received from an existing neighbor, a
+ new Hello message should be sent on this interface after a
+ randomized delay between 0 and Triggered_Hello_Delay.
+ */
+ pim_hello_restart_triggered(neigh->interface);
+
+ return neigh;
+}
+
+static void delete_prefix_list(struct pim_neighbor *neigh)
+{
+ if (neigh->prefix_list) {
+
+#ifdef DUMP_PREFIX_LIST
+ struct listnode *p_node;
+ struct prefix *p;
+ char addr_str[10];
+ int list_size = neigh->prefix_list ? (int) listcount(neigh->prefix_list) : -1;
+ int i = 0;
+ for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, p_node, p)) {
+ pim_inet4_dump("<addr?>", p->u.prefix4, addr_str, sizeof(addr_str));
+ zlog_debug("%s: DUMP_PREFIX_LIST neigh=%x prefix_list=%x prefix=%x addr=%s [%d/%d]",
+ __PRETTY_FUNCTION__,
+ (unsigned) neigh, (unsigned) neigh->prefix_list, (unsigned) p,
+ addr_str, i, list_size);
+ ++i;
+ }
+#endif
+
+ list_delete(neigh->prefix_list);
+ neigh->prefix_list = 0;
+ }
+}
+
+void pim_neighbor_free(struct pim_neighbor *neigh)
+{
+ zassert(!neigh->t_expire_timer);
+
+ delete_prefix_list(neigh);
+
+ XFREE(MTYPE_PIM_NEIGHBOR, neigh);
+}
+
+struct pim_neighbor *pim_neighbor_find(struct interface *ifp,
+ struct in_addr source_addr)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *node;
+ struct pim_neighbor *neigh;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) {
+ if (source_addr.s_addr == neigh->source_addr.s_addr) {
+ return neigh;
+ }
+ }
+
+ return 0;
+}
+
+struct pim_neighbor *pim_neighbor_add(struct interface *ifp,
+ struct in_addr source_addr,
+ pim_hello_options hello_options,
+ uint16_t holdtime,
+ uint16_t propagation_delay,
+ uint16_t override_interval,
+ uint32_t dr_priority,
+ uint32_t generation_id,
+ struct list *addr_list)
+{
+ struct pim_interface *pim_ifp;
+ struct pim_neighbor *neigh;
+
+ neigh = pim_neighbor_new(ifp, source_addr,
+ hello_options,
+ holdtime,
+ propagation_delay,
+ override_interval,
+ dr_priority,
+ generation_id,
+ addr_list);
+ if (!neigh) {
+ return 0;
+ }
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ listnode_add(pim_ifp->pim_neighbor_list, neigh);
+
+ return neigh;
+}
+
+static uint16_t
+find_neighbors_next_highest_propagation_delay_msec(struct interface *ifp,
+ struct pim_neighbor *highest_neigh)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *neigh_node;
+ struct pim_neighbor *neigh;
+ uint16_t next_highest_delay_msec;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ next_highest_delay_msec = pim_ifp->pim_propagation_delay_msec;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neigh_node, neigh)) {
+ if (neigh == highest_neigh)
+ continue;
+ if (neigh->propagation_delay_msec > next_highest_delay_msec)
+ next_highest_delay_msec = neigh->propagation_delay_msec;
+ }
+
+ return next_highest_delay_msec;
+}
+
+static uint16_t
+find_neighbors_next_highest_override_interval_msec(struct interface *ifp,
+ struct pim_neighbor *highest_neigh)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *neigh_node;
+ struct pim_neighbor *neigh;
+ uint16_t next_highest_interval_msec;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ next_highest_interval_msec = pim_ifp->pim_override_interval_msec;
+
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neigh_node, neigh)) {
+ if (neigh == highest_neigh)
+ continue;
+ if (neigh->override_interval_msec > next_highest_interval_msec)
+ next_highest_interval_msec = neigh->override_interval_msec;
+ }
+
+ return next_highest_interval_msec;
+}
+
+void pim_neighbor_delete(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ const char *delete_message)
+{
+ struct pim_interface *pim_ifp;
+ char src_str[100];
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ pim_inet4_dump("<src?>", neigh->source_addr, src_str, sizeof(src_str));
+ zlog_info("PIM NEIGHBOR DOWN: neighbor %s on interface %s: %s",
+ src_str, ifp->name, delete_message);
+
+ neighbor_timer_off(neigh);
+
+ pim_if_assert_on_neighbor_down(ifp, neigh->source_addr);
+
+ if (!PIM_OPTION_IS_SET(neigh->hello_options,
+ PIM_OPTION_MASK_LAN_PRUNE_DELAY)) {
+ /* update num. of neighbors without hello option lan_delay */
+
+ --pim_ifp->pim_number_of_nonlandelay_neighbors;
+ }
+
+ if (!PIM_OPTION_IS_SET(neigh->hello_options,
+ PIM_OPTION_MASK_DR_PRIORITY)) {
+ /* update num. of neighbors without dr_pri */
+
+ --pim_ifp->pim_dr_num_nondrpri_neighbors;
+ }
+
+ zassert(neigh->propagation_delay_msec <= pim_ifp->pim_neighbors_highest_propagation_delay_msec);
+ zassert(neigh->override_interval_msec <= pim_ifp->pim_neighbors_highest_override_interval_msec);
+
+ if (pim_if_lan_delay_enabled(ifp)) {
+
+ /* will delete a neighbor with highest propagation delay? */
+ if (neigh->propagation_delay_msec == pim_ifp->pim_neighbors_highest_propagation_delay_msec) {
+ /* then find the next highest propagation delay */
+ pim_ifp->pim_neighbors_highest_propagation_delay_msec =
+ find_neighbors_next_highest_propagation_delay_msec(ifp, neigh);
+ }
+
+ /* will delete a neighbor with highest override interval? */
+ if (neigh->override_interval_msec == pim_ifp->pim_neighbors_highest_override_interval_msec) {
+ /* then find the next highest propagation delay */
+ pim_ifp->pim_neighbors_highest_override_interval_msec =
+ find_neighbors_next_highest_override_interval_msec(ifp, neigh);
+ }
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("%s: deleting PIM neighbor %s on interface %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifp->name);
+ }
+
+ listnode_delete(pim_ifp->pim_neighbor_list, neigh);
+
+ pim_neighbor_free(neigh);
+}
+
+void pim_neighbor_delete_all(struct interface *ifp,
+ const char *delete_message)
+{
+ struct pim_interface *pim_ifp;
+ struct listnode *neigh_node;
+ struct listnode *neigh_nextnode;
+ struct pim_neighbor *neigh;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_neighbor_list, neigh_node,
+ neigh_nextnode, neigh)) {
+ pim_neighbor_delete(ifp, neigh, delete_message);
+ }
+}
+
+struct prefix *pim_neighbor_find_secondary(struct pim_neighbor *neigh,
+ struct in_addr addr)
+{
+ struct listnode *node;
+ struct prefix *p;
+
+ if (!neigh->prefix_list)
+ return 0;
+
+ for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list, node, p)) {
+ if (p->family == AF_INET) {
+ if (addr.s_addr == p->u.prefix4.s_addr) {
+ return p;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/*
+ RFC 4601: 4.3.4. Maintaining Secondary Address Lists
+
+ All the advertised secondary addresses in received Hello messages
+ must be checked against those previously advertised by all other
+ PIM neighbors on that interface. If there is a conflict and the
+ same secondary address was previously advertised by another
+ neighbor, then only the most recently received mapping MUST be
+ maintained, and an error message SHOULD be logged to the
+ administrator in a rate-limited manner.
+*/
+static void delete_from_neigh_addr(struct interface *ifp,
+ struct list *addr_list,
+ struct in_addr neigh_addr)
+{
+ struct listnode *addr_node;
+ struct prefix *addr;
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ zassert(addr_list);
+
+ /*
+ Scan secondary address list
+ */
+ for (ALL_LIST_ELEMENTS_RO(addr_list, addr_node,
+ addr)) {
+ struct listnode *neigh_node;
+ struct pim_neighbor *neigh;
+
+ if (addr->family != AF_INET)
+ continue;
+
+ /*
+ Scan neighbors
+ */
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neigh_node,
+ neigh)) {
+ {
+ struct prefix *p = pim_neighbor_find_secondary(neigh, addr->u.prefix4);
+ if (p) {
+ char addr_str[100];
+ char this_neigh_str[100];
+ char other_neigh_str[100];
+
+ pim_inet4_dump("<addr?>", addr->u.prefix4, addr_str, sizeof(addr_str));
+ pim_inet4_dump("<neigh1?>", neigh_addr, this_neigh_str, sizeof(this_neigh_str));
+ pim_inet4_dump("<neigh2?>", neigh->source_addr, other_neigh_str, sizeof(other_neigh_str));
+
+ zlog_info("secondary addr %s recvd from neigh %s deleted from neigh %s on %s",
+ addr_str, this_neigh_str, other_neigh_str, ifp->name);
+
+ listnode_delete(neigh->prefix_list, p);
+ prefix_free(p);
+ }
+ }
+
+ } /* scan neighbors */
+
+ } /* scan addr list */
+
+}
+
+void pim_neighbor_update(struct pim_neighbor *neigh,
+ pim_hello_options hello_options,
+ uint16_t holdtime,
+ uint32_t dr_priority,
+ struct list *addr_list)
+{
+ struct pim_interface *pim_ifp = neigh->interface->info;
+
+ /* Received holdtime ? */
+ if (PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME)) {
+ pim_neighbor_timer_reset(neigh, holdtime);
+ }
+ else {
+ pim_neighbor_timer_reset(neigh, PIM_IF_DEFAULT_HOLDTIME(pim_ifp));
+ }
+
+#ifdef DUMP_PREFIX_LIST
+ zlog_debug("%s: DUMP_PREFIX_LIST old_prefix_list=%x old_size=%d new_prefix_list=%x new_size=%d",
+ __PRETTY_FUNCTION__,
+ (unsigned) neigh->prefix_list,
+ neigh->prefix_list ? (int) listcount(neigh->prefix_list) : -1,
+ (unsigned) addr_list,
+ addr_list ? (int) listcount(addr_list) : -1);
+#endif
+
+ if (neigh->prefix_list == addr_list) {
+ if (addr_list) {
+ zlog_err("%s: internal error: trying to replace same prefix list=%u",
+ __PRETTY_FUNCTION__, (unsigned) addr_list);
+ }
+ }
+ else {
+ /* Delete existing secondary address list */
+ delete_prefix_list(neigh);
+ }
+
+ if (addr_list) {
+ delete_from_neigh_addr(neigh->interface, addr_list, neigh->source_addr);
+ }
+
+ /* Replace secondary address list */
+ neigh->prefix_list = addr_list;
+
+ update_dr_priority(neigh,
+ hello_options,
+ dr_priority);
+ /*
+ Copy flags
+ */
+ neigh->hello_options = hello_options;
+}
diff --git a/pimd/pim_neighbor.h b/pimd/pim_neighbor.h
new file mode 100644
index 00000000..8f19c750
--- /dev/null
+++ b/pimd/pim_neighbor.h
@@ -0,0 +1,74 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_NEIGHBOR_H
+#define PIM_NEIGHBOR_H
+
+#include <zebra.h>
+
+#include "if.h"
+#include "linklist.h"
+
+#include "pim_tlv.h"
+
+struct pim_neighbor {
+ int64_t creation; /* timestamp of creation */
+ struct in_addr source_addr;
+ pim_hello_options hello_options;
+ uint16_t holdtime;
+ uint16_t propagation_delay_msec;
+ uint16_t override_interval_msec;
+ uint32_t dr_priority;
+ uint32_t generation_id;
+ struct list *prefix_list; /* list of struct prefix */
+ struct thread *t_expire_timer;
+ struct interface *interface;
+};
+
+void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime);
+void pim_neighbor_free(struct pim_neighbor *neigh);
+struct pim_neighbor *pim_neighbor_find(struct interface *ifp,
+ struct in_addr source_addr);
+struct pim_neighbor *pim_neighbor_add(struct interface *ifp,
+ struct in_addr source_addr,
+ pim_hello_options hello_options,
+ uint16_t holdtime,
+ uint16_t propagation_delay,
+ uint16_t override_interval,
+ uint32_t dr_priority,
+ uint32_t generation_id,
+ struct list *addr_list);
+void pim_neighbor_delete(struct interface *ifp,
+ struct pim_neighbor *neigh,
+ const char *delete_message);
+void pim_neighbor_delete_all(struct interface *ifp,
+ const char *delete_message);
+void pim_neighbor_update(struct pim_neighbor *neigh,
+ pim_hello_options hello_options,
+ uint16_t holdtime,
+ uint32_t dr_priority,
+ struct list *addr_list);
+struct prefix *pim_neighbor_find_secondary(struct pim_neighbor *neigh,
+ struct in_addr addr);
+void pim_if_dr_election(struct interface *ifp);
+
+#endif /* PIM_NEIGHBOR_H */
diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c
new file mode 100644
index 00000000..2c8b056e
--- /dev/null
+++ b/pimd/pim_oil.c
@@ -0,0 +1,140 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "memory.h"
+#include "linklist.h"
+
+#include "pimd.h"
+#include "pim_oil.h"
+#include "pim_str.h"
+#include "pim_iface.h"
+
+void pim_channel_oil_free(struct channel_oil *c_oil)
+{
+ XFREE(MTYPE_PIM_CHANNEL_OIL, c_oil);
+}
+
+static void pim_channel_oil_delete(struct channel_oil *c_oil)
+{
+ /*
+ notice that listnode_delete() can't be moved
+ into pim_channel_oil_free() because the later is
+ called by list_delete_all_node()
+ */
+ listnode_delete(qpim_channel_oil_list, c_oil);
+
+ pim_channel_oil_free(c_oil);
+}
+
+static struct channel_oil *channel_oil_new(struct in_addr group_addr,
+ struct in_addr source_addr,
+ int input_vif_index)
+{
+ struct channel_oil *c_oil;
+ struct interface *ifp_in;
+
+ ifp_in = pim_if_find_by_vif_index(input_vif_index);
+ if (!ifp_in) {
+ /* warning only */
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: (S,G)=(%s,%s) could not find input interface for input_vif_index=%d",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, input_vif_index);
+ }
+
+ c_oil = XCALLOC(MTYPE_PIM_CHANNEL_OIL, sizeof(*c_oil));
+ if (!c_oil) {
+ zlog_err("PIM XCALLOC(%d) failure", sizeof(*c_oil));
+ return 0;
+ }
+
+ c_oil->oil.mfcc_mcastgrp = group_addr;
+ c_oil->oil.mfcc_origin = source_addr;
+ c_oil->oil.mfcc_parent = input_vif_index;
+ c_oil->oil_ref_count = 1;
+
+ zassert(c_oil->oil_size == 0);
+
+ return c_oil;
+}
+
+static struct channel_oil *pim_add_channel_oil(struct in_addr group_addr,
+ struct in_addr source_addr,
+ int input_vif_index)
+{
+ struct channel_oil *c_oil;
+
+ c_oil = channel_oil_new(group_addr, source_addr, input_vif_index);
+ if (!c_oil) {
+ zlog_warn("PIM XCALLOC(%d) failure", sizeof(*c_oil));
+ return 0;
+ }
+
+ listnode_add(qpim_channel_oil_list, c_oil);
+
+ return c_oil;
+}
+
+static struct channel_oil *pim_find_channel_oil(struct in_addr group_addr,
+ struct in_addr source_addr)
+{
+ struct listnode *node;
+ struct channel_oil *c_oil;
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_channel_oil_list, node, c_oil)) {
+ if ((group_addr.s_addr == c_oil->oil.mfcc_mcastgrp.s_addr) &&
+ (source_addr.s_addr == c_oil->oil.mfcc_origin.s_addr))
+ return c_oil;
+ }
+
+ return 0;
+}
+
+struct channel_oil *pim_channel_oil_add(struct in_addr group_addr,
+ struct in_addr source_addr,
+ int input_vif_index)
+{
+ struct channel_oil *c_oil;
+
+ c_oil = pim_find_channel_oil(group_addr, source_addr);
+ if (c_oil) {
+ ++c_oil->oil_ref_count;
+ return c_oil;
+ }
+
+ return pim_add_channel_oil(group_addr, source_addr, input_vif_index);
+}
+
+void pim_channel_oil_del(struct channel_oil *c_oil)
+{
+ --c_oil->oil_ref_count;
+
+ if (c_oil->oil_ref_count < 1) {
+ pim_channel_oil_delete(c_oil);
+ }
+}
diff --git a/pimd/pim_oil.h b/pimd/pim_oil.h
new file mode 100644
index 00000000..1753545a
--- /dev/null
+++ b/pimd/pim_oil.h
@@ -0,0 +1,53 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_OIL_H
+#define PIM_OIL_H
+
+#include "pim_mroute.h"
+
+#define PIM_OIF_FLAG_PROTO_IGMP (1 << 0) /* bitmask 1 */
+#define PIM_OIF_FLAG_PROTO_PIM (1 << 1) /* bitmask 2 */
+#define PIM_OIF_FLAG_PROTO_ANY (3) /* bitmask (1 | 2) */
+
+/*
+ qpim_channel_oil_list holds a list of struct channel_oil.
+
+ Each channel_oil.oil is used to control an (S,G) entry in the Kernel
+ Multicast Forwarding Cache.
+*/
+
+struct channel_oil {
+ struct mfcctl oil;
+ int oil_size;
+ int oil_ref_count;
+ time_t oif_creation[MAXVIFS];
+ uint32_t oif_flags[MAXVIFS];
+};
+
+void pim_channel_oil_free(struct channel_oil *c_oil);
+struct channel_oil *pim_channel_oil_add(struct in_addr group_addr,
+ struct in_addr source_addr,
+ int input_vif_index);
+void pim_channel_oil_del(struct channel_oil *c_oil);
+
+#endif /* PIM_OIL_H */
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c
new file mode 100644
index 00000000..9595d2d7
--- /dev/null
+++ b/pimd/pim_pim.c
@@ -0,0 +1,734 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "thread.h"
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_pim.h"
+#include "pim_time.h"
+#include "pim_iface.h"
+#include "pim_sock.h"
+#include "pim_str.h"
+#include "pim_util.h"
+#include "pim_tlv.h"
+#include "pim_neighbor.h"
+#include "pim_hello.h"
+#include "pim_join.h"
+#include "pim_assert.h"
+#include "pim_msg.h"
+#include "pim_rand.h"
+
+static int on_pim_hello_send(struct thread *t);
+static int pim_hello_send(struct interface *ifp,
+ uint16_t holdtime);
+
+static void sock_close(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp = ifp->info;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ if (pim_ifp->t_pim_sock_read) {
+ zlog_debug("Cancelling READ event for PIM socket fd=%d on interface %s",
+ pim_ifp->pim_sock_fd,
+ ifp->name);
+ }
+ }
+ THREAD_OFF(pim_ifp->t_pim_sock_read);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ if (pim_ifp->t_pim_hello_timer) {
+ zlog_debug("Cancelling PIM hello timer for interface %s",
+ ifp->name);
+ }
+ }
+ THREAD_OFF(pim_ifp->t_pim_hello_timer);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("Deleting PIM socket fd=%d on interface %s",
+ pim_ifp->pim_sock_fd, ifp->name);
+ }
+
+ if (close(pim_ifp->pim_sock_fd)) {
+ zlog_warn("Failure closing PIM socket fd=%d on interface %s: errno=%d: %s",
+ pim_ifp->pim_sock_fd, ifp->name,
+ errno, safe_strerror(errno));
+ }
+
+ pim_ifp->pim_sock_fd = -1;
+ pim_ifp->pim_sock_creation = 0;
+
+ zassert(pim_ifp->pim_sock_fd < 0);
+ zassert(!pim_ifp->t_pim_sock_read);
+ zassert(!pim_ifp->t_pim_hello_timer);
+ zassert(!pim_ifp->pim_sock_creation);
+}
+
+void pim_sock_delete(struct interface *ifp, const char *delete_message)
+{
+ zlog_info("PIM INTERFACE DOWN: on interface %s: %s",
+ ifp->name, delete_message);
+
+ if (!ifp->info) {
+ zlog_err("%s: %s: but PIM not enabled on interface %s (!)",
+ __PRETTY_FUNCTION__, delete_message, ifp->name);
+ return;
+ }
+
+ /*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Before an interface goes down or changes primary IP address, a Hello
+ message with a zero HoldTime should be sent immediately (with the
+ old IP address if the IP address changed).
+ */
+ pim_hello_send(ifp, 0 /* zero-sec holdtime */);
+
+ pim_neighbor_delete_all(ifp, delete_message);
+
+ sock_close(ifp);
+}
+
+int pim_pim_packet(struct interface *ifp, char *buf, size_t len)
+{
+ struct ip *ip_hdr;
+ size_t ip_hlen; /* ip header length in bytes */
+ char src_str[100];
+ char dst_str[100];
+ char *pim_msg;
+ int pim_msg_len;
+ uint8_t pim_version;
+ uint8_t pim_type;
+ uint16_t pim_checksum; /* received checksum */
+ uint16_t checksum; /* computed checksum */
+ struct pim_neighbor *neigh;
+
+ if (!ifp->info) {
+ zlog_warn("%s: PIM not enabled on interface %s",
+ __PRETTY_FUNCTION__, ifp->name);
+ return -1;
+ }
+
+ if (len < sizeof(*ip_hdr)) {
+ zlog_warn("PIM packet size=%d shorter than minimum=%d",
+ len, sizeof(*ip_hdr));
+ return -1;
+ }
+
+ ip_hdr = (struct ip *) buf;
+
+ pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, sizeof(src_str));
+ pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, sizeof(dst_str));
+
+ ip_hlen = ip_hdr->ip_hl << 2; /* ip_hl gives length in 4-byte words */
+
+ if (PIM_DEBUG_PIM_PACKETS) {
+ zlog_debug("Recv IP packet from %s to %s on %s: size=%d ip_header_size=%d ip_proto=%d",
+ src_str, dst_str, ifp->name, len, ip_hlen, ip_hdr->ip_p);
+ }
+
+ if (ip_hdr->ip_p != PIM_IP_PROTO_PIM) {
+ zlog_warn("IP packet protocol=%d is not PIM=%d",
+ ip_hdr->ip_p, PIM_IP_PROTO_PIM);
+ return -1;
+ }
+
+ if (ip_hlen < PIM_IP_HEADER_MIN_LEN) {
+ zlog_warn("IP packet header size=%d shorter than minimum=%d",
+ ip_hlen, PIM_IP_HEADER_MIN_LEN);
+ return -1;
+ }
+ if (ip_hlen > PIM_IP_HEADER_MAX_LEN) {
+ zlog_warn("IP packet header size=%d greater than maximum=%d",
+ ip_hlen, PIM_IP_HEADER_MAX_LEN);
+ return -1;
+ }
+
+ pim_msg = buf + ip_hlen;
+ pim_msg_len = len - ip_hlen;
+
+ if (PIM_DEBUG_PIM_PACKETDUMP_RECV) {
+ pim_pkt_dump(__PRETTY_FUNCTION__, pim_msg, pim_msg_len);
+ }
+
+ if (pim_msg_len < PIM_PIM_MIN_LEN) {
+ zlog_warn("PIM message size=%d shorter than minimum=%d",
+ pim_msg_len, PIM_PIM_MIN_LEN);
+ return -1;
+ }
+
+ pim_version = PIM_MSG_HDR_GET_VERSION(pim_msg);
+ pim_type = PIM_MSG_HDR_GET_TYPE(pim_msg);
+
+ if (pim_version != PIM_PROTO_VERSION) {
+ zlog_warn("Ignoring PIM pkt from %s with unsupported version: %d",
+ ifp->name, pim_version);
+ return -1;
+ }
+
+ /* save received checksum */
+ pim_checksum = PIM_MSG_HDR_GET_CHECKSUM(pim_msg);
+
+ /* for computing checksum */
+ *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) = 0;
+
+ checksum = pim_inet_checksum(pim_msg, pim_msg_len);
+ if (checksum != pim_checksum) {
+ zlog_warn("Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x",
+ ifp->name, pim_checksum, checksum);
+ return -1;
+ }
+
+ if (PIM_DEBUG_PIM_PACKETS) {
+ zlog_debug("Recv PIM packet from %s to %s on %s: ttl=%d pim_version=%d pim_type=%d pim_msg_size=%d checksum=%x",
+ src_str, dst_str, ifp->name, ip_hdr->ip_ttl,
+ pim_version, pim_type, pim_msg_len, checksum);
+ }
+
+ if (pim_type == PIM_MSG_TYPE_HELLO) {
+ return pim_hello_recv(ifp,
+ ip_hdr->ip_src,
+ pim_msg + PIM_MSG_HEADER_LEN,
+ pim_msg_len - PIM_MSG_HEADER_LEN);
+ }
+
+ neigh = pim_neighbor_find(ifp, ip_hdr->ip_src);
+ if (!neigh) {
+ zlog_warn("%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ pim_type, src_str, ifp->name);
+ return -1;
+ }
+
+ switch (pim_type) {
+ case PIM_MSG_TYPE_JOIN_PRUNE:
+ return pim_joinprune_recv(ifp, neigh,
+ ip_hdr->ip_src,
+ pim_msg + PIM_MSG_HEADER_LEN,
+ pim_msg_len - PIM_MSG_HEADER_LEN);
+ case PIM_MSG_TYPE_ASSERT:
+ return pim_assert_recv(ifp, neigh,
+ ip_hdr->ip_src,
+ pim_msg + PIM_MSG_HEADER_LEN,
+ pim_msg_len - PIM_MSG_HEADER_LEN);
+ default:
+ zlog_warn("%s %s: unsupported PIM message type=%d from %s on %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ pim_type, src_str, ifp->name);
+ }
+
+ return -1;
+}
+
+static void pim_sock_read_on(struct interface *ifp);
+
+static int pim_sock_read(struct thread *t)
+{
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ int fd;
+ struct sockaddr_in from;
+ struct sockaddr_in to;
+ socklen_t fromlen = sizeof(from);
+ socklen_t tolen = sizeof(to);
+ char buf[PIM_PIM_BUFSIZE_READ];
+ int len;
+ int ifindex = -1;
+ int result = -1; /* defaults to bad */
+
+ zassert(t);
+
+ ifp = THREAD_ARG(t);
+ zassert(ifp);
+
+ fd = THREAD_FD(t);
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ zassert(fd == pim_ifp->pim_sock_fd);
+
+ len = pim_socket_recvfromto(fd, buf, sizeof(buf),
+ &from, &fromlen,
+ &to, &tolen,
+ &ifindex);
+ if (len < 0) {
+ zlog_warn("Failure receiving IP PIM packet on fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ goto done;
+ }
+
+ if (PIM_DEBUG_PIM_PACKETS) {
+ char from_str[100];
+ char to_str[100];
+
+ if (!inet_ntop(AF_INET, &from.sin_addr, from_str, sizeof(from_str)))
+ sprintf(from_str, "<from?>");
+ if (!inet_ntop(AF_INET, &to.sin_addr, to_str, sizeof(to_str)))
+ sprintf(to_str, "<to?>");
+
+ zlog_debug("Recv IP PIM pkt size=%d from %s to %s on fd=%d on ifindex=%d (sock_ifindex=%d)",
+ len, from_str, to_str, fd, ifindex, ifp->ifindex);
+ }
+
+ if (PIM_DEBUG_PIM_PACKETDUMP_RECV) {
+ pim_pkt_dump(__PRETTY_FUNCTION__, buf, len);
+ }
+
+#ifdef PIM_CHECK_RECV_IFINDEX_SANITY
+ /* ifindex sanity check */
+ if (ifindex != (int) ifp->ifindex) {
+ char from_str[100];
+ char to_str[100];
+ struct interface *recv_ifp;
+
+ if (!inet_ntop(AF_INET, &from.sin_addr, from_str , sizeof(from_str)))
+ sprintf(from_str, "<from?>");
+ if (!inet_ntop(AF_INET, &to.sin_addr, to_str , sizeof(to_str)))
+ sprintf(to_str, "<to?>");
+
+ recv_ifp = if_lookup_by_index(ifindex);
+ if (recv_ifp) {
+ zassert(ifindex == (int) recv_ifp->ifindex);
+ }
+
+#ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
+ zlog_warn("Interface mismatch: recv PIM pkt from %s to %s on fd=%d: recv_ifindex=%d (%s) sock_ifindex=%d (%s)",
+ from_str, to_str, fd,
+ ifindex, recv_ifp ? recv_ifp->name : "<if-notfound>",
+ ifp->ifindex, ifp->name);
+#endif
+ goto done;
+ }
+#endif
+
+ if (pim_pim_packet(ifp, buf, len)) {
+ goto done;
+ }
+
+ result = 0; /* good */
+
+ done:
+ pim_sock_read_on(ifp);
+
+ if (result) {
+ ++pim_ifp->pim_ifstat_hello_recvfail;
+ }
+
+ return result;
+}
+
+static void pim_sock_read_on(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ zassert(ifp->info);
+
+ pim_ifp = ifp->info;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("Scheduling READ event on PIM socket fd=%d",
+ pim_ifp->pim_sock_fd);
+ }
+ pim_ifp->t_pim_sock_read = 0;
+ zassert(!pim_ifp->t_pim_sock_read);
+ THREAD_READ_ON(master, pim_ifp->t_pim_sock_read, pim_sock_read, ifp,
+ pim_ifp->pim_sock_fd);
+}
+
+static int pim_sock_open(struct in_addr ifaddr, int ifindex)
+{
+ int fd;
+
+ fd = pim_socket_mcast(IPPROTO_PIM, ifaddr, 0 /* loop=false */);
+ if (fd < 0)
+ return -1;
+
+ if (pim_socket_join(fd, qpim_all_pim_routers_addr, ifaddr, ifindex)) {
+ return -2;
+ }
+
+ return fd;
+}
+
+void pim_ifstat_reset(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp) {
+ return;
+ }
+
+ pim_ifp->pim_ifstat_start = pim_time_monotonic_sec();
+ pim_ifp->pim_ifstat_hello_sent = 0;
+ pim_ifp->pim_ifstat_hello_sendfail = 0;
+ pim_ifp->pim_ifstat_hello_recv = 0;
+ pim_ifp->pim_ifstat_hello_recvfail = 0;
+}
+
+void pim_sock_reset(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ zassert(ifp->info);
+
+ pim_ifp = ifp->info;
+
+ pim_ifp->primary_address = pim_find_primary_addr(ifp);
+
+ pim_ifp->pim_sock_fd = -1;
+ pim_ifp->pim_sock_creation = 0;
+ pim_ifp->t_pim_sock_read = 0;
+
+ pim_ifp->t_pim_hello_timer = 0;
+ pim_ifp->pim_hello_period = PIM_DEFAULT_HELLO_PERIOD;
+ pim_ifp->pim_default_holdtime = -1; /* unset: means 3.5 * pim_hello_period */
+ pim_ifp->pim_triggered_hello_delay = PIM_DEFAULT_TRIGGERED_HELLO_DELAY;
+ pim_ifp->pim_dr_priority = PIM_DEFAULT_DR_PRIORITY;
+ pim_ifp->pim_propagation_delay_msec = PIM_DEFAULT_PROPAGATION_DELAY_MSEC;
+ pim_ifp->pim_override_interval_msec = PIM_DEFAULT_OVERRIDE_INTERVAL_MSEC;
+ if (PIM_DEFAULT_CAN_DISABLE_JOIN_SUPPRESSION) {
+ PIM_IF_DO_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options);
+ }
+ else {
+ PIM_IF_DONT_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options);
+ }
+
+ /* neighbors without lan_delay */
+ pim_ifp->pim_number_of_nonlandelay_neighbors = 0;
+ pim_ifp->pim_neighbors_highest_propagation_delay_msec = 0;
+ pim_ifp->pim_neighbors_highest_override_interval_msec = 0;
+
+ /* DR Election */
+ pim_ifp->pim_dr_election_last = 0; /* timestamp */
+ pim_ifp->pim_dr_election_count = 0;
+ pim_ifp->pim_dr_num_nondrpri_neighbors = 0; /* neighbors without dr_pri */
+ pim_ifp->pim_dr_addr = pim_ifp->primary_address;
+
+ pim_ifstat_reset(ifp);
+}
+
+int pim_msg_send(int fd,
+ struct in_addr dst,
+ char *pim_msg,
+ int pim_msg_size,
+ const char *ifname)
+{
+ ssize_t sent;
+ struct sockaddr_in to;
+ socklen_t tolen;
+
+ if (PIM_DEBUG_PIM_PACKETS) {
+ char dst_str[100];
+ pim_inet4_dump("<dst?>", dst, dst_str, sizeof(dst_str));
+ zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, pim_msg_size,
+ *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg));
+ }
+
+#if 0
+ memset(&to, 0, sizeof(to));
+#endif
+ to.sin_family = AF_INET;
+ to.sin_addr = dst;
+#if 0
+ to.sin_port = htons(0);
+#endif
+ tolen = sizeof(to);
+
+ if (PIM_DEBUG_PIM_PACKETDUMP_SEND) {
+ pim_pkt_dump(__PRETTY_FUNCTION__, pim_msg, pim_msg_size);
+ }
+
+ sent = sendto(fd, pim_msg, pim_msg_size, MSG_DONTWAIT, &to, tolen);
+ if (sent != (ssize_t) pim_msg_size) {
+ int e = errno;
+ char dst_str[100];
+ pim_inet4_dump("<dst?>", dst, dst_str, sizeof(dst_str));
+ if (sent < 0) {
+ zlog_warn("%s: sendto() failure to %s on %s: fd=%d msg_size=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, fd, pim_msg_size,
+ e, safe_strerror(e));
+ }
+ else {
+ zlog_warn("%s: sendto() partial to %s on %s: fd=%d msg_size=%d: sent=%d",
+ __PRETTY_FUNCTION__,
+ dst_str, ifname, fd,
+ pim_msg_size, sent);
+ }
+ return -1;
+ }
+
+ return 0;
+}
+
+static int hello_send(struct interface *ifp,
+ uint16_t holdtime)
+{
+ char pim_msg[PIM_PIM_BUFSIZE_WRITE];
+ struct pim_interface *pim_ifp;
+ int pim_tlv_size;
+ int pim_msg_size;
+
+ pim_ifp = ifp->info;
+
+ if (PIM_DEBUG_PIM_PACKETS) {
+ char dst_str[100];
+ pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr, dst_str, sizeof(dst_str));
+ zlog_debug("%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d",
+ __PRETTY_FUNCTION__,
+ dst_str, ifp->name,
+ holdtime,
+ pim_ifp->pim_propagation_delay_msec, pim_ifp->pim_override_interval_msec,
+ PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options),
+ pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id,
+ listcount(ifp->connected));
+ }
+
+ pim_tlv_size = pim_hello_build_tlv(ifp->name,
+ pim_msg + PIM_PIM_MIN_LEN,
+ sizeof(pim_msg) - PIM_PIM_MIN_LEN,
+ holdtime,
+ pim_ifp->pim_dr_priority,
+ pim_ifp->pim_generation_id,
+ pim_ifp->pim_propagation_delay_msec,
+ pim_ifp->pim_override_interval_msec,
+ PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp->options),
+ ifp->connected);
+ if (pim_tlv_size < 0) {
+ return -1;
+ }
+
+ pim_msg_size = pim_tlv_size + PIM_PIM_MIN_LEN;
+
+ zassert(pim_msg_size >= PIM_PIM_MIN_LEN);
+ zassert(pim_msg_size <= PIM_PIM_BUFSIZE_WRITE);
+
+ pim_msg_build_header(pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_HELLO);
+
+ if (pim_msg_send(pim_ifp->pim_sock_fd,
+ qpim_all_pim_routers_addr,
+ pim_msg,
+ pim_msg_size,
+ ifp->name)) {
+ zlog_warn("%s: could not send PIM message on interface %s",
+ __PRETTY_FUNCTION__, ifp->name);
+ return -2;
+ }
+
+ return 0;
+}
+
+static int pim_hello_send(struct interface *ifp,
+ uint16_t holdtime)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ if (hello_send(ifp, holdtime)) {
+ ++pim_ifp->pim_ifstat_hello_sendfail;
+
+ zlog_warn("Could not send PIM hello on interface %s",
+ ifp->name);
+ return -1;
+ }
+
+ ++pim_ifp->pim_ifstat_hello_sent;
+
+ return 0;
+}
+
+static void hello_resched(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_debug("Rescheduling %d sec hello on interface %s",
+ pim_ifp->pim_hello_period, ifp->name);
+ }
+ THREAD_OFF(pim_ifp->t_pim_hello_timer);
+ THREAD_TIMER_ON(master, pim_ifp->t_pim_hello_timer,
+ on_pim_hello_send,
+ ifp, pim_ifp->pim_hello_period);
+}
+
+/*
+ Periodic hello timer
+ */
+static int on_pim_hello_send(struct thread *t)
+{
+ struct pim_interface *pim_ifp;
+ struct interface *ifp;
+
+ zassert(t);
+ ifp = THREAD_ARG(t);
+ zassert(ifp);
+
+ pim_ifp = ifp->info;
+
+ /*
+ * Schedule next hello
+ */
+ pim_ifp->t_pim_hello_timer = 0;
+ hello_resched(ifp);
+
+ /*
+ * Send hello
+ */
+ return pim_hello_send(ifp, PIM_IF_DEFAULT_HOLDTIME(pim_ifp));
+}
+
+/*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ Thus, if a router needs to send a Join/Prune or Assert message on an
+ interface on which it has not yet sent a Hello message with the
+ currently configured IP address, then it MUST immediately send the
+ relevant Hello message without waiting for the Hello Timer to
+ expire, followed by the Join/Prune or Assert message.
+ */
+void pim_hello_restart_now(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ /*
+ * Reset next hello timer
+ */
+ hello_resched(ifp);
+
+ /*
+ * Immediately send hello
+ */
+ pim_hello_send(ifp, PIM_IF_DEFAULT_HOLDTIME(pim_ifp));
+}
+
+/*
+ RFC 4601: 4.3.1. Sending Hello Messages
+
+ To allow new or rebooting routers to learn of PIM neighbors quickly,
+ when a Hello message is received from a new neighbor, or a Hello
+ message with a new GenID is received from an existing neighbor, a
+ new Hello message should be sent on this interface after a
+ randomized delay between 0 and Triggered_Hello_Delay.
+ */
+void pim_hello_restart_triggered(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ int triggered_hello_delay_msec;
+ int random_msec;
+
+ zassert(ifp);
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ triggered_hello_delay_msec = 1000 * pim_ifp->pim_triggered_hello_delay;
+
+ if (pim_ifp->t_pim_hello_timer) {
+ long remain_msec = pim_time_timer_remain_msec(pim_ifp->t_pim_hello_timer);
+ if (remain_msec <= triggered_hello_delay_msec) {
+ /* Rescheduling hello would increase the delay, then it's faster
+ to just wait for the scheduled periodic hello. */
+ return;
+ }
+
+ THREAD_OFF(pim_ifp->t_pim_hello_timer);
+ pim_ifp->t_pim_hello_timer = 0;
+ }
+ zassert(!pim_ifp->t_pim_hello_timer);
+
+ random_msec = pim_rand_next(0, triggered_hello_delay_msec);
+
+ if (PIM_DEBUG_PIM_EVENTS) {
+ zlog_debug("Scheduling %d msec triggered hello on interface %s",
+ random_msec, ifp->name);
+ }
+
+ THREAD_TIMER_MSEC_ON(master, pim_ifp->t_pim_hello_timer,
+ on_pim_hello_send,
+ ifp, random_msec);
+}
+
+int pim_sock_add(struct interface *ifp)
+{
+ struct pim_interface *pim_ifp;
+ struct in_addr ifaddr;
+
+ pim_ifp = ifp->info;
+ zassert(pim_ifp);
+
+ if (pim_ifp->pim_sock_fd >= 0) {
+ zlog_warn("Can't recreate existing PIM socket fd=%d for interface %s",
+ pim_ifp->pim_sock_fd, ifp->name);
+ return -1;
+ }
+
+ ifaddr = pim_ifp->primary_address;
+
+ pim_ifp->pim_sock_fd = pim_sock_open(ifaddr, ifp->ifindex);
+ if (pim_ifp->pim_sock_fd < 0) {
+ zlog_warn("Could not open PIM socket on interface %s",
+ ifp->name);
+ return -2;
+ }
+
+ pim_ifp->t_pim_sock_read = 0;
+ pim_ifp->pim_sock_creation = pim_time_monotonic_sec();
+
+ pim_ifp->pim_generation_id = pim_rand() & (int64_t) 0xFFFFFFFF;
+
+ zlog_info("PIM INTERFACE UP: on interface %s",
+ ifp->name);
+
+ /*
+ * Start receiving PIM messages
+ */
+ pim_sock_read_on(ifp);
+
+ /*
+ * Start sending PIM hello's
+ */
+ pim_hello_restart_triggered(ifp);
+
+ return 0;
+}
diff --git a/pimd/pim_pim.h b/pimd/pim_pim.h
new file mode 100644
index 00000000..a2c8fa58
--- /dev/null
+++ b/pimd/pim_pim.h
@@ -0,0 +1,71 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_PIM_H
+#define PIM_PIM_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+#define PIM_PIM_BUFSIZE_READ (20000)
+#define PIM_PIM_BUFSIZE_WRITE (20000)
+
+#define PIM_NEXTHOP_IFINDEX_TAB_SIZE (20)
+
+#define PIM_DEFAULT_HELLO_PERIOD (30) /* seconds, RFC 4601: 4.11 */
+#define PIM_DEFAULT_TRIGGERED_HELLO_DELAY (5) /* seconds, RFC 4601: 4.11 */
+#define PIM_DEFAULT_DR_PRIORITY (1) /* RFC 4601: 4.3.1 */
+#define PIM_DEFAULT_PROPAGATION_DELAY_MSEC (500) /* RFC 4601: 4.11. Timer Values */
+#define PIM_DEFAULT_OVERRIDE_INTERVAL_MSEC (2500) /* RFC 4601: 4.11. Timer Values */
+#define PIM_DEFAULT_CAN_DISABLE_JOIN_SUPPRESSION (0) /* boolean */
+#define PIM_DEFAULT_T_PERIODIC (60) /* RFC 4601: 4.11. Timer Values */
+
+#define PIM_MSG_TYPE_HELLO (0)
+#define PIM_MSG_TYPE_JOIN_PRUNE (3)
+#define PIM_MSG_TYPE_ASSERT (5)
+
+#define PIM_MSG_HDR_OFFSET_VERSION(pim_msg) (pim_msg)
+#define PIM_MSG_HDR_OFFSET_TYPE(pim_msg) (pim_msg)
+#define PIM_MSG_HDR_OFFSET_RESERVED(pim_msg) (((char *)(pim_msg)) + 1)
+#define PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) (((char *)(pim_msg)) + 2)
+
+#define PIM_MSG_HDR_GET_VERSION(pim_msg) ((*(uint8_t*) PIM_MSG_HDR_OFFSET_VERSION(pim_msg)) >> 4)
+#define PIM_MSG_HDR_GET_TYPE(pim_msg) ((*(uint8_t*) PIM_MSG_HDR_OFFSET_TYPE(pim_msg)) & 0xF)
+#define PIM_MSG_HDR_GET_CHECKSUM(pim_msg) (*(uint16_t*) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg))
+
+void pim_ifstat_reset(struct interface *ifp);
+void pim_sock_reset(struct interface *ifp);
+int pim_sock_add(struct interface *ifp);
+void pim_sock_delete(struct interface *ifp, const char *delete_message);
+void pim_hello_restart_now(struct interface *ifp);
+void pim_hello_restart_triggered(struct interface *ifp);
+
+int pim_pim_packet(struct interface *ifp, char *buf, size_t len);
+
+int pim_msg_send(int fd,
+ struct in_addr dst,
+ char *pim_msg,
+ int pim_msg_size,
+ const char *ifname);
+
+#endif /* PIM_PIM_H */
diff --git a/pimd/pim_rand.c b/pimd/pim_rand.c
new file mode 100644
index 00000000..df2a1111
--- /dev/null
+++ b/pimd/pim_rand.c
@@ -0,0 +1,60 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include "pim_rand.h"
+#include "pim_time.h"
+
+/* Quick and dirty random number generator from NUMERICAL RECIPES IN C:
+ THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5). */
+/* BEWARE: '_qseed_' is assigned! */
+#define QRANDOM(_qseed_) ((_qseed_) = (((_qseed_) * 1664525L) + 1013904223L))
+
+static long qpim_rand_seed;
+
+void pim_rand_init()
+{
+ qpim_rand_seed = pim_time_monotonic_sec() ^ getpid();
+}
+
+long pim_rand()
+{
+ return QRANDOM(qpim_rand_seed);
+}
+
+int pim_rand_next(int min, int max)
+{
+ long rand;
+
+ assert(min <= max);
+
+ /* FIXME better random generator ? */
+
+ rand = QRANDOM(qpim_rand_seed);
+ if (rand < 0)
+ rand = -rand;
+ rand = rand % (1 + max - min) + min;
+
+ assert(rand >= min);
+ assert(rand <= max);
+
+ return rand;
+}
diff --git a/pimd/pim_rand.h b/pimd/pim_rand.h
new file mode 100644
index 00000000..a1df5054
--- /dev/null
+++ b/pimd/pim_rand.h
@@ -0,0 +1,30 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_RAND_H
+#define PIM_RAND_H
+
+void pim_rand_init(void);
+long pim_rand(void);
+int pim_rand_next(int min, int max);
+
+#endif /* PIM_RAND_H */
diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c
new file mode 100644
index 00000000..7fdeecfd
--- /dev/null
+++ b/pimd/pim_rpf.c
@@ -0,0 +1,254 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "prefix.h"
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_rpf.h"
+#include "pim_pim.h"
+#include "pim_str.h"
+#include "pim_iface.h"
+#include "pim_zlookup.h"
+#include "pim_ifchannel.h"
+
+static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up);
+
+int pim_nexthop_lookup(struct pim_nexthop *nexthop,
+ struct in_addr addr)
+{
+ struct pim_zlookup_nexthop nexthop_tab[PIM_NEXTHOP_IFINDEX_TAB_SIZE];
+ int num_ifindex;
+ struct interface *ifp;
+ int first_ifindex;
+
+ num_ifindex = zclient_lookup_nexthop(qpim_zclient_lookup, nexthop_tab,
+ PIM_NEXTHOP_IFINDEX_TAB_SIZE,
+ addr, PIM_NEXTHOP_LOOKUP_MAX);
+ if (num_ifindex < 1) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: could not find nexthop ifindex for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ addr_str);
+ return -1;
+ }
+
+ first_ifindex = nexthop_tab[0].ifindex;
+
+ if (num_ifindex > 1) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s %s: FIXME ignoring multiple nexthop ifindex'es num_ifindex=%d for address %s (using only ifindex=%d)",
+ __FILE__, __PRETTY_FUNCTION__,
+ num_ifindex, addr_str, first_ifindex);
+ /* debug warning only, do not return */
+ }
+
+ ifp = if_lookup_by_index(first_ifindex);
+ if (!ifp) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: could not find interface for ifindex %d (address %s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ first_ifindex, addr_str);
+ return -2;
+ }
+
+ if (!ifp->info) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s: multicast not enabled on input interface %s (ifindex=%d, RPF for source %s)",
+ __PRETTY_FUNCTION__,
+ ifp->name, first_ifindex, addr_str);
+ /* debug warning only, do not return */
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char nexthop_str[100];
+ char addr_str[100];
+ pim_inet4_dump("<nexthop?>", nexthop_tab[0].nexthop_addr, nexthop_str, sizeof(nexthop_str));
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s %s: found nexthop %s for address %s: interface %s ifindex=%d metric=%d pref=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ nexthop_str, addr_str,
+ ifp->name, first_ifindex,
+ nexthop_tab[0].route_metric,
+ nexthop_tab[0].protocol_distance);
+ }
+
+ /* update nextop data */
+ nexthop->interface = ifp;
+ nexthop->mrib_nexthop_addr = nexthop_tab[0].nexthop_addr;
+ nexthop->mrib_metric_preference = nexthop_tab[0].protocol_distance;
+ nexthop->mrib_route_metric = nexthop_tab[0].route_metric;
+
+ return 0;
+}
+
+static int nexthop_mismatch(const struct pim_nexthop *nh1,
+ const struct pim_nexthop *nh2)
+{
+ return (nh1->interface != nh2->interface)
+ ||
+ (nh1->mrib_nexthop_addr.s_addr != nh2->mrib_nexthop_addr.s_addr)
+ ||
+ (nh1->mrib_metric_preference != nh2->mrib_metric_preference)
+ ||
+ (nh1->mrib_route_metric != nh2->mrib_route_metric);
+}
+
+enum pim_rpf_result pim_rpf_update(struct pim_upstream *up,
+ struct in_addr *old_rpf_addr)
+{
+ struct in_addr save_rpf_addr;
+ struct pim_nexthop save_nexthop;
+ struct pim_rpf *rpf = &up->rpf;
+
+ save_nexthop = rpf->source_nexthop; /* detect change in pim_nexthop */
+ save_rpf_addr = rpf->rpf_addr; /* detect change in RPF'(S,G) */
+
+ if (pim_nexthop_lookup(&rpf->source_nexthop,
+ up->source_addr)) {
+ return PIM_RPF_FAILURE;
+ }
+
+ rpf->rpf_addr = pim_rpf_find_rpf_addr(up);
+ if (PIM_INADDR_IS_ANY(rpf->rpf_addr)) {
+ /* RPF'(S,G) not found */
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s %s: RPF'(%s,%s) not found: won't send join upstream",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str);
+ /* warning only */
+ }
+
+ /* detect change in pim_nexthop */
+ if (nexthop_mismatch(&rpf->source_nexthop, &save_nexthop)) {
+ char src_str[100];
+ char grp_str[100];
+ char nhaddr_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<addr?>", rpf->source_nexthop.mrib_nexthop_addr, nhaddr_str, sizeof(nhaddr_str));
+ zlog_warn("%s %s: (S,G)=(%s,%s) source nexthop now is: interface=%s address=%s pref=%d metric=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>",
+ nhaddr_str,
+ rpf->source_nexthop.mrib_metric_preference,
+ rpf->source_nexthop.mrib_route_metric);
+ /* warning only */
+
+ pim_upstream_update_join_desired(up);
+ pim_upstream_update_could_assert(up);
+ pim_upstream_update_my_assert_metric(up);
+ }
+
+ /* detect change in RPF_interface(S) */
+ if (save_nexthop.interface != rpf->source_nexthop.interface) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s %s: (S,G)=(%s,%s) RPF_interface(S) changed from %s to %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ save_nexthop.interface ? save_nexthop.interface->name : "<oldif?>",
+ rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<newif?>");
+ /* warning only */
+
+ pim_upstream_rpf_interface_changed(up, save_nexthop.interface);
+ }
+
+ /* detect change in RPF'(S,G) */
+ if (save_rpf_addr.s_addr != rpf->rpf_addr.s_addr) {
+
+ /* return old rpf to caller ? */
+ if (old_rpf_addr)
+ *old_rpf_addr = save_rpf_addr;
+
+ return PIM_RPF_CHANGED;
+ }
+
+ return PIM_RPF_OK;
+}
+
+/*
+ RFC 4601: 4.1.6. State Summarization Macros
+
+ neighbor RPF'(S,G) {
+ if ( I_Am_Assert_Loser(S, G, RPF_interface(S) )) {
+ return AssertWinner(S, G, RPF_interface(S) )
+ } else {
+ return NBR( RPF_interface(S), MRIB.next_hop( S ) )
+ }
+ }
+
+ RPF'(*,G) and RPF'(S,G) indicate the neighbor from which data
+ packets should be coming and to which joins should be sent on the RP
+ tree and SPT, respectively.
+*/
+static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up)
+{
+ struct pim_ifchannel *rpf_ch;
+ struct pim_neighbor *neigh;
+ struct in_addr rpf_addr;
+
+ if (!up->rpf.source_nexthop.interface) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_warn("%s: missing RPF interface for upstream (S,G)=(%s,%s)",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str);
+
+ rpf_addr.s_addr = PIM_NET_INADDR_ANY;
+ return rpf_addr;
+ }
+
+ rpf_ch = pim_ifchannel_find(up->rpf.source_nexthop.interface,
+ up->source_addr, up->group_addr);
+ if (rpf_ch) {
+ if (rpf_ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
+ return rpf_ch->ifassert_winner;
+ }
+ }
+
+ /* return NBR( RPF_interface(S), MRIB.next_hop( S ) ) */
+
+ neigh = pim_if_find_neighbor(up->rpf.source_nexthop.interface,
+ up->rpf.source_nexthop.mrib_nexthop_addr);
+ if (neigh)
+ rpf_addr = neigh->source_addr;
+ else
+ rpf_addr.s_addr = PIM_NET_INADDR_ANY;
+
+ return rpf_addr;
+}
diff --git a/pimd/pim_rpf.h b/pimd/pim_rpf.h
new file mode 100644
index 00000000..078e89f3
--- /dev/null
+++ b/pimd/pim_rpf.h
@@ -0,0 +1,36 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_RPF_H
+#define PIM_RPF_H
+
+#include <zebra.h>
+
+#include "pim_upstream.h"
+#include "pim_neighbor.h"
+
+int pim_nexthop_lookup(struct pim_nexthop *nexthop,
+ struct in_addr addr);
+enum pim_rpf_result pim_rpf_update(struct pim_upstream *up,
+ struct in_addr *old_rpf_addr);
+
+#endif /* PIM_RPF_H */
diff --git a/pimd/pim_signals.c b/pimd/pim_signals.c
new file mode 100644
index 00000000..1b146f6f
--- /dev/null
+++ b/pimd/pim_signals.c
@@ -0,0 +1,85 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <signal.h>
+
+#include <zebra.h>
+#include "sigevent.h"
+#include "log.h"
+
+#include "pim_signals.h"
+#include "pimd.h"
+
+/*
+ * Signal handlers
+ */
+
+static void pim_sighup()
+{
+ zlog_debug ("SIGHUP received, ignoring");
+}
+
+static void pim_sigint()
+{
+ zlog_notice("Terminating on signal SIGINT");
+ pim_terminate();
+ exit(1);
+}
+
+static void pim_sigterm()
+{
+ zlog_notice("Terminating on signal SIGTERM");
+ pim_terminate();
+ exit(1);
+}
+
+static void pim_sigusr1()
+{
+ zlog_debug ("SIGUSR1 received");
+ zlog_rotate (NULL);
+}
+
+struct quagga_signal_t pimd_signals[] =
+{
+ {
+ .signal = SIGHUP,
+ .handler = &pim_sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &pim_sigusr1,
+ },
+ {
+ .signal = SIGINT,
+ .handler = &pim_sigint,
+ },
+ {
+ .signal = SIGTERM,
+ .handler = &pim_sigterm,
+ },
+};
+
+void pim_signals_init()
+{
+ signal_init(master, Q_SIGC(pimd_signals), pimd_signals);
+}
+
diff --git a/pimd/pim_signals.h b/pimd/pim_signals.h
new file mode 100644
index 00000000..62523c03
--- /dev/null
+++ b/pimd/pim_signals.h
@@ -0,0 +1,28 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_SIGNALS_H
+#define PIM_SIGNALS_H
+
+void pim_signals_init(void);
+
+#endif /* PIM_SIGNALS_H */
diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c
new file mode 100644
index 00000000..2e786054
--- /dev/null
+++ b/pimd/pim_sock.c
@@ -0,0 +1,389 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include "pim_mroute.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/igmp.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <errno.h>
+
+#include <zebra.h>
+#include "log.h"
+#include "privs.h"
+
+#include "pimd.h"
+#include "pim_sock.h"
+#include "pim_str.h"
+#include "pim_igmp_join.h"
+
+/* GLOBAL VARS */
+extern struct zebra_privs_t pimd_privs;
+
+int pim_socket_raw(int protocol)
+{
+ int fd;
+
+ if ( pimd_privs.change (ZPRIVS_RAISE) )
+ zlog_err ("pim_sockek_raw: could not raise privs, %s",
+ safe_strerror (errno) );
+
+ fd = socket(AF_INET, SOCK_RAW, protocol);
+
+ if ( pimd_privs.change (ZPRIVS_LOWER) )
+ zlog_err ("pim_socket_raw: could not lower privs, %s",
+ safe_strerror (errno) );
+
+ if (fd < 0) {
+ zlog_warn("Could not create raw socket: errno=%d: %s",
+ errno, safe_strerror(errno));
+ return PIM_SOCK_ERR_SOCKET;
+ }
+
+ return fd;
+}
+
+int pim_socket_mcast(int protocol, struct in_addr ifaddr, int loop)
+{
+ int fd;
+
+ fd = pim_socket_raw(protocol);
+ if (fd < 0) {
+ zlog_warn("Could not create multicast socket: errno=%d: %s",
+ errno, safe_strerror(errno));
+ return PIM_SOCK_ERR_SOCKET;
+ }
+
+ /* Needed to obtain destination address from recvmsg() */
+ {
+#if defined(HAVE_IP_PKTINFO)
+ /* Linux IP_PKTINFO */
+ int opt = 1;
+ if (setsockopt(fd, SOL_IP, IP_PKTINFO, &opt, sizeof(opt))) {
+ zlog_warn("Could not set IP_PKTINFO on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ }
+#elif defined(HAVE_IP_RECVDSTADDR)
+ /* BSD IP_RECVDSTADDR */
+ int opt = 1;
+ if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof(opt))) {
+ zlog_warn("Could not set IP_RECVDSTADDR on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ }
+#else
+ zlog_err("%s %s: Missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()",
+ __FILE__, __PRETTY_FUNCTION__);
+ close(fd);
+ return PIM_SOCK_ERR_DSTADDR;
+#endif
+ }
+
+
+ /* Set router alert (RFC 2113) for all IGMP messages (RFC 3376 4. Message Formats)*/
+ if (protocol == IPPROTO_IGMP) {
+ char ra[4];
+ ra[0] = 148;
+ ra[1] = 4;
+ ra[2] = 0;
+ ra[3] = 0;
+ if (setsockopt(fd, IPPROTO_IP, IP_OPTIONS, ra, 4)) {
+ zlog_warn("Could not set Router Alert Option on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_RA;
+ }
+ }
+
+ {
+ int reuse = 1;
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
+ (void *) &reuse, sizeof(reuse))) {
+ zlog_warn("Could not set Reuse Address Option on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_REUSE;
+ }
+ }
+
+ {
+ const int MTTL = 1;
+ int ttl = MTTL;
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
+ (void *) &ttl, sizeof(ttl))) {
+ zlog_warn("Could not set multicast TTL=%d on socket fd=%d: errno=%d: %s",
+ MTTL, fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_TTL;
+ }
+ }
+
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
+ (void *) &loop, sizeof(loop))) {
+ zlog_warn("Could not %s Multicast Loopback Option on socket fd=%d: errno=%d: %s",
+ loop ? "enable" : "disable",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_LOOP;
+ }
+
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
+ (void *) &ifaddr, sizeof(ifaddr))) {
+ zlog_warn("Could not set Outgoing Interface Option on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_IFACE;
+ }
+
+ {
+ long flags;
+
+ flags = fcntl(fd, F_GETFL, 0);
+ if (flags < 0) {
+ zlog_warn("Could not get fcntl(F_GETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_NONBLOCK_GETFL;
+ }
+
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
+ zlog_warn("Could not set fcntl(F_SETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_NONBLOCK_SETFL;
+ }
+ }
+
+ return fd;
+}
+
+int pim_socket_join(int fd, struct in_addr group,
+ struct in_addr ifaddr, int ifindex)
+{
+ int ret;
+
+#ifdef HAVE_STRUCT_IP_MREQN_IMR_IFINDEX
+ struct ip_mreqn opt;
+#else
+ struct ip_mreq opt;
+#endif
+
+ opt.imr_multiaddr = group;
+
+#ifdef HAVE_STRUCT_IP_MREQN_IMR_IFINDEX
+ opt.imr_address = ifaddr;
+ opt.imr_ifindex = ifindex;
+#else
+ opt.imr_interface = ifaddr;
+#endif
+
+ ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &opt, sizeof(opt));
+ if (ret) {
+ char group_str[100];
+ char ifaddr_str[100];
+ if (!inet_ntop(AF_INET, &group, group_str , sizeof(group_str)))
+ sprintf(group_str, "<group?>");
+ if (!inet_ntop(AF_INET, &ifaddr, ifaddr_str , sizeof(ifaddr_str)))
+ sprintf(ifaddr_str, "<ifaddr?>");
+
+ zlog_err("Failure socket joining fd=%d group %s on interface address %s: errno=%d: %s",
+ fd, group_str, ifaddr_str, errno, safe_strerror(errno));
+ return ret;
+ }
+
+ if (PIM_DEBUG_TRACE) {
+ char group_str[100];
+ char ifaddr_str[100];
+ if (!inet_ntop(AF_INET, &group, group_str , sizeof(group_str)))
+ sprintf(group_str, "<group?>");
+ if (!inet_ntop(AF_INET, &ifaddr, ifaddr_str , sizeof(ifaddr_str)))
+ sprintf(ifaddr_str, "<ifaddr?>");
+
+ zlog_debug("Socket fd=%d joined group %s on interface address %s",
+ fd, group_str, ifaddr_str);
+ }
+
+ return ret;
+}
+
+int pim_socket_join_source(int fd, int ifindex,
+ struct in_addr group_addr,
+ struct in_addr source_addr,
+ const char *ifname)
+{
+ if (pim_igmp_join_source(fd, ifindex, group_addr, source_addr)) {
+ int e = errno;
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: setsockopt(fd=%d) failure for IGMP group %s source %s ifindex %d on interface %s: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ fd, group_str, source_str, ifindex, ifname,
+ e, safe_strerror(e));
+ return -1;
+ }
+
+ return 0;
+}
+
+int pim_socket_recvfromto(int fd, char *buf, size_t len,
+ struct sockaddr_in *from, socklen_t *fromlen,
+ struct sockaddr_in *to, socklen_t *tolen,
+ int *ifindex)
+{
+ struct msghdr msgh;
+ struct cmsghdr *cmsg;
+ struct iovec iov;
+ char cbuf[1000];
+ int err;
+
+ /*
+ * IP_PKTINFO / IP_RECVDSTADDR don't yield sin_port.
+ * Use getsockname() to get sin_port.
+ */
+ if (to) {
+ struct sockaddr_in si;
+ socklen_t si_len = sizeof(si);
+
+ ((struct sockaddr_in *) to)->sin_family = AF_INET;
+
+ if (pim_socket_getsockname(fd, (struct sockaddr *) &si, &si_len)) {
+ ((struct sockaddr_in *) to)->sin_port = ntohs(0);
+ ((struct sockaddr_in *) to)->sin_addr.s_addr = ntohl(0);
+ }
+ else {
+ ((struct sockaddr_in *) to)->sin_port = si.sin_port;
+ ((struct sockaddr_in *) to)->sin_addr = si.sin_addr;
+ }
+
+ if (tolen)
+ *tolen = sizeof(si);
+ }
+
+ memset(&msgh, 0, sizeof(struct msghdr));
+ iov.iov_base = buf;
+ iov.iov_len = len;
+ msgh.msg_control = cbuf;
+ msgh.msg_controllen = sizeof(cbuf);
+ msgh.msg_name = from;
+ msgh.msg_namelen = fromlen ? *fromlen : 0;
+ msgh.msg_iov = &iov;
+ msgh.msg_iovlen = 1;
+ msgh.msg_flags = 0;
+
+ err = recvmsg(fd, &msgh, 0);
+ if (err < 0)
+ return err;
+
+ if (fromlen)
+ *fromlen = msgh.msg_namelen;
+
+ for (cmsg = CMSG_FIRSTHDR(&msgh);
+ cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
+
+#ifdef HAVE_IP_PKTINFO
+ if ((cmsg->cmsg_level == SOL_IP) && (cmsg->cmsg_type == IP_PKTINFO)) {
+ struct in_pktinfo *i = (struct in_pktinfo *) CMSG_DATA(cmsg);
+ if (to)
+ ((struct sockaddr_in *) to)->sin_addr = i->ipi_addr;
+ if (tolen)
+ *tolen = sizeof(struct sockaddr_in);
+ if (ifindex)
+ *ifindex = i->ipi_ifindex;
+
+ if (to && PIM_DEBUG_PACKETS) {
+ char to_str[100];
+ pim_inet4_dump("<to?>", to->sin_addr, to_str, sizeof(to_str));
+ zlog_debug("%s: HAVE_IP_PKTINFO to=%s,%d",
+ __PRETTY_FUNCTION__,
+ to_str, ntohs(to->sin_port));
+ }
+
+ break;
+ }
+#endif
+
+#ifdef HAVE_IP_RECVDSTADDR
+ if ((cmsg->cmsg_level == IPPROTO_IP) && (cmsg->cmsg_type == IP_RECVDSTADDR)) {
+ struct in_addr *i = (struct in_addr *) CMSG_DATA(cmsg);
+ if (to)
+ ((struct sockaddr_in *) to)->sin_addr = *i;
+ if (tolen)
+ *tolen = sizeof(struct sockaddr_in);
+
+ if (to && PIM_DEBUG_PACKETS) {
+ char to_str[100];
+ pim_inet4_dump("<to?>", to->sin_addr, to_str, sizeof(to_str));
+ zlog_debug("%s: HAVE_IP_RECVDSTADDR to=%s,%d",
+ __PRETTY_FUNCTION__,
+ to_str, ntohs(to->sin_port));
+ }
+
+ break;
+ }
+#endif
+
+#if defined(HAVE_IP_RECVIF) && defined(CMSG_IFINDEX)
+ if (cmsg->cmsg_type == IP_RECVIF)
+ if (ifindex)
+ *ifindex = CMSG_IFINDEX(cmsg);
+#endif
+
+ } /* for (cmsg) */
+
+ return err; /* len */
+}
+
+int pim_socket_mcastloop_get(int fd)
+{
+ int loop;
+ socklen_t loop_len = sizeof(loop);
+
+ if (getsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
+ &loop, &loop_len)) {
+ int e = errno;
+ zlog_warn("Could not get Multicast Loopback Option on socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ errno = e;
+ return PIM_SOCK_ERR_LOOP;
+ }
+
+ return loop;
+}
+
+int pim_socket_getsockname(int fd, struct sockaddr *name, int *namelen)
+{
+ if (getsockname(fd, name, namelen)) {
+ int e = errno;
+ zlog_warn("Could not get Socket Name for socket fd=%d: errno=%d: %s",
+ fd, errno, safe_strerror(errno));
+ errno = e;
+ return PIM_SOCK_ERR_NAME;
+ }
+
+ return PIM_SOCK_ERR_NONE;
+}
diff --git a/pimd/pim_sock.h b/pimd/pim_sock.h
new file mode 100644
index 00000000..3f026dcd
--- /dev/null
+++ b/pimd/pim_sock.h
@@ -0,0 +1,57 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_SOCK_H
+#define PIM_SOCK_H
+
+#include <netinet/in.h>
+
+#define PIM_SOCK_ERR_NONE (0) /* No error */
+#define PIM_SOCK_ERR_SOCKET (-1) /* socket() */
+#define PIM_SOCK_ERR_RA (-2) /* Router Alert option */
+#define PIM_SOCK_ERR_REUSE (-3) /* Reuse option */
+#define PIM_SOCK_ERR_TTL (-4) /* TTL option */
+#define PIM_SOCK_ERR_LOOP (-5) /* Loopback option */
+#define PIM_SOCK_ERR_IFACE (-6) /* Outgoing interface option */
+#define PIM_SOCK_ERR_DSTADDR (-7) /* Outgoing interface option */
+#define PIM_SOCK_ERR_NONBLOCK_GETFL (-8) /* Get O_NONBLOCK */
+#define PIM_SOCK_ERR_NONBLOCK_SETFL (-9) /* Set O_NONBLOCK */
+#define PIM_SOCK_ERR_NAME (-10) /* Socket name (getsockname) */
+
+int pim_socket_raw(int protocol);
+int pim_socket_mcast(int protocol, struct in_addr ifaddr, int loop);
+int pim_socket_join(int fd, struct in_addr group,
+ struct in_addr ifaddr, int ifindex);
+int pim_socket_join_source(int fd, int ifindex,
+ struct in_addr group_addr,
+ struct in_addr source_addr,
+ const char *ifname);
+int pim_socket_recvfromto(int fd, char *buf, size_t len,
+ struct sockaddr_in *from, socklen_t *fromlen,
+ struct sockaddr_in *to, socklen_t *tolen,
+ int *ifindex);
+
+int pim_socket_mcastloop_get(int fd);
+
+int pim_socket_getsockname(int fd, struct sockaddr *name, int *namelen);
+
+#endif /* PIM_SOCK_H */
diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c
new file mode 100644
index 00000000..6422cf62
--- /dev/null
+++ b/pimd/pim_ssmpingd.c
@@ -0,0 +1,448 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "if.h"
+#include "log.h"
+#include "memory.h"
+
+#include "pim_ssmpingd.h"
+#include "pim_time.h"
+#include "pim_sock.h"
+#include "pim_str.h"
+#include "pimd.h"
+
+static const char * const PIM_SSMPINGD_REPLY_GROUP = "232.43.211.234";
+
+enum {
+ PIM_SSMPINGD_REQUEST = 'Q',
+ PIM_SSMPINGD_REPLY = 'A'
+};
+
+static void ssmpingd_read_on(struct ssmpingd_sock *ss);
+
+void pim_ssmpingd_init()
+{
+ int result;
+
+ zassert(!qpim_ssmpingd_list);
+
+ result = inet_pton(AF_INET, PIM_SSMPINGD_REPLY_GROUP, &qpim_ssmpingd_group_addr);
+
+ zassert(result > 0);
+}
+
+void pim_ssmpingd_destroy()
+{
+ if (qpim_ssmpingd_list) {
+ list_free(qpim_ssmpingd_list);
+ qpim_ssmpingd_list = 0;
+ }
+}
+
+static struct ssmpingd_sock *ssmpingd_find(struct in_addr source_addr)
+{
+ struct listnode *node;
+ struct ssmpingd_sock *ss;
+
+ if (!qpim_ssmpingd_list)
+ return 0;
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_ssmpingd_list, node, ss))
+ if (source_addr.s_addr == ss->source_addr.s_addr)
+ return ss;
+
+ return 0;
+}
+
+static void ssmpingd_free(struct ssmpingd_sock *ss)
+{
+ XFREE(MTYPE_PIM_SSMPINGD, ss);
+}
+
+static int ssmpingd_socket(struct in_addr addr, int port, int mttl)
+{
+ struct sockaddr_in sockaddr;
+ int fd;
+
+ fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0) {
+ zlog_err("%s: could not create socket: errno=%d: %s",
+ __PRETTY_FUNCTION__, errno, safe_strerror(errno));
+ return -1;
+ }
+
+ sockaddr.sin_family = AF_INET;
+ sockaddr.sin_addr = addr;
+ sockaddr.sin_port = htons(port);
+
+ if (bind(fd, &sockaddr, sizeof(sockaddr))) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s: bind(fd=%d,addr=%s,port=%d,len=%d) failure: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ fd, addr_str, port, sizeof(sockaddr),
+ errno, safe_strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ /* Needed to obtain destination address from recvmsg() */
+ {
+#if defined(HAVE_IP_PKTINFO)
+ /* Linux IP_PKTINFO */
+ int opt = 1;
+ if (setsockopt(fd, SOL_IP, IP_PKTINFO, &opt, sizeof(opt))) {
+ zlog_warn("%s: could not set IP_PKTINFO on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ }
+#elif defined(HAVE_IP_RECVDSTADDR)
+ /* BSD IP_RECVDSTADDR */
+ int opt = 1;
+ if (setsockopt(fd, IPPROTO_IP, IP_RECVDSTADDR, &opt, sizeof(opt))) {
+ zlog_warn("%s: could not set IP_RECVDSTADDR on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ }
+#else
+ zlog_err("%s %s: missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()",
+ __FILE__, __PRETTY_FUNCTION__);
+ close(fd);
+ return -1;
+#endif
+ }
+
+ {
+ int reuse = 1;
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
+ (void *) &reuse, sizeof(reuse))) {
+ zlog_warn("%s: could not set Reuse Address Option on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ close(fd);
+ return -1;
+ }
+ }
+
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
+ (void *) &mttl, sizeof(mttl))) {
+ zlog_warn("%s: could not set multicast TTL=%d on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, mttl, fd, errno, safe_strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ {
+ int loop = 0;
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
+ (void *) &loop, sizeof(loop))) {
+ zlog_warn("%s: could not %s Multicast Loopback Option on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ loop ? "enable" : "disable",
+ fd, errno, safe_strerror(errno));
+ close(fd);
+ return PIM_SOCK_ERR_LOOP;
+ }
+ }
+
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
+ (void *) &addr, sizeof(addr))) {
+ zlog_warn("%s: could not set Outgoing Interface Option on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ {
+ long flags;
+
+ flags = fcntl(fd, F_GETFL, 0);
+ if (flags < 0) {
+ zlog_warn("%s: could not get fcntl(F_GETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
+ zlog_warn("%s: could not set fcntl(F_SETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, fd, errno, safe_strerror(errno));
+ close(fd);
+ return -1;
+ }
+ }
+
+ return fd;
+}
+
+static void ssmpingd_delete(struct ssmpingd_sock *ss)
+{
+ zassert(ss);
+ zassert(qpim_ssmpingd_list);
+
+ THREAD_OFF(ss->t_sock_read);
+
+ if (close(ss->sock_fd)) {
+ int e = errno;
+ char source_str[100];
+ pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: failure closing ssmpingd sock_fd=%d for source %s: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ ss->sock_fd, source_str, e, safe_strerror(e));
+ /* warning only */
+ }
+
+ listnode_delete(qpim_ssmpingd_list, ss);
+ ssmpingd_free(ss);
+}
+
+static void ssmpingd_sendto(struct ssmpingd_sock *ss,
+ const char *buf,
+ int len,
+ struct sockaddr_in to)
+{
+ socklen_t tolen = sizeof(to);
+ int sent;
+
+ sent = sendto(ss->sock_fd, buf, len, MSG_DONTWAIT, &to, tolen);
+ if (sent != len) {
+ int e = errno;
+ char to_str[100];
+ pim_inet4_dump("<to?>", to.sin_addr, to_str, sizeof(to_str));
+ if (sent < 0) {
+ zlog_warn("%s: sendto() failure to %s,%d: fd=%d len=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ to_str, ntohs(to.sin_port), ss->sock_fd, len,
+ e, safe_strerror(e));
+ }
+ else {
+ zlog_warn("%s: sendto() partial to %s,%d: fd=%d len=%d: sent=%d",
+ __PRETTY_FUNCTION__,
+ to_str, ntohs(to.sin_port), ss->sock_fd,
+ len, sent);
+ }
+ }
+}
+
+static int ssmpingd_read_msg(struct ssmpingd_sock *ss)
+{
+ struct interface *ifp;
+ struct sockaddr_in from;
+ struct sockaddr_in to;
+ socklen_t fromlen = sizeof(from);
+ socklen_t tolen = sizeof(to);
+ int ifindex = -1;
+ char buf[1000];
+ int len;
+
+ ++ss->requests;
+
+ len = pim_socket_recvfromto(ss->sock_fd, buf, sizeof(buf),
+ &from, &fromlen,
+ &to, &tolen,
+ &ifindex);
+ if (len < 0) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: failure receiving ssmping for source %s on fd=%d: errno=%d: %s",
+ __PRETTY_FUNCTION__, source_str, ss->sock_fd, errno, safe_strerror(errno));
+ return -1;
+ }
+
+ ifp = if_lookup_by_index(ifindex);
+
+ if (buf[0] != PIM_SSMPINGD_REQUEST) {
+ char source_str[100];
+ char from_str[100];
+ char to_str[100];
+ pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<from?>", from.sin_addr, from_str, sizeof(from_str));
+ pim_inet4_dump("<to?>", to.sin_addr, to_str, sizeof(to_str));
+ zlog_warn("%s: bad ssmping type=%d from %s,%d to %s,%d on interface %s ifindex=%d fd=%d src=%s",
+ __PRETTY_FUNCTION__,
+ buf[0],
+ from_str, ntohs(from.sin_port),
+ to_str, ntohs(to.sin_port),
+ ifp ? ifp->name : "<iface?>",
+ ifindex, ss->sock_fd,
+ source_str);
+ return 0;
+ }
+
+ if (PIM_DEBUG_SSMPINGD) {
+ char source_str[100];
+ char from_str[100];
+ char to_str[100];
+ pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<from?>", from.sin_addr, from_str, sizeof(from_str));
+ pim_inet4_dump("<to?>", to.sin_addr, to_str, sizeof(to_str));
+ zlog_debug("%s: recv ssmping from %s,%d to %s,%d on interface %s ifindex=%d fd=%d src=%s",
+ __PRETTY_FUNCTION__,
+ from_str, ntohs(from.sin_port),
+ to_str, ntohs(to.sin_port),
+ ifp ? ifp->name : "<iface?>",
+ ifindex, ss->sock_fd,
+ source_str);
+ }
+
+ buf[0] = PIM_SSMPINGD_REPLY;
+
+ /* unicast reply */
+ ssmpingd_sendto(ss, buf, len, from);
+
+ /* multicast reply */
+ from.sin_addr = qpim_ssmpingd_group_addr;
+ ssmpingd_sendto(ss, buf, len, from);
+
+ return 0;
+}
+
+static int ssmpingd_sock_read(struct thread *t)
+{
+ struct ssmpingd_sock *ss;
+ int sock_fd;
+ int result;
+
+ zassert(t);
+
+ ss = THREAD_ARG(t);
+ zassert(ss);
+
+ sock_fd = THREAD_FD(t);
+ zassert(sock_fd == ss->sock_fd);
+
+ result = ssmpingd_read_msg(ss);
+
+ /* Keep reading */
+ ss->t_sock_read = 0;
+ ssmpingd_read_on(ss);
+
+ return result;
+}
+
+static void ssmpingd_read_on(struct ssmpingd_sock *ss)
+{
+ zassert(!ss->t_sock_read);
+ THREAD_READ_ON(master, ss->t_sock_read,
+ ssmpingd_sock_read, ss, ss->sock_fd);
+}
+
+static struct ssmpingd_sock *ssmpingd_new(struct in_addr source_addr)
+{
+ struct ssmpingd_sock *ss;
+ int sock_fd;
+
+ if (!qpim_ssmpingd_list) {
+ qpim_ssmpingd_list = list_new();
+ if (!qpim_ssmpingd_list) {
+ zlog_err("%s %s: failure: qpim_ssmpingd_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return 0;
+ }
+ qpim_ssmpingd_list->del = (void (*)(void *)) ssmpingd_free;
+ }
+
+ sock_fd = ssmpingd_socket(source_addr, /* port: */ 4321, /* mTTL: */ 64);
+ if (sock_fd < 0) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: ssmpingd_socket() failure for source %s",
+ __PRETTY_FUNCTION__, source_str);
+ return 0;
+ }
+
+ ss = XMALLOC(MTYPE_PIM_SSMPINGD, sizeof(*ss));
+ if (!ss) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_err("%s: XMALLOC(%d) failure for ssmpingd source %s",
+ __PRETTY_FUNCTION__,
+ sizeof(*ss), source_str);
+ close(sock_fd);
+ return 0;
+ }
+
+ ss->sock_fd = sock_fd;
+ ss->t_sock_read = 0;
+ ss->source_addr = source_addr;
+ ss->creation = pim_time_monotonic_sec();
+ ss->requests = 0;
+
+ listnode_add(qpim_ssmpingd_list, ss);
+
+ ssmpingd_read_on(ss);
+
+ return ss;
+}
+
+int pim_ssmpingd_start(struct in_addr source_addr)
+{
+ struct ssmpingd_sock *ss;
+
+ ss = ssmpingd_find(source_addr);
+ if (ss) {
+ /* silently ignore request to recreate entry */
+ return 0;
+ }
+
+ {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_info("%s: starting ssmpingd for source %s",
+ __PRETTY_FUNCTION__, source_str);
+ }
+
+ ss = ssmpingd_new(source_addr);
+ if (!ss) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: ssmpingd_new() failure for source %s",
+ __PRETTY_FUNCTION__, source_str);
+ return -1;
+ }
+
+ return 0;
+}
+
+int pim_ssmpingd_stop(struct in_addr source_addr)
+{
+ struct ssmpingd_sock *ss;
+
+ ss = ssmpingd_find(source_addr);
+ if (!ss) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s: could not find ssmpingd for source %s",
+ __PRETTY_FUNCTION__, source_str);
+ return -1;
+ }
+
+ {
+ char source_str[100];
+ pim_inet4_dump("<src?>", source_addr, source_str, sizeof(source_str));
+ zlog_info("%s: stopping ssmpingd for source %s",
+ __PRETTY_FUNCTION__, source_str);
+ }
+
+ ssmpingd_delete(ss);
+
+ return 0;
+}
diff --git a/pimd/pim_ssmpingd.h b/pimd/pim_ssmpingd.h
new file mode 100644
index 00000000..4bef20b2
--- /dev/null
+++ b/pimd/pim_ssmpingd.h
@@ -0,0 +1,45 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_SSMPINGD_H
+#define PIM_SSMPINGD_H
+
+#include <zebra.h>
+
+#include "if.h"
+
+#include "pim_iface.h"
+
+struct ssmpingd_sock {
+ int sock_fd; /* socket */
+ struct thread *t_sock_read; /* thread for reading socket */
+ struct in_addr source_addr; /* source address */
+ int64_t creation; /* timestamp of socket creation */
+ int64_t requests; /* counter */
+};
+
+void pim_ssmpingd_init(void);
+void pim_ssmpingd_destroy(void);
+int pim_ssmpingd_start(struct in_addr source_addr);
+int pim_ssmpingd_stop(struct in_addr source_addr);
+
+#endif /* PIM_SSMPINGD_H */
diff --git a/pimd/pim_str.c b/pimd/pim_str.c
new file mode 100644
index 00000000..af5a184d
--- /dev/null
+++ b/pimd/pim_str.c
@@ -0,0 +1,46 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+#include <zebra.h>
+
+#include "log.h"
+
+#include "pim_str.h"
+
+void pim_inet4_dump(const char *onfail, struct in_addr addr, char *buf, int buf_size)
+{
+ int save_errno = errno;
+
+ if (!inet_ntop(AF_INET, &addr, buf, buf_size)) {
+ int e = errno;
+ zlog_warn("pim_inet4_dump: inet_ntop(AF_INET,buf_size=%d): errno=%d: %s",
+ buf_size, e, safe_strerror(e));
+ if (onfail)
+ snprintf(buf, buf_size, "%s", onfail);
+ }
+
+ errno = save_errno;
+}
diff --git a/pimd/pim_str.h b/pimd/pim_str.h
new file mode 100644
index 00000000..925f17f7
--- /dev/null
+++ b/pimd/pim_str.h
@@ -0,0 +1,32 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_STR_H
+#define PIM_STR_H
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+void pim_inet4_dump(const char *onfail, struct in_addr addr, char *buf, int buf_size);
+
+#endif
diff --git a/pimd/pim_time.c b/pimd/pim_time.c
new file mode 100644
index 00000000..63861e5c
--- /dev/null
+++ b/pimd/pim_time.c
@@ -0,0 +1,151 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include <zebra.h>
+#include "log.h"
+#include "thread.h"
+
+#include "pim_time.h"
+
+/*
+ see man clock_gettime
+ */
+static int pim_gettime(clockid_t clk_id, struct timeval *tv)
+{
+ return quagga_gettime(clk_id, tv);
+}
+
+/*
+ pim_time_monotonic_sec():
+ number of seconds since some unspecified starting point
+*/
+int64_t pim_time_monotonic_sec()
+{
+ struct timeval now_tv;
+
+ if (pim_gettime(CLOCK_MONOTONIC, &now_tv)) {
+ zlog_err("%s: gettime(CLOCK_MONOTONIC) failure: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ errno, safe_strerror(errno));
+ return -1;
+ }
+
+ return now_tv.tv_sec;
+}
+
+/*
+ pim_time_monotonic_dsec():
+ number of deciseconds since some unspecified starting point
+*/
+int64_t pim_time_monotonic_dsec()
+{
+ struct timeval now_tv;
+ int64_t now_dsec;
+
+ if (pim_gettime(CLOCK_MONOTONIC, &now_tv)) {
+ zlog_err("%s: gettime(CLOCK_MONOTONIC) failure: errno=%d: %s",
+ __PRETTY_FUNCTION__,
+ errno, safe_strerror(errno));
+ return -1;
+ }
+
+ now_dsec = ((int64_t) now_tv.tv_sec) * 10 + ((int64_t) now_tv.tv_usec) / 100000;
+
+ return now_dsec;
+}
+
+int pim_time_mmss(char *buf, int buf_size, long sec)
+{
+ long mm;
+ int wr;
+
+ zassert(buf_size >= 5);
+
+ mm = sec / 60;
+ sec %= 60;
+
+ wr = snprintf(buf, buf_size, "%02ld:%02ld", mm, sec);
+
+ return wr != 8;
+}
+
+static int pim_time_hhmmss(char *buf, int buf_size, long sec)
+{
+ long hh;
+ long mm;
+ int wr;
+
+ zassert(buf_size >= 8);
+
+ hh = sec / 3600;
+ sec %= 3600;
+ mm = sec / 60;
+ sec %= 60;
+
+ wr = snprintf(buf, buf_size, "%02ld:%02ld:%02ld", hh, mm, sec);
+
+ return wr != 8;
+}
+
+void pim_time_timer_to_mmss(char *buf, int buf_size, struct thread *t_timer)
+{
+ if (t_timer) {
+ pim_time_mmss(buf, buf_size,
+ thread_timer_remain_second(t_timer));
+ }
+ else {
+ snprintf(buf, buf_size, "--:--");
+ }
+}
+
+void pim_time_timer_to_hhmmss(char *buf, int buf_size, struct thread *t_timer)
+{
+ if (t_timer) {
+ pim_time_hhmmss(buf, buf_size,
+ thread_timer_remain_second(t_timer));
+ }
+ else {
+ snprintf(buf, buf_size, "--:--:--");
+ }
+}
+
+void pim_time_uptime(char *buf, int buf_size, int64_t uptime_sec)
+{
+ zassert(buf_size >= 8);
+
+ pim_time_hhmmss(buf, buf_size, uptime_sec);
+}
+
+long pim_time_timer_remain_msec(struct thread *t_timer)
+{
+ /* FIXME: Actually fetch msec resolution from thread */
+
+ /* no timer thread running means timer has expired: return 0 */
+
+ return t_timer ?
+ 1000 * thread_timer_remain_second(t_timer) :
+ 0;
+}
diff --git a/pimd/pim_time.h b/pimd/pim_time.h
new file mode 100644
index 00000000..379eb6cf
--- /dev/null
+++ b/pimd/pim_time.h
@@ -0,0 +1,39 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_TIME_H
+#define PIM_TIME_H
+
+#include <stdint.h>
+
+#include <zebra.h>
+#include "thread.h"
+
+int64_t pim_time_monotonic_sec(void);
+int64_t pim_time_monotonic_dsec(void);
+int pim_time_mmss(char *buf, int buf_size, long sec);
+void pim_time_timer_to_mmss(char *buf, int buf_size, struct thread *t);
+void pim_time_timer_to_hhmmss(char *buf, int buf_size, struct thread *t);
+void pim_time_uptime(char *buf, int buf_size, int64_t uptime_sec);
+long pim_time_timer_remain_msec(struct thread *t_timer);
+
+#endif /* PIM_TIME_H */
diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c
new file mode 100644
index 00000000..16b7e93e
--- /dev/null
+++ b/pimd/pim_tlv.c
@@ -0,0 +1,726 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "prefix.h"
+
+#include "pimd.h"
+#include "pim_int.h"
+#include "pim_tlv.h"
+#include "pim_str.h"
+#include "pim_msg.h"
+
+char *pim_tlv_append_uint16(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ uint16_t option_type,
+ uint16_t option_value)
+{
+ uint16_t option_len = 2;
+
+ if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend) {
+ zlog_warn("%s: buffer overflow: left=%d needed=%d",
+ __PRETTY_FUNCTION__,
+ buf_pastend - buf, PIM_TLV_OPTION_SIZE(option_len));
+ return 0;
+ }
+
+ *(uint16_t *) buf = htons(option_type);
+ buf += 2;
+ *(uint16_t *) buf = htons(option_len);
+ buf += 2;
+ *(uint16_t *) buf = htons(option_value);
+ buf += option_len;
+
+ return buf;
+}
+
+char *pim_tlv_append_2uint16(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ uint16_t option_type,
+ uint16_t option_value1,
+ uint16_t option_value2)
+{
+ uint16_t option_len = 4;
+
+ if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend) {
+ zlog_warn("%s: buffer overflow: left=%d needed=%d",
+ __PRETTY_FUNCTION__,
+ buf_pastend - buf, PIM_TLV_OPTION_SIZE(option_len));
+ return 0;
+ }
+
+ *(uint16_t *) buf = htons(option_type);
+ buf += 2;
+ *(uint16_t *) buf = htons(option_len);
+ buf += 2;
+ *(uint16_t *) buf = htons(option_value1);
+ buf += 2;
+ *(uint16_t *) buf = htons(option_value2);
+ buf += 2;
+
+ return buf;
+}
+
+char *pim_tlv_append_uint32(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ uint16_t option_type,
+ uint32_t option_value)
+{
+ uint16_t option_len = 4;
+
+ if ((buf + PIM_TLV_OPTION_SIZE(option_len)) > buf_pastend) {
+ zlog_warn("%s: buffer overflow: left=%d needed=%d",
+ __PRETTY_FUNCTION__,
+ buf_pastend - buf, PIM_TLV_OPTION_SIZE(option_len));
+ return 0;
+ }
+
+ *(uint16_t *) buf = htons(option_type);
+ buf += 2;
+ *(uint16_t *) buf = htons(option_len);
+ buf += 2;
+ pim_write_uint32(buf, option_value);
+ buf += option_len;
+
+ return buf;
+}
+
+#define ucast_ipv4_encoding_len (2 + sizeof(struct in_addr))
+
+char *pim_tlv_append_addrlist_ucast(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ struct list *ifconnected)
+{
+ struct listnode *node;
+ uint16_t option_len = 0;
+
+ uint8_t *curr;
+
+ node = listhead(ifconnected);
+
+ /* Empty address list ? */
+ if (!node) {
+ return buf;
+ }
+
+ /* Skip first address (primary) */
+ node = listnextnode(node);
+
+ /* Scan secondary address list */
+ curr = buf + 4; /* skip T and L */
+ for (; node; node = listnextnode(node)) {
+ struct connected *ifc = listgetdata(node);
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ if ((curr + ucast_ipv4_encoding_len) > buf_pastend) {
+ zlog_warn("%s: buffer overflow: left=%d needed=%d",
+ __PRETTY_FUNCTION__,
+ buf_pastend - curr, ucast_ipv4_encoding_len);
+ return 0;
+ }
+
+ /* Write encoded unicast IPv4 address */
+ *(uint8_t *) curr = PIM_MSG_ADDRESS_FAMILY_IPV4; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
+ ++curr;
+ *(uint8_t *) curr = 0; /* ucast IPv4 native encoding type (RFC 4601: 4.9.1) */
+ ++curr;
+ *(struct in_addr *) curr = p->u.prefix4;
+ curr += sizeof(struct in_addr);
+
+ option_len += ucast_ipv4_encoding_len;
+ }
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ zlog_warn("%s: number of encoded secondary unicast IPv4 addresses: %d",
+ __PRETTY_FUNCTION__,
+ option_len / ucast_ipv4_encoding_len);
+ }
+
+ if (option_len < 1) {
+ /* Empty secondary unicast IPv4 address list */
+ return buf;
+ }
+
+ /*
+ * Write T and L
+ */
+ *(uint16_t *) buf = htons(PIM_MSG_OPTION_TYPE_ADDRESS_LIST);
+ *(uint16_t *) (buf + 2) = htons(option_len);
+
+ return curr;
+}
+
+static int check_tlv_length(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ int correct_len, int option_len)
+{
+ if (option_len != correct_len) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: PIM hello %s TLV with incorrect value size=%d correct=%d from %s on interface %s",
+ label, tlv_name,
+ option_len, correct_len,
+ src_str, ifname);
+ return -1;
+ }
+
+ return 0;
+}
+
+static void check_tlv_redefinition_uint16(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ pim_hello_options options,
+ pim_hello_options opt_mask,
+ uint16_t new, uint16_t old)
+{
+ if (PIM_OPTION_IS_SET(options, opt_mask)) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: PIM hello TLV redefined %s=%u old=%u from %s on interface %s",
+ label, tlv_name,
+ new, old,
+ src_str, ifname);
+ }
+}
+
+static void check_tlv_redefinition_uint32(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ pim_hello_options options,
+ pim_hello_options opt_mask,
+ uint32_t new, uint32_t old)
+{
+ if (PIM_OPTION_IS_SET(options, opt_mask)) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: PIM hello TLV redefined %s=%u old=%u from %s on interface %s",
+ label, tlv_name,
+ new, old,
+ src_str, ifname);
+ }
+}
+
+static void check_tlv_redefinition_uint32_hex(const char *label, const char *tlv_name,
+ const char *ifname, struct in_addr src_addr,
+ pim_hello_options options,
+ pim_hello_options opt_mask,
+ uint32_t new, uint32_t old)
+{
+ if (PIM_OPTION_IS_SET(options, opt_mask)) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: PIM hello TLV redefined %s=%08x old=%08x from %s on interface %s",
+ label, tlv_name,
+ new, old,
+ src_str, ifname);
+ }
+}
+
+int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint16_t *hello_option_holdtime,
+ uint16_t option_len,
+ const char *tlv_curr)
+{
+ const char *label = "holdtime";
+
+ if (check_tlv_length(__PRETTY_FUNCTION__, label,
+ ifname, src_addr,
+ sizeof(uint16_t), option_len)) {
+ return -1;
+ }
+
+ check_tlv_redefinition_uint16(__PRETTY_FUNCTION__, label,
+ ifname, src_addr,
+ *hello_options, PIM_OPTION_MASK_HOLDTIME,
+ PIM_TLV_GET_HOLDTIME(tlv_curr),
+ *hello_option_holdtime);
+
+ PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_HOLDTIME);
+
+ *hello_option_holdtime = PIM_TLV_GET_HOLDTIME(tlv_curr);
+
+ return 0;
+}
+
+int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint16_t *hello_option_propagation_delay,
+ uint16_t *hello_option_override_interval,
+ uint16_t option_len,
+ const char *tlv_curr)
+{
+ if (check_tlv_length(__PRETTY_FUNCTION__, "lan_prune_delay",
+ ifname, src_addr,
+ sizeof(uint32_t), option_len)) {
+ return -1;
+ }
+
+ check_tlv_redefinition_uint16(__PRETTY_FUNCTION__, "propagation_delay",
+ ifname, src_addr,
+ *hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY,
+ PIM_TLV_GET_PROPAGATION_DELAY(tlv_curr),
+ *hello_option_propagation_delay);
+
+ PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY);
+
+ *hello_option_propagation_delay = PIM_TLV_GET_PROPAGATION_DELAY(tlv_curr);
+ if (PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(tlv_curr)) {
+ PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION);
+ }
+ else {
+ PIM_OPTION_UNSET(*hello_options, PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION);
+ }
+ ++tlv_curr;
+ ++tlv_curr;
+ *hello_option_override_interval = PIM_TLV_GET_OVERRIDE_INTERVAL(tlv_curr);
+
+ return 0;
+}
+
+int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint32_t *hello_option_dr_priority,
+ uint16_t option_len,
+ const char *tlv_curr)
+{
+ const char *label = "dr_priority";
+
+ if (check_tlv_length(__PRETTY_FUNCTION__, label,
+ ifname, src_addr,
+ sizeof(uint32_t), option_len)) {
+ return -1;
+ }
+
+ check_tlv_redefinition_uint32(__PRETTY_FUNCTION__, label,
+ ifname, src_addr,
+ *hello_options, PIM_OPTION_MASK_DR_PRIORITY,
+ PIM_TLV_GET_DR_PRIORITY(tlv_curr),
+ *hello_option_dr_priority);
+
+ PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_DR_PRIORITY);
+
+ *hello_option_dr_priority = PIM_TLV_GET_DR_PRIORITY(tlv_curr);
+
+ return 0;
+}
+
+int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint32_t *hello_option_generation_id,
+ uint16_t option_len,
+ const char *tlv_curr)
+{
+ const char *label = "generation_id";
+
+ if (check_tlv_length(__PRETTY_FUNCTION__, label,
+ ifname, src_addr,
+ sizeof(uint32_t), option_len)) {
+ return -1;
+ }
+
+ check_tlv_redefinition_uint32_hex(__PRETTY_FUNCTION__, label,
+ ifname, src_addr,
+ *hello_options, PIM_OPTION_MASK_GENERATION_ID,
+ PIM_TLV_GET_GENERATION_ID(tlv_curr),
+ *hello_option_generation_id);
+
+ PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_GENERATION_ID);
+
+ *hello_option_generation_id = PIM_TLV_GET_GENERATION_ID(tlv_curr);
+
+ return 0;
+}
+
+int pim_parse_addr_ucast(const char *ifname, struct in_addr src_addr,
+ struct prefix *p,
+ const char *buf,
+ int buf_size)
+{
+ const int ucast_encoding_min_len = 3; /* 1 family + 1 type + 1 addr */
+ const char *addr;
+ const char *pastend;
+ int family;
+ int type;
+
+ if (buf_size < ucast_encoding_min_len) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unicast address encoding overflow: left=%d needed=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ buf_size, ucast_encoding_min_len,
+ src_str, ifname);
+ return -1;
+ }
+
+ addr = buf;
+ pastend = buf + buf_size;
+
+ family = *(const uint8_t *) addr;
+ ++addr;
+ type = *(const uint8_t *) addr;
+ ++addr;
+
+ switch (family) {
+ case PIM_MSG_ADDRESS_FAMILY_IPV4:
+ if (type) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unknown unicast address encoding type=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ type, src_str, ifname);
+ return -2;
+ }
+
+ if ((addr + sizeof(struct in_addr)) > pastend) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: IPv4 unicast address overflow: left=%d needed=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ pastend - addr, sizeof(struct in_addr),
+ src_str, ifname);
+ return -3;
+ }
+
+ p->family = AF_INET; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
+ p->u.prefix4 = *(const struct in_addr *) addr;
+ addr += sizeof(struct in_addr);
+
+ break;
+ default:
+ {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unknown unicast address encoding family=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ family, src_str, ifname);
+ return -4;
+ }
+ }
+
+ return addr - buf;
+}
+
+int pim_parse_addr_group(const char *ifname, struct in_addr src_addr,
+ struct prefix *p,
+ const char *buf,
+ int buf_size)
+{
+ const int grp_encoding_min_len = 4; /* 1 family + 1 type + 1 reserved + 1 addr */
+ const char *addr;
+ const char *pastend;
+ int family;
+ int type;
+ int mask_len;
+
+ if (buf_size < grp_encoding_min_len) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: group address encoding overflow: left=%d needed=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ buf_size, grp_encoding_min_len,
+ src_str, ifname);
+ return -1;
+ }
+
+ addr = buf;
+ pastend = buf + buf_size;
+
+ family = *(const uint8_t *) addr;
+ ++addr;
+ type = *(const uint8_t *) addr;
+ ++addr;
+ ++addr; /* skip b_reserved_z fields */
+ mask_len = *(const uint8_t *) addr;
+ ++addr;
+
+ switch (family) {
+ case PIM_MSG_ADDRESS_FAMILY_IPV4:
+ if (type) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unknown group address encoding type=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ type, src_str, ifname);
+ return -2;
+ }
+
+ if ((addr + sizeof(struct in_addr)) > pastend) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: IPv4 group address overflow: left=%d needed=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ pastend - addr, sizeof(struct in_addr),
+ src_str, ifname);
+ return -3;
+ }
+
+ p->family = AF_INET; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
+ p->u.prefix4 = *(const struct in_addr *) addr;
+ p->prefixlen = mask_len;
+
+ addr += sizeof(struct in_addr);
+
+ break;
+ default:
+ {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unknown group address encoding family=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ family, src_str, ifname);
+ return -4;
+ }
+ }
+
+ return addr - buf;
+}
+
+int pim_parse_addr_source(const char *ifname,
+ struct in_addr src_addr,
+ struct prefix *p,
+ uint8_t *flags,
+ const char *buf,
+ int buf_size)
+{
+ const int src_encoding_min_len = 4; /* 1 family + 1 type + 1 reserved + 1 addr */
+ const char *addr;
+ const char *pastend;
+ int family;
+ int type;
+ int mask_len;
+
+ if (buf_size < src_encoding_min_len) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: source address encoding overflow: left=%d needed=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ buf_size, src_encoding_min_len,
+ src_str, ifname);
+ return -1;
+ }
+
+ addr = buf;
+ pastend = buf + buf_size;
+
+ family = *(const uint8_t *) addr;
+ ++addr;
+ type = *(const uint8_t *) addr;
+ ++addr;
+ *flags = *(const uint8_t *) addr;
+ ++addr;
+ mask_len = *(const uint8_t *) addr;
+ ++addr;
+
+ switch (family) {
+ case PIM_MSG_ADDRESS_FAMILY_IPV4:
+ if (type) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unknown source address encoding type=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ type, src_str, ifname);
+ return -2;
+ }
+
+ if ((addr + sizeof(struct in_addr)) > pastend) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: IPv4 source address overflow: left=%d needed=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ pastend - addr, sizeof(struct in_addr),
+ src_str, ifname);
+ return -3;
+ }
+
+ p->family = AF_INET; /* notice: AF_INET != PIM_MSG_ADDRESS_FAMILY_IPV4 */
+ p->u.prefix4 = *(const struct in_addr *) addr;
+ p->prefixlen = mask_len;
+
+ /*
+ RFC 4601: 4.9.1 Encoded Source and Group Address Formats
+
+ Encoded-Source Address
+
+ The mask length MUST be equal to the mask length in bits for
+ the given Address Family and Encoding Type (32 for IPv4 native
+ and 128 for IPv6 native). A router SHOULD ignore any messages
+ received with any other mask length.
+ */
+ if (p->prefixlen != 32) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", p->u.prefix4, src_str, sizeof(src_str));
+ zlog_warn("%s: IPv4 bad source address mask: %s/%d",
+ __PRETTY_FUNCTION__, src_str, p->prefixlen);
+ return -4;
+ }
+
+ addr += sizeof(struct in_addr);
+
+ break;
+ default:
+ {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: unknown source address encoding family=%d from %s on %s",
+ __PRETTY_FUNCTION__,
+ family, src_str, ifname);
+ return -5;
+ }
+ }
+
+ return addr - buf;
+}
+
+#define FREE_ADDR_LIST(hello_option_addr_list) \
+{ \
+ if (hello_option_addr_list) { \
+ list_delete(hello_option_addr_list); \
+ hello_option_addr_list = 0; \
+ } \
+}
+
+int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ struct list **hello_option_addr_list,
+ uint16_t option_len,
+ const char *tlv_curr)
+{
+ const char *addr;
+ const char *pastend;
+
+ zassert(hello_option_addr_list);
+
+ /*
+ Scan addr list
+ */
+ addr = tlv_curr;
+ pastend = tlv_curr + option_len;
+ while (addr < pastend) {
+ struct prefix tmp;
+ int addr_offset;
+
+ /*
+ Parse ucast addr
+ */
+ addr_offset = pim_parse_addr_ucast(ifname, src_addr, &tmp,
+ addr, pastend - addr);
+ if (addr_offset < 1) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifname);
+ FREE_ADDR_LIST(*hello_option_addr_list);
+ return -1;
+ }
+ addr += addr_offset;
+
+ /*
+ Debug
+ */
+ if (PIM_DEBUG_PIM_TRACE) {
+ switch (tmp.family) {
+ case AF_INET:
+ {
+ char addr_str[100];
+ char src_str[100];
+ pim_inet4_dump("<addr?>", tmp.u.prefix4, addr_str, sizeof(addr_str));
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello TLV option: list_old_size=%d IPv4 address %s from %s on %s",
+ __PRETTY_FUNCTION__,
+ *hello_option_addr_list ?
+ ((int) listcount(*hello_option_addr_list)) : -1,
+ addr_str, src_str, ifname);
+ }
+ break;
+ default:
+ {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_debug("%s: PIM hello TLV option: list_old_size=%d UNKNOWN address family from %s on %s",
+ __PRETTY_FUNCTION__,
+ *hello_option_addr_list ?
+ ((int) listcount(*hello_option_addr_list)) : -1,
+ src_str, ifname);
+ }
+ }
+ }
+
+ /*
+ Exclude neighbor's primary address if incorrectly included in
+ the secondary address list
+ */
+ if (tmp.family == AF_INET) {
+ if (tmp.u.prefix4.s_addr == src_addr.s_addr) {
+ char src_str[100];
+ pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str));
+ zlog_warn("%s: ignoring primary address in secondary list from %s on %s",
+ __PRETTY_FUNCTION__,
+ src_str, ifname);
+ continue;
+ }
+ }
+
+ /*
+ Allocate list if needed
+ */
+ if (!*hello_option_addr_list) {
+ *hello_option_addr_list = list_new();
+ if (!*hello_option_addr_list) {
+ zlog_err("%s %s: failure: hello_option_addr_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return -2;
+ }
+ (*hello_option_addr_list)->del = (void (*)(void *)) prefix_free;
+ }
+
+ /*
+ Attach addr to list
+ */
+ {
+ struct prefix *p;
+ p = prefix_new();
+ if (!p) {
+ zlog_err("%s %s: failure: prefix_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ FREE_ADDR_LIST(*hello_option_addr_list);
+ return -3;
+ }
+ p->family = tmp.family;
+ p->u.prefix4 = tmp.u.prefix4;
+ listnode_add(*hello_option_addr_list, p);
+ }
+
+ } /* while (addr < pastend) */
+
+ /*
+ Mark hello option
+ */
+ PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_ADDRESS_LIST);
+
+ return 0;
+}
diff --git a/pimd/pim_tlv.h b/pimd/pim_tlv.h
new file mode 100644
index 00000000..5ec3dc43
--- /dev/null
+++ b/pimd/pim_tlv.h
@@ -0,0 +1,133 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_TLV_H
+#define PIM_TLV_H
+
+#include <zebra.h>
+
+#include "config.h"
+#include "if.h"
+#include "linklist.h"
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif /* HAVE_INTTYPES_H */
+
+#define PIM_MSG_OPTION_TYPE_HOLDTIME (1)
+#define PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY (2)
+#define PIM_MSG_OPTION_TYPE_DR_PRIORITY (19)
+#define PIM_MSG_OPTION_TYPE_GENERATION_ID (20)
+#define PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH (21)
+#define PIM_MSG_OPTION_TYPE_ADDRESS_LIST (24)
+
+typedef uint32_t pim_hello_options;
+#define PIM_OPTION_MASK_HOLDTIME (1 << 0) /* recv holdtime */
+#define PIM_OPTION_MASK_LAN_PRUNE_DELAY (1 << 1) /* recv lan_prune_delay */
+#define PIM_OPTION_MASK_DR_PRIORITY (1 << 2) /* recv dr_priority */
+#define PIM_OPTION_MASK_GENERATION_ID (1 << 3) /* recv generation_id */
+#define PIM_OPTION_MASK_ADDRESS_LIST (1 << 4) /* recv secondary address list */
+#define PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION (1 << 5) /* T bit value (valid if recv lan_prune_delay) */
+
+#define PIM_RPT_BIT_MASK (1 << 0)
+#define PIM_WILDCARD_BIT_MASK (1 << 1)
+
+#define PIM_OPTION_SET(options, option_mask) ((options) |= (option_mask))
+#define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask))
+#define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask))
+
+#define PIM_TLV_GET_UINT16(buf) ntohs(*(const uint16_t *)(buf))
+#define PIM_TLV_GET_UINT32(buf) ntohl(*(const uint32_t *)(buf))
+#define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf)
+#define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf)
+#define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf)
+#define PIM_TLV_GET_PROPAGATION_DELAY(buf) (PIM_TLV_GET_UINT16(buf) & 0x7FFF)
+#define PIM_TLV_GET_OVERRIDE_INTERVAL(buf) PIM_TLV_GET_UINT16(buf)
+#define PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(buf) ((*(const uint8_t *)(buf)) & 0x80)
+#define PIM_TLV_GET_DR_PRIORITY(buf) PIM_TLV_GET_UINT32(buf)
+#define PIM_TLV_GET_GENERATION_ID(buf) PIM_TLV_GET_UINT32(buf)
+
+#define PIM_TLV_TYPE_SIZE (2)
+#define PIM_TLV_LENGTH_SIZE (2)
+#define PIM_TLV_MIN_SIZE (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE)
+#define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len))
+
+char *pim_tlv_append_uint16(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ uint16_t option_type,
+ uint16_t option_value);
+char *pim_tlv_append_2uint16(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ uint16_t option_type,
+ uint16_t option_value1,
+ uint16_t option_value2);
+char *pim_tlv_append_uint32(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ uint16_t option_type,
+ uint32_t option_value);
+char *pim_tlv_append_addrlist_ucast(uint8_t *buf,
+ const uint8_t *buf_pastend,
+ struct list *ifconnected);
+
+int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint16_t *hello_option_holdtime,
+ uint16_t option_len,
+ const char *tlv_curr);
+int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint16_t *hello_option_propagation_delay,
+ uint16_t *hello_option_override_interval,
+ uint16_t option_len,
+ const char *tlv_curr);
+int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint32_t *hello_option_dr_priority,
+ uint16_t option_len,
+ const char *tlv_curr);
+int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ uint32_t *hello_option_generation_id,
+ uint16_t option_len,
+ const char *tlv_curr);
+int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr,
+ pim_hello_options *hello_options,
+ struct list **hello_option_addr_list,
+ uint16_t option_len,
+ const char *tlv_curr);
+
+int pim_parse_addr_ucast(const char *ifname, struct in_addr src_addr,
+ struct prefix *p,
+ const char *buf,
+ int buf_size);
+int pim_parse_addr_group(const char *ifname, struct in_addr src_addr,
+ struct prefix *p,
+ const char *buf,
+ int buf_size);
+int pim_parse_addr_source(const char *ifname,
+ struct in_addr src_addr,
+ struct prefix *p,
+ uint8_t *flags,
+ const char *buf,
+ int buf_size);
+
+#endif /* PIM_TLV_H */
diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c
new file mode 100644
index 00000000..b9cf1e52
--- /dev/null
+++ b/pimd/pim_upstream.c
@@ -0,0 +1,686 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "zebra/rib.h"
+
+#include "log.h"
+#include "zclient.h"
+#include "memory.h"
+#include "thread.h"
+#include "linklist.h"
+
+#include "pimd.h"
+#include "pim_pim.h"
+#include "pim_str.h"
+#include "pim_time.h"
+#include "pim_iface.h"
+#include "pim_join.h"
+#include "pim_zlookup.h"
+#include "pim_upstream.h"
+#include "pim_ifchannel.h"
+#include "pim_neighbor.h"
+#include "pim_rpf.h"
+#include "pim_zebra.h"
+#include "pim_oil.h"
+#include "pim_macro.h"
+
+static void join_timer_start(struct pim_upstream *up);
+static void pim_upstream_update_assert_tracking_desired(struct pim_upstream *up);
+
+void pim_upstream_free(struct pim_upstream *up)
+{
+ XFREE(MTYPE_PIM_UPSTREAM, up);
+}
+
+static void upstream_channel_oil_detach(struct pim_upstream *up)
+{
+ if (up->channel_oil) {
+ pim_channel_oil_del(up->channel_oil);
+ up->channel_oil = 0;
+ }
+}
+
+void pim_upstream_delete(struct pim_upstream *up)
+{
+ THREAD_OFF(up->t_join_timer);
+
+ upstream_channel_oil_detach(up);
+
+ /*
+ notice that listnode_delete() can't be moved
+ into pim_upstream_free() because the later is
+ called by list_delete_all_node()
+ */
+ listnode_delete(qpim_upstream_list, up);
+
+ pim_upstream_free(up);
+}
+
+static void send_join(struct pim_upstream *up)
+{
+ zassert(up->join_state == PIM_UPSTREAM_JOINED);
+
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ if (PIM_INADDR_IS_ANY(up->rpf.rpf_addr)) {
+ char src_str[100];
+ char grp_str[100];
+ char rpf_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<rpf?>", up->rpf.rpf_addr, rpf_str, sizeof(rpf_str));
+ zlog_warn("%s: can't send join upstream: RPF'(%s,%s)=%s",
+ __PRETTY_FUNCTION__,
+ src_str, grp_str, rpf_str);
+ /* warning only */
+ }
+ }
+
+ /* send Join(S,G) to the current upstream neighbor */
+ pim_joinprune_send(up->rpf.source_nexthop.interface,
+ up->rpf.rpf_addr,
+ up->source_addr,
+ up->group_addr,
+ 1 /* join */);
+}
+
+static int on_join_timer(struct thread *t)
+{
+ struct pim_upstream *up;
+
+ zassert(t);
+ up = THREAD_ARG(t);
+ zassert(up);
+
+ send_join(up);
+
+ up->t_join_timer = 0;
+ join_timer_start(up);
+
+ return 0;
+}
+
+static void join_timer_start(struct pim_upstream *up)
+{
+ if (PIM_DEBUG_PIM_EVENTS) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: starting %d sec timer for upstream (S,G)=(%s,%s)",
+ __PRETTY_FUNCTION__,
+ qpim_t_periodic,
+ src_str, grp_str);
+ }
+
+ zassert(!up->t_join_timer);
+
+ THREAD_TIMER_ON(master, up->t_join_timer,
+ on_join_timer,
+ up, qpim_t_periodic);
+}
+
+void pim_upstream_join_timer_restart(struct pim_upstream *up)
+{
+ THREAD_OFF(up->t_join_timer);
+ join_timer_start(up);
+}
+
+static void pim_upstream_join_timer_restart_msec(struct pim_upstream *up,
+ int interval_msec)
+{
+ if (PIM_DEBUG_PIM_EVENTS) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: restarting %d msec timer for upstream (S,G)=(%s,%s)",
+ __PRETTY_FUNCTION__,
+ interval_msec,
+ src_str, grp_str);
+ }
+
+ THREAD_OFF(up->t_join_timer);
+ THREAD_TIMER_MSEC_ON(master, up->t_join_timer,
+ on_join_timer,
+ up, interval_msec);
+}
+
+void pim_upstream_join_suppress(struct pim_upstream *up,
+ struct in_addr rpf_addr,
+ int holdtime)
+{
+ long t_joinsuppress_msec;
+ long join_timer_remain_msec;
+
+ t_joinsuppress_msec = MIN(pim_if_t_suppressed_msec(up->rpf.source_nexthop.interface),
+ 1000 * holdtime);
+
+ join_timer_remain_msec = pim_time_timer_remain_msec(up->t_join_timer);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char grp_str[100];
+ char rpf_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<rpf?>", rpf_addr, rpf_str, sizeof(rpf_str));
+ zlog_debug("%s %s: detected Join(%s,%s) to RPF'(S,G)=%s: join_timer=%ld msec t_joinsuppress=%ld msec",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str,
+ rpf_str,
+ join_timer_remain_msec, t_joinsuppress_msec);
+ }
+
+ if (join_timer_remain_msec < t_joinsuppress_msec) {
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s %s: suppressing Join(S,G)=(%s,%s) for %ld msec",
+ __FILE__, __PRETTY_FUNCTION__,
+ src_str, grp_str, t_joinsuppress_msec);
+ }
+
+ pim_upstream_join_timer_restart_msec(up, t_joinsuppress_msec);
+ }
+}
+
+void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label,
+ struct pim_upstream *up,
+ struct in_addr rpf_addr)
+{
+ long join_timer_remain_msec;
+ int t_override_msec;
+
+ join_timer_remain_msec = pim_time_timer_remain_msec(up->t_join_timer);
+ t_override_msec = pim_if_t_override_msec(up->rpf.source_nexthop.interface);
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char grp_str[100];
+ char rpf_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<rpf?>", rpf_addr, rpf_str, sizeof(rpf_str));
+ zlog_debug("%s: to RPF'(%s,%s)=%s: join_timer=%ld msec t_override=%d msec",
+ debug_label,
+ src_str, grp_str, rpf_str,
+ join_timer_remain_msec, t_override_msec);
+ }
+
+ if (join_timer_remain_msec > t_override_msec) {
+ if (PIM_DEBUG_PIM_TRACE) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: decreasing (S,G)=(%s,%s) join timer to t_override=%d msec",
+ debug_label,
+ src_str, grp_str,
+ t_override_msec);
+ }
+
+ pim_upstream_join_timer_restart_msec(up, t_override_msec);
+ }
+}
+
+static void forward_on(struct pim_upstream *up)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+ struct in_addr ifaddr;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ ifaddr = pim_ifp->primary_address;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+
+ if (ch->upstream != up)
+ continue;
+
+ if (pim_macro_chisin_oiflist(ch))
+ pim_forward_start(ch);
+
+ } /* scan iface channel list */
+ } /* scan iflist */
+}
+
+static void forward_off(struct pim_upstream *up)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+
+ if (ch->upstream != up)
+ continue;
+
+ pim_forward_stop(ch);
+
+ } /* scan iface channel list */
+ } /* scan iflist */
+}
+
+static void pim_upstream_switch(struct pim_upstream *up,
+ enum pim_upstream_state new_state)
+{
+ enum pim_upstream_state old_state = up->join_state;
+
+ zassert(old_state != new_state);
+
+ up->join_state = new_state;
+ up->state_transition = pim_time_monotonic_sec();
+
+ if (PIM_DEBUG_PIM_EVENTS) {
+ char src_str[100];
+ char grp_str[100];
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ zlog_debug("%s: PIM_UPSTREAM_%s: (S,G)=(%s,%s)",
+ __PRETTY_FUNCTION__,
+ ((new_state == PIM_UPSTREAM_JOINED) ? "JOINED" : "NOTJOINED"),
+ src_str, grp_str);
+ }
+
+ pim_upstream_update_assert_tracking_desired(up);
+
+ if (new_state == PIM_UPSTREAM_JOINED) {
+ forward_on(up);
+ send_join(up);
+ join_timer_start(up);
+ }
+ else {
+ forward_off(up);
+ pim_joinprune_send(up->rpf.source_nexthop.interface,
+ up->rpf.rpf_addr,
+ up->source_addr,
+ up->group_addr,
+ 0 /* prune */);
+ zassert(up->t_join_timer);
+ THREAD_OFF(up->t_join_timer);
+ }
+
+}
+
+static struct pim_upstream *pim_upstream_new(struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_upstream *up;
+
+ up = XMALLOC(MTYPE_PIM_UPSTREAM, sizeof(*up));
+ if (!up) {
+ zlog_err("%s: PIM XMALLOC(%d) failure",
+ __PRETTY_FUNCTION__, sizeof(*up));
+ return 0;
+ }
+
+ up->source_addr = source_addr;
+ up->group_addr = group_addr;
+ up->flags = 0;
+ up->ref_count = 1;
+ up->t_join_timer = 0;
+ up->join_state = 0;
+ up->state_transition = pim_time_monotonic_sec();
+ up->channel_oil = 0;
+
+ up->rpf.source_nexthop.interface = 0;
+ up->rpf.source_nexthop.mrib_nexthop_addr.s_addr = PIM_NET_INADDR_ANY;
+ up->rpf.source_nexthop.mrib_metric_preference = qpim_infinite_assert_metric.metric_preference;
+ up->rpf.source_nexthop.mrib_route_metric = qpim_infinite_assert_metric.route_metric;
+ up->rpf.rpf_addr.s_addr = PIM_NET_INADDR_ANY;
+
+ pim_rpf_update(up, 0);
+
+ listnode_add(qpim_upstream_list, up);
+
+ return up;
+}
+
+struct pim_upstream *pim_upstream_find(struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct listnode *up_node;
+ struct pim_upstream *up;
+
+ for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, up_node, up)) {
+ if (
+ (source_addr.s_addr == up->source_addr.s_addr) &&
+ (group_addr.s_addr == up->group_addr.s_addr)
+ ) {
+ return up;
+ }
+ }
+
+ return 0;
+}
+
+struct pim_upstream *pim_upstream_add(struct in_addr source_addr,
+ struct in_addr group_addr)
+{
+ struct pim_upstream *up;
+
+ up = pim_upstream_find(source_addr, group_addr);
+ if (up) {
+ ++up->ref_count;
+ }
+ else {
+ up = pim_upstream_new(source_addr, group_addr);
+ }
+
+ return up;
+}
+
+void pim_upstream_del(struct pim_upstream *up)
+{
+ --up->ref_count;
+
+ if (up->ref_count < 1) {
+ pim_upstream_delete(up);
+ }
+}
+
+/*
+ Evaluate JoinDesired(S,G):
+
+ JoinDesired(S,G) is true if there is a downstream (S,G) interface I
+ in the set:
+
+ inherited_olist(S,G) =
+ joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
+
+ JoinDesired(S,G) may be affected by changes in the following:
+
+ pim_ifp->primary_address
+ pim_ifp->pim_dr_addr
+ ch->ifassert_winner_metric
+ ch->ifassert_winner
+ ch->local_ifmembership
+ ch->ifjoin_state
+ ch->upstream->rpf.source_nexthop.mrib_metric_preference
+ ch->upstream->rpf.source_nexthop.mrib_route_metric
+ ch->upstream->rpf.source_nexthop.interface
+
+ See also pim_upstream_update_join_desired() below.
+ */
+int pim_upstream_evaluate_join_desired(struct pim_upstream *up)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+ if (ch->upstream != up)
+ continue;
+
+ if (pim_macro_ch_lost_assert(ch))
+ continue; /* keep searching */
+
+ if (pim_macro_chisin_joins_or_include(ch))
+ return 1; /* true */
+ } /* scan iface channel list */
+ } /* scan iflist */
+
+ return 0; /* false */
+}
+
+/*
+ See also pim_upstream_evaluate_join_desired() above.
+*/
+void pim_upstream_update_join_desired(struct pim_upstream *up)
+{
+ int was_join_desired; /* boolean */
+ int is_join_desired; /* boolean */
+
+ was_join_desired = PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags);
+
+ is_join_desired = pim_upstream_evaluate_join_desired(up);
+ if (is_join_desired)
+ PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED(up->flags);
+ else
+ PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED(up->flags);
+
+ /* switched from false to true */
+ if (is_join_desired && !was_join_desired) {
+ zassert(up->join_state == PIM_UPSTREAM_NOTJOINED);
+ pim_upstream_switch(up, PIM_UPSTREAM_JOINED);
+ return;
+ }
+
+ /* switched from true to false */
+ if (!is_join_desired && was_join_desired) {
+ zassert(up->join_state == PIM_UPSTREAM_JOINED);
+ pim_upstream_switch(up, PIM_UPSTREAM_NOTJOINED);
+ return;
+ }
+}
+
+/*
+ RFC 4601 4.5.7. Sending (S,G) Join/Prune Messages
+ Transitions from Joined State
+ RPF'(S,G) GenID changes
+
+ The upstream (S,G) state machine remains in Joined state. If the
+ Join Timer is set to expire in more than t_override seconds, reset
+ it so that it expires after t_override seconds.
+*/
+void pim_upstream_rpf_genid_changed(struct in_addr neigh_addr)
+{
+ struct listnode *up_node;
+ struct listnode *up_nextnode;
+ struct pim_upstream *up;
+
+ /*
+ Scan all (S,G) upstreams searching for RPF'(S,G)=neigh_addr
+ */
+ for (ALL_LIST_ELEMENTS(qpim_upstream_list, up_node, up_nextnode, up)) {
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char neigh_str[100];
+ char src_str[100];
+ char grp_str[100];
+ char rpf_addr_str[100];
+ pim_inet4_dump("<neigh?>", neigh_addr, neigh_str, sizeof(neigh_str));
+ pim_inet4_dump("<src?>", up->source_addr, src_str, sizeof(src_str));
+ pim_inet4_dump("<grp?>", up->group_addr, grp_str, sizeof(grp_str));
+ pim_inet4_dump("<rpf?>", up->rpf.rpf_addr, rpf_addr_str, sizeof(rpf_addr_str));
+ zlog_debug("%s: matching neigh=%s against upstream (S,G)=(%s,%s) joined=%d rpf_addr=%s",
+ __PRETTY_FUNCTION__,
+ neigh_str, src_str, grp_str,
+ up->join_state == PIM_UPSTREAM_JOINED,
+ rpf_addr_str);
+ }
+
+ /* consider only (S,G) upstream in Joined state */
+ if (up->join_state != PIM_UPSTREAM_JOINED)
+ continue;
+
+ /* match RPF'(S,G)=neigh_addr */
+ if (up->rpf.rpf_addr.s_addr != neigh_addr.s_addr)
+ continue;
+
+ pim_upstream_join_timer_decrease_to_t_override("RPF'(S,G) GenID change",
+ up, neigh_addr);
+ }
+}
+
+
+void pim_upstream_rpf_interface_changed(struct pim_upstream *up,
+ struct interface *old_rpf_ifp)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct interface *ifp;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct pim_ifchannel *ch;
+ struct pim_interface *pim_ifp;
+
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ /* search all ifchannels */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+ if (ch->upstream != up)
+ continue;
+
+ if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) {
+ if (
+ /* RPF_interface(S) was NOT I */
+ (old_rpf_ifp == ch->interface)
+ &&
+ /* RPF_interface(S) stopped being I */
+ (ch->upstream->rpf.source_nexthop.interface != ch->interface)
+ ) {
+ assert_action_a5(ch);
+ }
+ } /* PIM_IFASSERT_I_AM_LOSER */
+
+ pim_ifchannel_update_assert_tracking_desired(ch);
+ }
+ }
+}
+
+void pim_upstream_update_could_assert(struct pim_upstream *up)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+
+ if (ch->upstream != up)
+ continue;
+
+ pim_ifchannel_update_could_assert(ch);
+
+ } /* scan iface channel list */
+ } /* scan iflist */
+}
+
+void pim_upstream_update_my_assert_metric(struct pim_upstream *up)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+
+ if (ch->upstream != up)
+ continue;
+
+ pim_ifchannel_update_my_assert_metric(ch);
+
+ } /* scan iface channel list */
+ } /* scan iflist */
+}
+
+static void pim_upstream_update_assert_tracking_desired(struct pim_upstream *up)
+{
+ struct listnode *ifnode;
+ struct listnode *ifnextnode;
+ struct listnode *chnode;
+ struct listnode *chnextnode;
+ struct interface *ifp;
+ struct pim_interface *pim_ifp;
+ struct pim_ifchannel *ch;
+
+ /* scan all interfaces */
+ for (ALL_LIST_ELEMENTS(iflist, ifnode, ifnextnode, ifp)) {
+ pim_ifp = ifp->info;
+ if (!pim_ifp)
+ continue;
+
+ /* scan per-interface (S,G) state */
+ for (ALL_LIST_ELEMENTS(pim_ifp->pim_ifchannel_list, chnode, chnextnode, ch)) {
+
+ if (ch->upstream != up)
+ continue;
+
+ pim_ifchannel_update_assert_tracking_desired(ch);
+
+ } /* scan iface channel list */
+ } /* scan iflist */
+}
diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h
new file mode 100644
index 00000000..5b5182dd
--- /dev/null
+++ b/pimd/pim_upstream.h
@@ -0,0 +1,122 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_UPSTREAM_H
+#define PIM_UPSTREAM_H
+
+#include <zebra.h>
+
+#define PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED (1 << 0)
+#define PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED (2 << 0)
+
+#define PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(flags) ((flags) & PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED)
+#define PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED_UPDATED(flags) ((flags) & PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED)
+
+#define PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED)
+#define PIM_UPSTREAM_FLAG_SET_DR_JOIN_DESIRED_UPDATED(flags) ((flags) |= PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED)
+
+#define PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED)
+#define PIM_UPSTREAM_FLAG_UNSET_DR_JOIN_DESIRED_UPDATED(flags) ((flags) &= ~PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED)
+
+/*
+ RFC 4601:
+
+ Metric Preference
+ Preference value assigned to the unicast routing protocol that
+ provided the route to the multicast source or Rendezvous-Point.
+
+ Metric
+ The unicast routing table metric associated with the route used to
+ reach the multicast source or Rendezvous-Point. The metric is in
+ units applicable to the unicast routing protocol used.
+*/
+struct pim_nexthop {
+ struct interface *interface; /* RPF_interface(S) */
+ struct in_addr mrib_nexthop_addr; /* MRIB.next_hop(S) */
+ uint32_t mrib_metric_preference; /* MRIB.pref(S) */
+ uint32_t mrib_route_metric; /* MRIB.metric(S) */
+};
+
+struct pim_rpf {
+ struct pim_nexthop source_nexthop;
+ struct in_addr rpf_addr; /* RPF'(S,G) */
+};
+
+enum pim_rpf_result {
+ PIM_RPF_OK = 0,
+ PIM_RPF_CHANGED,
+ PIM_RPF_FAILURE
+};
+
+enum pim_upstream_state {
+ PIM_UPSTREAM_NOTJOINED,
+ PIM_UPSTREAM_JOINED
+};
+
+/*
+ Upstream (S,G) channel in Joined state
+
+ (S,G) in the "Not Joined" state is not represented
+
+ See RFC 4601: 4.5.7. Sending (S,G) Join/Prune Message
+*/
+struct pim_upstream {
+ struct in_addr source_addr; /* (S,G) source key */
+ struct in_addr group_addr; /* (S,G) group key */
+ uint32_t flags;
+ struct channel_oil *channel_oil;
+
+ enum pim_upstream_state join_state;
+ int ref_count;
+
+ struct pim_rpf rpf;
+
+ struct thread *t_join_timer;
+ int64_t state_transition; /* Record current state uptime */
+};
+
+void pim_upstream_free(struct pim_upstream *up);
+void pim_upstream_delete(struct pim_upstream *up);
+struct pim_upstream *pim_upstream_find(struct in_addr source_addr,
+ struct in_addr group_addr);
+struct pim_upstream *pim_upstream_add(struct in_addr source_addr,
+ struct in_addr group_addr);
+void pim_upstream_del(struct pim_upstream *up);
+
+int pim_upstream_evaluate_join_desired(struct pim_upstream *up);
+void pim_upstream_update_join_desired(struct pim_upstream *up);
+
+void pim_upstream_join_suppress(struct pim_upstream *up,
+ struct in_addr rpf_addr,
+ int holdtime);
+void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label,
+ struct pim_upstream *up,
+ struct in_addr rpf_addr);
+void pim_upstream_join_timer_restart(struct pim_upstream *up);
+void pim_upstream_rpf_genid_changed(struct in_addr neigh_addr);
+void pim_upstream_rpf_interface_changed(struct pim_upstream *up,
+ struct interface *old_rpf_ifp);
+
+void pim_upstream_update_could_assert(struct pim_upstream *up);
+void pim_upstream_update_my_assert_metric(struct pim_upstream *up);
+
+#endif /* PIM_UPSTREAM_H */
diff --git a/pimd/pim_util.c b/pimd/pim_util.c
new file mode 100644
index 00000000..d97b599c
--- /dev/null
+++ b/pimd/pim_util.c
@@ -0,0 +1,159 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+
+#include "pim_util.h"
+
+/*
+ RFC 3376: 4.1.7. QQIC (Querier's Query Interval Code)
+
+ If QQIC < 128, QQI = QQIC
+ If QQIC >= 128, QQI = (mant | 0x10) << (exp + 3)
+
+ 0 1 2 3 4 5 6 7
+ +-+-+-+-+-+-+-+-+
+ |1| exp | mant |
+ +-+-+-+-+-+-+-+-+
+
+ Since exp=0..7 then (exp+3)=3..10, then QQI has
+ one of the following bit patterns:
+
+ exp=0: QQI = 0000.0000.1MMM.M000
+ exp=1: QQI = 0000.0001.MMMM.0000
+ ...
+ exp=6: QQI = 001M.MMM0.0000.0000
+ exp=7: QQI = 01MM.MM00.0000.0000
+ --------- ---------
+ 0x4 0x0 0x0 0x0
+*/
+uint8_t igmp_msg_encode16to8(uint16_t value)
+{
+ uint8_t code;
+
+ if (value < 128) {
+ code = value;
+ }
+ else {
+ uint16_t mask = 0x4000;
+ uint8_t exp;
+ uint16_t mant;
+ for (exp = 7; exp > 0; --exp) {
+ if (mask & value)
+ break;
+ mask >>= 1;
+ }
+ mant = 0x000F & (value >> (exp + 3));
+ code = ((uint8_t) 1 << 7) | ((uint8_t) exp << 4) | (uint8_t) mant;
+ }
+
+ return code;
+}
+
+/*
+ RFC 3376: 4.1.7. QQIC (Querier's Query Interval Code)
+
+ If QQIC < 128, QQI = QQIC
+ If QQIC >= 128, QQI = (mant | 0x10) << (exp + 3)
+
+ 0 1 2 3 4 5 6 7
+ +-+-+-+-+-+-+-+-+
+ |1| exp | mant |
+ +-+-+-+-+-+-+-+-+
+*/
+uint16_t igmp_msg_decode8to16(uint8_t code)
+{
+ uint16_t value;
+
+ if (code < 128) {
+ value = code;
+ }
+ else {
+ uint16_t mant = (code & 0x0F);
+ uint8_t exp = (code & 0x70) >> 4;
+ value = (mant | 0x10) << (exp + 3);
+ }
+
+ return value;
+}
+
+#ifndef PIM_USE_QUAGGA_INET_CHECKSUM
+/*
+ RFC 3376: 4.1.2. Checksum
+
+ The Checksum is the 16-bit one's complement of the one's complement
+ sum of the whole IGMP message (the entire IP payload). For
+ computing the checksum, the Checksum field is set to zero. When
+ receiving packets, the checksum MUST be verified before processing a
+ packet. [RFC-1071]
+*/
+uint16_t pim_inet_checksum(const char *buf, int size)
+{
+ const uint16_t *ptr;
+ uint32_t sum;
+ uint16_t checksum;
+
+ ptr = (const uint16_t *) buf;
+ sum = 0;
+ while (size > 1) {
+ sum += *ptr;
+ ++ptr;
+ size -= 2;
+ }
+
+ /* Add left-over byte, if any */
+ if (size > 0)
+ sum += (uint16_t) *(const uint8_t *) ptr;
+
+ /* Fold 32-bit sum to 16 bits */
+ sum = (sum & 0xffff) + (sum >> 16);
+
+ checksum = ~sum;
+
+ return checksum;
+}
+#endif /* PIM_USE_QUAGGA_INET_CHECKSUM */
+
+void pim_pkt_dump(const char *label, const uint8_t *buf, int size)
+{
+ char dump_buf[1000];
+ int i = 0;
+ int j = 0;
+
+ for (; i < size; ++i, j += 3) {
+ int left = sizeof(dump_buf) - j;
+ if (left < 4) {
+ if (left > 1) {
+ strcat(dump_buf + j, "!"); /* mark as truncated */
+ }
+ break;
+ }
+ snprintf(dump_buf + j, left, " %02x", buf[i]);
+ }
+
+ zlog_debug("%s: pkt dump size=%d:%s",
+ label,
+ size,
+ dump_buf);
+}
diff --git a/pimd/pim_util.h b/pimd/pim_util.h
new file mode 100644
index 00000000..6f5bf223
--- /dev/null
+++ b/pimd/pim_util.h
@@ -0,0 +1,43 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_UTIL_H
+#define PIM_UTIL_H
+
+#include <stdint.h>
+
+#include <zebra.h>
+
+#include "checksum.h"
+
+uint8_t igmp_msg_encode16to8(uint16_t value);
+uint16_t igmp_msg_decode8to16(uint8_t code);
+
+#ifdef PIM_USE_QUAGGA_INET_CHECKSUM
+#define pim_inet_checksum(buf,size) in_cksum(buf,size)
+#else
+uint16_t pim_inet_checksum(const char *buf, int size);
+#endif /* PIM_USE_QUAGGA_INET_CHECKSUM */
+
+void pim_pkt_dump(const char *label, const uint8_t *buf, int size);
+
+#endif /* PIM_UTIL_H */
diff --git a/pimd/pim_version.c b/pimd/pim_version.c
new file mode 100644
index 00000000..fe7e5634
--- /dev/null
+++ b/pimd/pim_version.c
@@ -0,0 +1,25 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include "pim_version.h"
+
+const char * const PIMD_VERSION = PIMD_VERSION_STR;
diff --git a/pimd/pim_version.h b/pimd/pim_version.h
new file mode 100644
index 00000000..546ace3b
--- /dev/null
+++ b/pimd/pim_version.h
@@ -0,0 +1,30 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_VERSION_H
+#define PIM_VERSION_H
+
+#define PIMD_VERSION_STR "0.159"
+
+const char * const PIMD_VERSION;
+
+#endif /* PIM_VERSION_H */
diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c
new file mode 100644
index 00000000..3a1abf13
--- /dev/null
+++ b/pimd/pim_vty.c
@@ -0,0 +1,173 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "if.h"
+#include "linklist.h"
+
+#include "pimd.h"
+#include "pim_vty.h"
+#include "pim_iface.h"
+#include "pim_cmd.h"
+#include "pim_str.h"
+#include "pim_ssmpingd.h"
+
+int pim_debug_config_write(struct vty *vty)
+{
+ int writes = 0;
+
+ if (PIM_DEBUG_IGMP_EVENTS) {
+ vty_out(vty, "debug igmp events%s", VTY_NEWLINE);
+ ++writes;
+ }
+ if (PIM_DEBUG_IGMP_PACKETS) {
+ vty_out(vty, "debug igmp packets%s", VTY_NEWLINE);
+ ++writes;
+ }
+ if (PIM_DEBUG_IGMP_TRACE) {
+ vty_out(vty, "debug igmp trace%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ if (PIM_DEBUG_PIM_EVENTS) {
+ vty_out(vty, "debug pim events%s", VTY_NEWLINE);
+ ++writes;
+ }
+ if (PIM_DEBUG_PIM_PACKETS) {
+ vty_out(vty, "debug pim packets%s", VTY_NEWLINE);
+ ++writes;
+ }
+ if (PIM_DEBUG_PIM_PACKETDUMP_SEND) {
+ vty_out(vty, "debug pim packet-dump send%s", VTY_NEWLINE);
+ ++writes;
+ }
+ if (PIM_DEBUG_PIM_PACKETDUMP_RECV) {
+ vty_out(vty, "debug pim packet-dump receive%s", VTY_NEWLINE);
+ ++writes;
+ }
+ if (PIM_DEBUG_PIM_TRACE) {
+ vty_out(vty, "debug pim trace%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ if (PIM_DEBUG_ZEBRA) {
+ vty_out(vty, "debug pim zebra%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ if (PIM_DEBUG_SSMPINGD) {
+ vty_out(vty, "debug ssmpingd%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ return writes;
+}
+
+int pim_global_config_write(struct vty *vty)
+{
+ int writes = 0;
+
+ if (PIM_MROUTE_IS_ENABLED) {
+ vty_out(vty, "%s%s", PIM_CMD_IP_MULTICAST_ROUTING, VTY_NEWLINE);
+ ++writes;
+ }
+
+ if (qpim_ssmpingd_list) {
+ struct listnode *node;
+ struct ssmpingd_sock *ss;
+ vty_out(vty, "!%s", VTY_NEWLINE);
+ ++writes;
+ for (ALL_LIST_ELEMENTS_RO(qpim_ssmpingd_list, node, ss)) {
+ char source_str[100];
+ pim_inet4_dump("<src?>", ss->source_addr, source_str, sizeof(source_str));
+ vty_out(vty, "ip ssmpingd %s%s", source_str, VTY_NEWLINE);
+ ++writes;
+ }
+ }
+
+ return writes;
+}
+
+int pim_interface_config_write(struct vty *vty)
+{
+ int writes = 0;
+ struct listnode *node;
+ struct interface *ifp;
+
+ for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) {
+
+ /* IF name */
+ vty_out(vty, "interface %s%s", ifp->name, VTY_NEWLINE);
+ ++writes;
+
+ if (ifp->info) {
+ struct pim_interface *pim_ifp = ifp->info;
+
+ /* IF ip pim ssm */
+ if (PIM_IF_TEST_PIM(pim_ifp->options)) {
+ vty_out(vty, " ip pim ssm%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ /* IF ip igmp */
+ if (PIM_IF_TEST_IGMP(pim_ifp->options)) {
+ vty_out(vty, " ip igmp%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ /* IF ip igmp query-interval */
+ vty_out(vty, " %s %d%s",
+ PIM_CMD_IP_IGMP_QUERY_INTERVAL,
+ pim_ifp->igmp_default_query_interval,
+ VTY_NEWLINE);
+ ++writes;
+
+ /* IF ip igmp query-max-response-time */
+ vty_out(vty, " %s %d%s",
+ PIM_CMD_IP_IGMP_QUERY_MAX_RESPONSE_TIME_DSEC,
+ pim_ifp->igmp_query_max_response_time_dsec,
+ VTY_NEWLINE);
+ ++writes;
+
+ /* IF ip igmp join */
+ if (pim_ifp->igmp_join_list) {
+ struct listnode *node;
+ struct igmp_join *ij;
+ for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_join_list, node, ij)) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<grp?>", ij->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<src?>", ij->source_addr, source_str, sizeof(source_str));
+ vty_out(vty, " ip igmp join %s %s%s",
+ group_str, source_str,
+ VTY_NEWLINE);
+ ++writes;
+ }
+ }
+ }
+ vty_out(vty, "!%s", VTY_NEWLINE);
+ ++writes;
+ }
+
+ return writes;
+}
diff --git a/pimd/pim_vty.h b/pimd/pim_vty.h
new file mode 100644
index 00000000..904ee553
--- /dev/null
+++ b/pimd/pim_vty.h
@@ -0,0 +1,32 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_VTY_H
+#define PIM_VTY_H
+
+#include "vty.h"
+
+int pim_debug_config_write(struct vty *vty);
+int pim_global_config_write(struct vty *vty);
+int pim_interface_config_write(struct vty *vty);
+
+#endif /* PIM_VTY_H */
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
new file mode 100644
index 00000000..9e3a0ec3
--- /dev/null
+++ b/pimd/pim_zebra.c
@@ -0,0 +1,1188 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "zebra/rib.h"
+
+#include "log.h"
+#include "prefix.h"
+#include "zclient.h"
+#include "stream.h"
+#include "network.h"
+#include "paths.h"
+
+#include "pimd.h"
+#include "pim_pim.h"
+#include "pim_zebra.h"
+#include "pim_iface.h"
+#include "pim_str.h"
+#include "pim_oil.h"
+#include "pim_rpf.h"
+#include "pim_time.h"
+#include "pim_join.h"
+#include "pim_zlookup.h"
+#include "pim_ifchannel.h"
+
+#undef PIM_DEBUG_IFADDR_DUMP
+#define PIM_DEBUG_IFADDR_DUMP
+
+static int fib_lookup_if_vif_index(struct in_addr addr);
+static int del_oif(struct channel_oil *channel_oil,
+ struct interface *oif,
+ uint32_t proto_mask);
+
+/* Router-id update message from zebra. */
+static int pim_router_id_update_zebra(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct prefix router_id;
+
+ /* FIXME: actually use router_id for anything ? */
+ zebra_router_id_update_read(zclient->ibuf, &router_id);
+
+ return 0;
+}
+
+static int pim_zebra_if_add(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct interface *ifp;
+
+ /*
+ zebra api adds/dels interfaces using the same call
+ interface_add_read below, see comments in lib/zclient.c
+ */
+ ifp = zebra_interface_add_read(zclient->ibuf);
+ if (!ifp)
+ return 0;
+
+ if (PIM_DEBUG_ZEBRA) {
+ zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
+ __PRETTY_FUNCTION__,
+ ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
+ ifp->mtu, if_is_operative(ifp));
+ }
+
+ if (if_is_operative(ifp))
+ pim_if_addr_add_all(ifp);
+
+ return 0;
+}
+
+static int pim_zebra_if_del(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct interface *ifp;
+
+ /*
+ zebra api adds/dels interfaces using the same call
+ interface_add_read below, see comments in lib/zclient.c
+ */
+ ifp = zebra_interface_add_read(zclient->ibuf);
+ if (!ifp)
+ return 0;
+
+ if (PIM_DEBUG_ZEBRA) {
+ zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
+ __PRETTY_FUNCTION__,
+ ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
+ ifp->mtu, if_is_operative(ifp));
+ }
+
+ if (!if_is_operative(ifp))
+ pim_if_addr_del_all(ifp);
+
+ return 0;
+}
+
+static int pim_zebra_if_state_up(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct interface *ifp;
+
+ /*
+ zebra api notifies interface up/down events by using the same call
+ interface_add_read below, see comments in lib/zclient.c
+ */
+ ifp = zebra_interface_state_read(zclient->ibuf);
+ if (!ifp)
+ return 0;
+
+ zlog_info("INTERFACE UP: %s", ifp->name);
+
+ if (PIM_DEBUG_ZEBRA) {
+ zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
+ __PRETTY_FUNCTION__,
+ ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
+ ifp->mtu, if_is_operative(ifp));
+ }
+
+ if (if_is_operative(ifp)) {
+ /*
+ pim_if_addr_add_all() suffices for bringing up both IGMP and PIM
+ */
+ pim_if_addr_add_all(ifp);
+ }
+
+ return 0;
+}
+
+static int pim_zebra_if_state_down(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct interface *ifp;
+
+ /*
+ zebra api notifies interface up/down events by using the same call
+ interface_add_read below, see comments in lib/zclient.c
+ */
+ ifp = zebra_interface_state_read(zclient->ibuf);
+ if (!ifp)
+ return 0;
+
+ zlog_info("INTERFACE DOWN: %s", ifp->name);
+
+ if (PIM_DEBUG_ZEBRA) {
+ zlog_debug("%s: %s index %d flags %ld metric %d mtu %d operative %d",
+ __PRETTY_FUNCTION__,
+ ifp->name, ifp->ifindex, (long)ifp->flags, ifp->metric,
+ ifp->mtu, if_is_operative(ifp));
+ }
+
+ if (!if_is_operative(ifp)) {
+ /*
+ pim_if_addr_del_all() suffices for shutting down IGMP,
+ but not for shutting down PIM
+ */
+ pim_if_addr_del_all(ifp);
+
+ /*
+ pim_sock_delete() closes the socket, stops read and timer threads,
+ and kills all neighbors.
+ */
+ if (ifp->info) {
+ pim_sock_delete(ifp, "link down");
+ }
+ }
+
+ return 0;
+}
+
+#ifdef PIM_DEBUG_IFADDR_DUMP
+static void dump_if_address(struct interface *ifp)
+{
+ struct connected *ifc;
+ struct listnode *node;
+
+ zlog_debug("%s %s: interface %s addresses:",
+ __FILE__, __PRETTY_FUNCTION__,
+ ifp->name);
+
+ for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ struct prefix *p = ifc->address;
+
+ if (p->family != AF_INET)
+ continue;
+
+ zlog_debug("%s %s: interface %s address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ ifp->name,
+ inet_ntoa(p->u.prefix4));
+ }
+}
+#endif
+
+static int pim_zebra_if_address_add(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct connected *c;
+ struct prefix *p;
+
+ zassert(command == ZEBRA_INTERFACE_ADDRESS_ADD);
+
+ /*
+ zebra api notifies address adds/dels events by using the same call
+ interface_add_read below, see comments in lib/zclient.c
+
+ zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, ...)
+ will add address to interface list by calling
+ connected_add_by_prefix()
+ */
+ c = zebra_interface_address_read(command, zclient->ibuf);
+ if (!c)
+ return 0;
+
+ p = c->address;
+ if (p->family != AF_INET)
+ return 0;
+
+ if (PIM_DEBUG_ZEBRA) {
+ char buf[BUFSIZ];
+ prefix2str(p, buf, BUFSIZ);
+ zlog_debug("%s: %s connected IP address %s flags %u",
+ __PRETTY_FUNCTION__,
+ c->ifp->name, buf, c->flags);
+
+#ifdef PIM_DEBUG_IFADDR_DUMP
+ dump_if_address(c->ifp);
+#endif
+ }
+
+ pim_if_addr_add(c);
+
+ return 0;
+}
+
+static int pim_zebra_if_address_del(int command, struct zclient *client,
+ zebra_size_t length)
+{
+ struct connected *c;
+ struct prefix *p;
+
+ zassert(command == ZEBRA_INTERFACE_ADDRESS_DELETE);
+
+ /*
+ zebra api notifies address adds/dels events by using the same call
+ interface_add_read below, see comments in lib/zclient.c
+
+ zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, ...)
+ will remove address from interface list by calling
+ connected_delete_by_prefix()
+ */
+ c = zebra_interface_address_read(command, client->ibuf);
+ if (!c)
+ return 0;
+
+ p = c->address;
+ if (p->family != AF_INET)
+ return 0;
+
+ if (PIM_DEBUG_ZEBRA) {
+ char buf[BUFSIZ];
+ prefix2str(p, buf, BUFSIZ);
+ zlog_debug("%s: %s disconnected IP address %s flags %u",
+ __PRETTY_FUNCTION__,
+ c->ifp->name, buf, c->flags);
+
+#ifdef PIM_DEBUG_IFADDR_DUMP
+ dump_if_address(c->ifp);
+#endif
+ }
+
+ pim_if_addr_del(c);
+
+ return 0;
+}
+
+static void scan_upstream_rpf_cache()
+{
+ struct listnode *up_node;
+ struct listnode *up_nextnode;
+ struct pim_upstream *up;
+
+ for (ALL_LIST_ELEMENTS(qpim_upstream_list, up_node, up_nextnode, up)) {
+ struct in_addr old_rpf_addr;
+ enum pim_rpf_result rpf_result;
+
+ rpf_result = pim_rpf_update(up, &old_rpf_addr);
+ if (rpf_result == PIM_RPF_FAILURE)
+ continue;
+
+ if (rpf_result == PIM_RPF_CHANGED) {
+
+ if (up->join_state == PIM_UPSTREAM_JOINED) {
+
+ /*
+ RFC 4601: 4.5.7. Sending (S,G) Join/Prune Messages
+
+ Transitions from Joined State
+
+ RPF'(S,G) changes not due to an Assert
+
+ The upstream (S,G) state machine remains in Joined
+ state. Send Join(S,G) to the new upstream neighbor, which is
+ the new value of RPF'(S,G). Send Prune(S,G) to the old
+ upstream neighbor, which is the old value of RPF'(S,G). Set
+ the Join Timer (JT) to expire after t_periodic seconds.
+ */
+
+
+ /* send Prune(S,G) to the old upstream neighbor */
+ pim_joinprune_send(up->rpf.source_nexthop.interface,
+ old_rpf_addr,
+ up->source_addr,
+ up->group_addr,
+ 0 /* prune */);
+
+ /* send Join(S,G) to the current upstream neighbor */
+ pim_joinprune_send(up->rpf.source_nexthop.interface,
+ up->rpf.rpf_addr,
+ up->source_addr,
+ up->group_addr,
+ 1 /* join */);
+
+ pim_upstream_join_timer_restart(up);
+ } /* up->join_state == PIM_UPSTREAM_JOINED */
+
+ /* FIXME can join_desired actually be changed by pim_rpf_update()
+ returning PIM_RPF_CHANGED ? */
+ pim_upstream_update_join_desired(up);
+
+ } /* PIM_RPF_CHANGED */
+
+ } /* for (qpim_upstream_list) */
+
+}
+
+static void scan_oil()
+{
+ struct listnode *node;
+ struct listnode *nextnode;
+ struct channel_oil *c_oil;
+
+ for (ALL_LIST_ELEMENTS(qpim_channel_oil_list, node, nextnode, c_oil)) {
+ int old_vif_index;
+ int input_iface_vif_index = fib_lookup_if_vif_index(c_oil->oil.mfcc_origin);
+ if (input_iface_vif_index < 1) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ zlog_warn("%s %s: could not find input interface for (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str);
+ continue;
+ }
+
+ if (input_iface_vif_index == c_oil->oil.mfcc_parent) {
+ /* RPF unchanged */
+ continue;
+ }
+
+ if (PIM_DEBUG_ZEBRA) {
+ struct interface *old_iif = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent);
+ struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index);
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ zlog_debug("%s %s: (S,G)=(%s,%s) input interface changed from %s vif_index=%d to %s vif_index=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str,
+ old_iif ? old_iif->name : "<old_iif?>", c_oil->oil.mfcc_parent,
+ new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index);
+ }
+
+ /* new iif loops to existing oif ? */
+ if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) {
+ struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index);
+
+ if (PIM_DEBUG_ZEBRA) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ zlog_debug("%s %s: (S,G)=(%s,%s) new iif loops to existing oif: %s vif_index=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str,
+ new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index);
+ }
+
+ del_oif(c_oil, new_iif, PIM_OIF_FLAG_PROTO_ANY);
+ }
+
+ /* update iif vif_index */
+ old_vif_index = c_oil->oil.mfcc_parent;
+ c_oil->oil.mfcc_parent = input_iface_vif_index;
+
+ /* update kernel multicast forwarding cache (MFC) */
+ if (pim_mroute_add(&c_oil->oil)) {
+ /* just log warning */
+ struct interface *old_iif = pim_if_find_by_vif_index(old_vif_index);
+ struct interface *new_iif = pim_if_find_by_vif_index(input_iface_vif_index);
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ zlog_warn("%s %s: (S,G)=(%s,%s) failure updating input interface from %s vif_index=%d to %s vif_index=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str,
+ old_iif ? old_iif->name : "<old_iif?>", c_oil->oil.mfcc_parent,
+ new_iif ? new_iif->name : "<new_iif?>", input_iface_vif_index);
+ continue;
+ }
+
+ } /* for (qpim_channel_oil_list) */
+}
+
+static int on_rpf_cache_refresh(struct thread *t)
+{
+ zassert(t);
+ zassert(qpim_rpf_cache_refresher);
+
+ qpim_rpf_cache_refresher = 0;
+
+ /* update PIM protocol state */
+ scan_upstream_rpf_cache();
+
+ /* update kernel multicast forwarding cache (MFC) */
+ scan_oil();
+
+ qpim_rpf_cache_refresh_last = pim_time_monotonic_sec();
+ ++qpim_rpf_cache_refresh_events;
+
+ return 0;
+}
+
+static void sched_rpf_cache_refresh()
+{
+ ++qpim_rpf_cache_refresh_requests;
+
+ if (qpim_rpf_cache_refresher) {
+ /* Refresh timer is already running */
+ return;
+ }
+
+ /* Start refresh timer */
+
+ if (PIM_DEBUG_ZEBRA) {
+ zlog_debug("%s: triggering %ld msec timer",
+ __PRETTY_FUNCTION__,
+ qpim_rpf_cache_refresh_delay_msec);
+ }
+
+ THREAD_TIMER_MSEC_ON(master, qpim_rpf_cache_refresher,
+ on_rpf_cache_refresh,
+ 0, qpim_rpf_cache_refresh_delay_msec);
+}
+
+static int redist_read_ipv4_route(int command, struct zclient *zclient,
+ zebra_size_t length)
+{
+ struct stream *s;
+ struct zapi_ipv4 api;
+ unsigned long ifindex;
+ struct in_addr nexthop;
+ struct prefix_ipv4 p;
+ int min_len = 4;
+
+ if (length < min_len) {
+ zlog_warn("%s %s: short buffer: length=%d min=%d",
+ __FILE__, __PRETTY_FUNCTION__,
+ length, min_len);
+ return -1;
+ }
+
+ s = zclient->ibuf;
+ ifindex = 0;
+ nexthop.s_addr = 0;
+
+ /* Type, flags, message. */
+ api.type = stream_getc(s);
+ api.flags = stream_getc(s);
+ api.message = stream_getc(s);
+
+ /* IPv4 prefix length. */
+ memset(&p, 0, sizeof(struct prefix_ipv4));
+ p.family = AF_INET;
+ p.prefixlen = stream_getc(s);
+
+ min_len +=
+ PSIZE(p.prefixlen) +
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? 5 : 0 +
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? 5 : 0 +
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? 1 : 0 +
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? 4 : 0;
+
+ if (PIM_DEBUG_ZEBRA) {
+ zlog_debug("%s %s: length=%d min_len=%d flags=%s%s%s%s",
+ __FILE__, __PRETTY_FUNCTION__,
+ length, min_len,
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? "nh" : "",
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? " ifi" : "",
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? " dist" : "",
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? " metr" : "");
+ }
+
+ if (length < min_len) {
+ zlog_warn("%s %s: short buffer: length=%d min_len=%d flags=%s%s%s%s",
+ __FILE__, __PRETTY_FUNCTION__,
+ length, min_len,
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP) ? "nh" : "",
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX) ? " ifi" : "",
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? " dist" : "",
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? " metr" : "");
+ return -1;
+ }
+
+ /* IPv4 prefix. */
+ stream_get(&p.prefix, s, PSIZE(p.prefixlen));
+
+ /* Nexthop, ifindex, distance, metric. */
+ if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP)) {
+ api.nexthop_num = stream_getc(s);
+ nexthop.s_addr = stream_get_ipv4(s);
+ }
+ if (CHECK_FLAG(api.message, ZAPI_MESSAGE_IFINDEX)) {
+ api.ifindex_num = stream_getc(s);
+ ifindex = stream_getl(s);
+ }
+
+ api.distance = CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ?
+ api.distance = stream_getc(s) :
+ 0;
+
+ api.metric = CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ?
+ stream_getl(s) :
+ 0;
+
+ switch (command) {
+ case ZEBRA_IPV4_ROUTE_ADD:
+ if (PIM_DEBUG_ZEBRA) {
+ char buf[2][INET_ADDRSTRLEN];
+ zlog_debug("%s: add %s %s/%d "
+ "nexthop %s ifindex %ld metric%s %u distance%s %u",
+ __PRETTY_FUNCTION__,
+ zebra_route_string(api.type),
+ inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])),
+ p.prefixlen,
+ inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])),
+ ifindex,
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? "-recv" : "-miss",
+ api.metric,
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? "-recv" : "-miss",
+ api.distance);
+ }
+ break;
+ case ZEBRA_IPV4_ROUTE_DELETE:
+ if (PIM_DEBUG_ZEBRA) {
+ char buf[2][INET_ADDRSTRLEN];
+ zlog_debug("%s: delete %s %s/%d "
+ "nexthop %s ifindex %ld metric%s %u distance%s %u",
+ __PRETTY_FUNCTION__,
+ zebra_route_string(api.type),
+ inet_ntop(AF_INET, &p.prefix, buf[0], sizeof(buf[0])),
+ p.prefixlen,
+ inet_ntop(AF_INET, &nexthop, buf[1], sizeof(buf[1])),
+ ifindex,
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC) ? "-recv" : "-miss",
+ api.metric,
+ CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE) ? "-recv" : "-miss",
+ api.distance);
+ }
+ break;
+ default:
+ zlog_warn("%s: unknown command=%d", __PRETTY_FUNCTION__, command);
+ return -1;
+ }
+
+ sched_rpf_cache_refresh();
+
+ return 0;
+}
+
+void pim_zebra_init()
+{
+ struct zclient *zclient;
+ int i;
+
+#ifdef HAVE_TCP_ZEBRA
+ zlog_notice("zclient update contacting ZEBRA daemon at socket TCP %s,%d", "127.0.0.1", ZEBRA_PORT);
+#else
+ zlog_notice("zclient update contacting ZEBRA daemon at socket UNIX %s", path_state (ZEBRA_SERV_NAME));
+#endif
+
+ /* Socket for receiving updates from Zebra daemon */
+ zclient = zclient_new();
+
+ zclient->router_id_update = pim_router_id_update_zebra;
+ zclient->interface_add = pim_zebra_if_add;
+ zclient->interface_delete = pim_zebra_if_del;
+ zclient->interface_up = pim_zebra_if_state_up;
+ zclient->interface_down = pim_zebra_if_state_down;
+ zclient->interface_address_add = pim_zebra_if_address_add;
+ zclient->interface_address_delete = pim_zebra_if_address_del;
+ zclient->ipv4_route_add = redist_read_ipv4_route;
+ zclient->ipv4_route_delete = redist_read_ipv4_route;
+
+ zclient_init(zclient, ZEBRA_ROUTE_PIM);
+ zlog_info("zclient_init cleared redistribution request");
+
+ zassert(zclient->redist_default == ZEBRA_ROUTE_PIM);
+
+ /* Request all redistribution */
+ for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
+ if (i == zclient->redist_default)
+ continue;
+ zclient->redist[i] = 1;
+ zlog_info("%s: requesting redistribution for %s (%i)",
+ __PRETTY_FUNCTION__, zebra_route_string(i), i);
+ }
+
+ /* Request default information */
+ zclient->default_information = 1;
+ zlog_info("%s: requesting default information redistribution",
+ __PRETTY_FUNCTION__);
+
+ zlog_notice("%s: zclient update socket initialized",
+ __PRETTY_FUNCTION__);
+
+ zassert(!qpim_zclient_lookup);
+ qpim_zclient_lookup = zclient_lookup_new();
+ zassert(qpim_zclient_lookup);
+}
+
+void igmp_anysource_forward_start(struct igmp_group *group)
+{
+ /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
+ zassert(group->group_filtermode_isexcl);
+ zassert(listcount(group->group_source_list) < 1);
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_debug("%s %s: UNIMPLEMENTED",
+ __FILE__, __PRETTY_FUNCTION__);
+ }
+}
+
+void igmp_anysource_forward_stop(struct igmp_group *group)
+{
+ /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
+ zassert((!group->group_filtermode_isexcl) || (listcount(group->group_source_list) > 0));
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ zlog_debug("%s %s: UNIMPLEMENTED",
+ __FILE__, __PRETTY_FUNCTION__);
+ }
+}
+
+static int fib_lookup_if_vif_index(struct in_addr addr)
+{
+ struct pim_zlookup_nexthop nexthop_tab[PIM_NEXTHOP_IFINDEX_TAB_SIZE];
+ int num_ifindex;
+ int vif_index;
+ int first_ifindex;
+
+ num_ifindex = zclient_lookup_nexthop(qpim_zclient_lookup, nexthop_tab,
+ PIM_NEXTHOP_IFINDEX_TAB_SIZE, addr,
+ PIM_NEXTHOP_LOOKUP_MAX);
+ if (num_ifindex < 1) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: could not find nexthop ifindex for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ addr_str);
+ return -1;
+ }
+
+ first_ifindex = nexthop_tab[0].ifindex;
+
+ if (num_ifindex > 1) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s %s: FIXME ignoring multiple nexthop ifindex'es num_ifindex=%d for address %s (using only ifindex=%d)",
+ __FILE__, __PRETTY_FUNCTION__,
+ num_ifindex, addr_str, first_ifindex);
+ /* debug warning only, do not return */
+ }
+
+ if (PIM_DEBUG_ZEBRA) {
+ char addr_str[100];
+ pim_inet4_dump("<ifaddr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s %s: found nexthop ifindex=%d (interface %s) for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ first_ifindex, ifindex2ifname(first_ifindex), addr_str);
+ }
+
+ vif_index = pim_if_find_vifindex_by_ifindex(first_ifindex);
+
+ if (vif_index < 1) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: low vif_index=%d < 1 nexthop for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ vif_index, addr_str);
+ return -2;
+ }
+
+ zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
+
+ if (vif_index > qpim_mroute_oif_highest_vif_index) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: high vif_index=%d > highest_vif_index=%d nexthop for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ vif_index, qpim_mroute_oif_highest_vif_index, addr_str);
+
+ zlog_warn("%s %s: pim disabled on interface %s vif_index=%d ?",
+ __FILE__, __PRETTY_FUNCTION__,
+ ifindex2ifname(vif_index),
+ vif_index);
+
+ return -3;
+ }
+
+ return vif_index;
+}
+
+static int add_oif(struct channel_oil *channel_oil,
+ struct interface *oif,
+ uint32_t proto_mask)
+{
+ struct pim_interface *pim_ifp;
+ int old_ttl;
+
+ zassert(channel_oil);
+
+ pim_ifp = oif->info;
+
+ if (pim_ifp->mroute_vif_index < 1) {
+ zlog_warn("%s %s: interface %s vif_index=%d < 1",
+ __FILE__, __PRETTY_FUNCTION__,
+ oif->name, pim_ifp->mroute_vif_index);
+ return -1;
+ }
+
+#ifdef PIM_ENFORCE_LOOPFREE_MFC
+ /*
+ Prevent creating MFC entry with OIF=IIF.
+
+ This is a protection against implementation mistakes.
+
+ PIM protocol implicitely ensures loopfree multicast topology.
+
+ IGMP must be protected against adding looped MFC entries created
+ by both source and receiver attached to the same interface. See
+ TODO T22.
+ */
+ if (pim_ifp->mroute_vif_index == channel_oil->oil.mfcc_parent) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: refusing protocol mask %u request for IIF=OIF=%s (vif_index=%d) for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ proto_mask, oif->name, pim_ifp->mroute_vif_index,
+ source_str, group_str);
+ return -2;
+ }
+#endif
+
+ zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
+ zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index);
+
+ /* Prevent single protocol from subscribing same interface to
+ channel (S,G) multiple times */
+ if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: existing protocol mask %u requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ proto_mask, oif->name, pim_ifp->mroute_vif_index,
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
+ source_str, group_str);
+ return -3;
+ }
+
+ /* Allow other protocol to request subscription of same interface to
+ channel (S,G) multiple times, by silently ignoring further
+ requests */
+ if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) {
+
+ /* Check the OIF really exists before returning, and only log
+ warning otherwise */
+ if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: new protocol mask %u requested nonexistent OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ proto_mask, oif->name, pim_ifp->mroute_vif_index,
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
+ source_str, group_str);
+ }
+
+ return 0;
+ }
+
+ old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index];
+
+ if (old_ttl > 0) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: interface %s (vif_index=%d) is existing output for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ oif->name, pim_ifp->mroute_vif_index,
+ source_str, group_str);
+ return -4;
+ }
+
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = PIM_MROUTE_MIN_TTL;
+
+ if (pim_mroute_add(&channel_oil->oil)) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ oif->name, pim_ifp->mroute_vif_index,
+ source_str, group_str);
+
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = old_ttl;
+ return -5;
+ }
+
+ channel_oil->oif_creation[pim_ifp->mroute_vif_index] = pim_time_monotonic_sec();
+ ++channel_oil->oil_size;
+ channel_oil->oif_flags[pim_ifp->mroute_vif_index] |= proto_mask;
+
+ return 0;
+}
+
+static int del_oif(struct channel_oil *channel_oil,
+ struct interface *oif,
+ uint32_t proto_mask)
+{
+ struct pim_interface *pim_ifp;
+ int old_ttl;
+
+ zassert(channel_oil);
+
+ pim_ifp = oif->info;
+
+ zassert(pim_ifp->mroute_vif_index >= 1);
+ zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
+ zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index);
+
+ /* Prevent single protocol from unsubscribing same interface from
+ channel (S,G) multiple times */
+ if (!(channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask)) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: nonexistent protocol mask %u removed OIF %s (vif_index=%d, min_ttl=%d) from channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ proto_mask, oif->name, pim_ifp->mroute_vif_index,
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
+ source_str, group_str);
+ return -2;
+ }
+
+ /* Mark that protocol is no longer interested in this OIF */
+ channel_oil->oif_flags[pim_ifp->mroute_vif_index] &= ~proto_mask;
+
+ /* Allow multiple protocols to unsubscribe same interface from
+ channel (S,G) multiple times, by silently ignoring requests while
+ there is at least one protocol interested in the channel */
+ if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) {
+
+ /* Check the OIF keeps existing before returning, and only log
+ warning otherwise */
+ if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: protocol mask %u removing nonexistent OIF %s (vif_index=%d, min_ttl=%d) from channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ proto_mask, oif->name, pim_ifp->mroute_vif_index,
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index],
+ source_str, group_str);
+ }
+
+ return 0;
+ }
+
+ old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index];
+
+ if (old_ttl < 1) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: interface %s (vif_index=%d) is not output for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ oif->name, pim_ifp->mroute_vif_index,
+ source_str, group_str);
+ return -3;
+ }
+
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = 0;
+
+ if (pim_mroute_add(&channel_oil->oil)) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: could not remove output interface %s (vif_index=%d) from channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ oif->name, pim_ifp->mroute_vif_index,
+ source_str, group_str);
+
+ channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = old_ttl;
+ return -4;
+ }
+
+ --channel_oil->oil_size;
+
+ if (channel_oil->oil_size < 1) {
+ if (pim_mroute_del(&channel_oil->oil)) {
+ /* just log a warning in case of failure */
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+ zlog_warn("%s %s: failure removing OIL for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str);
+ }
+ }
+
+ return 0;
+}
+
+void igmp_source_forward_start(struct igmp_source *source)
+{
+ struct igmp_group *group;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: (S,G)=(%s,%s) igmp_sock=%d oif=%s fwd=%d",
+ __PRETTY_FUNCTION__,
+ source_str, group_str,
+ source->source_group->group_igmp_sock->fd,
+ source->source_group->group_igmp_sock->interface->name,
+ IGMP_SOURCE_TEST_FORWARDING(source->source_flags));
+ }
+
+ /* Prevent IGMP interface from installing multicast route multiple
+ times */
+ if (IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) {
+ return;
+ }
+
+ group = source->source_group;
+
+ if (!source->source_channel_oil) {
+ struct pim_interface *pim_oif;
+ int input_iface_vif_index = fib_lookup_if_vif_index(source->source_addr);
+ if (input_iface_vif_index < 1) {
+ char source_str[100];
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s %s: could not find input interface for source %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str);
+ return;
+ }
+
+ /*
+ Protect IGMP against adding looped MFC entries created by both
+ source and receiver attached to the same interface. See TODO
+ T22.
+ */
+ pim_oif = source->source_group->group_igmp_sock->interface->info;
+ if (!pim_oif) {
+ zlog_warn("%s: multicast not enabled on oif=%s ?",
+ __PRETTY_FUNCTION__,
+ source->source_group->group_igmp_sock->interface->name);
+ return;
+ }
+ if (pim_oif->mroute_vif_index < 1) {
+ zlog_warn("%s %s: oif=%s vif_index=%d < 1",
+ __FILE__, __PRETTY_FUNCTION__,
+ source->source_group->group_igmp_sock->interface->name,
+ pim_oif->mroute_vif_index);
+ return;
+ }
+ if (input_iface_vif_index == pim_oif->mroute_vif_index) {
+ /* ignore request for looped MFC entry */
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: ignoring request for looped MFC entry (S,G)=(%s,%s): igmp_sock=%d oif=%s vif_index=%d",
+ __PRETTY_FUNCTION__,
+ source_str, group_str,
+ source->source_group->group_igmp_sock->fd,
+ source->source_group->group_igmp_sock->interface->name,
+ input_iface_vif_index);
+ }
+ return;
+ }
+
+ source->source_channel_oil = pim_channel_oil_add(group->group_addr,
+ source->source_addr,
+ input_iface_vif_index);
+ if (!source->source_channel_oil) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s %s: could not create OIL for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str);
+ return;
+ }
+ }
+
+ if (add_oif(source->source_channel_oil,
+ group->group_igmp_sock->interface,
+ PIM_OIF_FLAG_PROTO_IGMP)) {
+ return;
+ }
+
+ /*
+ Feed IGMPv3-gathered local membership information into PIM
+ per-interface (S,G) state.
+ */
+ pim_ifchannel_local_membership_add(group->group_igmp_sock->interface,
+ source->source_addr, group->group_addr);
+
+ IGMP_SOURCE_DO_FORWARDING(source->source_flags);
+}
+
+void igmp_source_forward_stop(struct igmp_source *source)
+{
+ struct igmp_group *group;
+
+ if (PIM_DEBUG_IGMP_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", source->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", source->source_group->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: (S,G)=(%s,%s) igmp_sock=%d oif=%s fwd=%d",
+ __PRETTY_FUNCTION__,
+ source_str, group_str,
+ source->source_group->group_igmp_sock->fd,
+ source->source_group->group_igmp_sock->interface->name,
+ IGMP_SOURCE_TEST_FORWARDING(source->source_flags));
+ }
+
+ /* Prevent IGMP interface from removing multicast route multiple
+ times */
+ if (!IGMP_SOURCE_TEST_FORWARDING(source->source_flags)) {
+ return;
+ }
+
+ group = source->source_group;
+
+ if (del_oif(source->source_channel_oil,
+ group->group_igmp_sock->interface,
+ PIM_OIF_FLAG_PROTO_IGMP)) {
+ return;
+ }
+
+ /*
+ Feed IGMPv3-gathered local membership information into PIM
+ per-interface (S,G) state.
+ */
+ pim_ifchannel_local_membership_del(group->group_igmp_sock->interface,
+ source->source_addr, group->group_addr);
+
+ IGMP_SOURCE_DONT_FORWARDING(source->source_flags);
+}
+
+void pim_forward_start(struct pim_ifchannel *ch)
+{
+ struct pim_upstream *up = ch->upstream;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: (S,G)=(%s,%s) oif=%s",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, ch->interface->name);
+ }
+
+ if (!up->channel_oil) {
+ int input_iface_vif_index = fib_lookup_if_vif_index(up->source_addr);
+ if (input_iface_vif_index < 1) {
+ char source_str[100];
+ pim_inet4_dump("<source?>", up->source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s %s: could not find input interface for source %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str);
+ return;
+ }
+
+ up->channel_oil = pim_channel_oil_add(up->group_addr, up->source_addr,
+ input_iface_vif_index);
+ if (!up->channel_oil) {
+ char group_str[100];
+ char source_str[100];
+ pim_inet4_dump("<group?>", up->group_addr, group_str, sizeof(group_str));
+ pim_inet4_dump("<source?>", up->source_addr, source_str, sizeof(source_str));
+ zlog_warn("%s %s: could not create OIL for channel (S,G)=(%s,%s)",
+ __FILE__, __PRETTY_FUNCTION__,
+ source_str, group_str);
+ return;
+ }
+ }
+
+ add_oif(up->channel_oil,
+ ch->interface,
+ PIM_OIF_FLAG_PROTO_PIM);
+}
+
+void pim_forward_stop(struct pim_ifchannel *ch)
+{
+ struct pim_upstream *up = ch->upstream;
+
+ if (PIM_DEBUG_PIM_TRACE) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str));
+ zlog_debug("%s: (S,G)=(%s,%s) oif=%s",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, ch->interface->name);
+ }
+
+ if (!up->channel_oil) {
+ char source_str[100];
+ char group_str[100];
+ pim_inet4_dump("<source?>", ch->source_addr, source_str, sizeof(source_str));
+ pim_inet4_dump("<group?>", ch->group_addr, group_str, sizeof(group_str));
+ zlog_warn("%s: (S,G)=(%s,%s) oif=%s missing channel OIL",
+ __PRETTY_FUNCTION__,
+ source_str, group_str, ch->interface->name);
+
+ return;
+ }
+
+ del_oif(up->channel_oil,
+ ch->interface,
+ PIM_OIF_FLAG_PROTO_PIM);
+}
diff --git a/pimd/pim_zebra.h b/pimd/pim_zebra.h
new file mode 100644
index 00000000..e0c9bdcb
--- /dev/null
+++ b/pimd/pim_zebra.h
@@ -0,0 +1,40 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_ZEBRA_H
+#define PIM_ZEBRA_H
+
+#include "pim_igmp.h"
+#include "pim_ifchannel.h"
+
+void pim_zebra_init(void);
+
+void igmp_anysource_forward_start(struct igmp_group *group);
+void igmp_anysource_forward_stop(struct igmp_group *group);
+
+void igmp_source_forward_start(struct igmp_source *source);
+void igmp_source_forward_stop(struct igmp_source *source);
+
+void pim_forward_start(struct pim_ifchannel *ch);
+void pim_forward_stop(struct pim_ifchannel *ch);
+
+#endif /* PIM_ZEBRA_H */
diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c
new file mode 100644
index 00000000..5f3eeaba
--- /dev/null
+++ b/pimd/pim_zlookup.c
@@ -0,0 +1,456 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+#include "zebra/rib.h"
+
+#include "log.h"
+#include "prefix.h"
+#include "zclient.h"
+#include "stream.h"
+#include "network.h"
+#include "thread.h"
+#include "paths.h"
+
+#include "pimd.h"
+#include "pim_pim.h"
+#include "pim_str.h"
+#include "pim_zlookup.h"
+
+extern int zclient_debug;
+
+static void zclient_lookup_sched(struct zclient *zlookup, int delay);
+
+/* Connect to zebra for nexthop lookup. */
+static int zclient_lookup_connect(struct thread *t)
+{
+ struct zclient *zlookup;
+
+ zlookup = THREAD_ARG(t);
+ zlookup->t_connect = NULL;
+
+ if (zlookup->sock >= 0) {
+ return 0;
+ }
+
+#ifdef HAVE_TCP_ZEBRA
+ zlog_debug("%s: FIXME blocking connect: zclient_socket()",
+ __PRETTY_FUNCTION__);
+ zlookup->sock = zclient_socket();
+ if (zlookup->sock < 0) {
+ zlog_warn("%s: failure connecting TCP socket %s,%d",
+ __PRETTY_FUNCTION__, "127.0.0.1", ZEBRA_PORT);
+ }
+ else if (zclient_debug) {
+ zlog_notice("%s: connected TCP socket %s,%d",
+ __PRETTY_FUNCTION__, "127.0.0.1", ZEBRA_PORT);
+ }
+#else
+ zlog_debug("%s: FIXME blocking connect: zclient_socket_un()",
+ __PRETTY_FUNCTION__);
+ zlookup->sock = zclient_socket_un(path_state (ZEBRA_SERV_NAME));
+ if (zlookup->sock < 0) {
+ zlog_warn("%s: failure connecting UNIX socket %s",
+ __PRETTY_FUNCTION__, path_state (ZEBRA_SERV_NAME));
+ }
+ else if (zclient_debug) {
+ zlog_notice("%s: connected UNIX socket %s",
+ __PRETTY_FUNCTION__, path_state (ZEBRA_SERV_NAME));
+ }
+#endif /* HAVE_TCP_ZEBRA */
+
+ zassert(!zlookup->t_connect);
+ if (zlookup->sock < 0) {
+ /* Since last connect failed, retry within 10 secs */
+ zclient_lookup_sched(zlookup, 10);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* Schedule connection with delay. */
+static void zclient_lookup_sched(struct zclient *zlookup, int delay)
+{
+ zassert(!zlookup->t_connect);
+
+ THREAD_TIMER_ON(master, zlookup->t_connect,
+ zclient_lookup_connect,
+ zlookup, delay);
+
+ zlog_notice("%s: zclient lookup connection scheduled for %d seconds",
+ __PRETTY_FUNCTION__, delay);
+}
+
+/* Schedule connection for now. */
+static void zclient_lookup_sched_now(struct zclient *zlookup)
+{
+ zassert(!zlookup->t_connect);
+
+ zlookup->t_connect = thread_add_event(master, zclient_lookup_connect,
+ zlookup, 0);
+
+ zlog_notice("%s: zclient lookup immediate connection scheduled",
+ __PRETTY_FUNCTION__);
+}
+
+/* Schedule reconnection, if needed. */
+static void zclient_lookup_reconnect(struct zclient *zlookup)
+{
+ if (zlookup->t_connect) {
+ return;
+ }
+
+ zclient_lookup_sched_now(zlookup);
+}
+
+struct zclient *zclient_lookup_new()
+{
+ struct zclient *zlookup;
+
+ zlookup = zclient_new();
+ if (!zlookup) {
+ zlog_err("%s: zclient_new() failure",
+ __PRETTY_FUNCTION__);
+ return 0;
+ }
+
+ zlookup->sock = -1;
+ zlookup->ibuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
+ zlookup->obuf = stream_new(ZEBRA_MAX_PACKET_SIZ);
+ zlookup->t_connect = 0;
+
+ zclient_lookup_sched_now(zlookup);
+
+ zlog_notice("%s: zclient lookup socket initialized",
+ __PRETTY_FUNCTION__);
+
+ return zlookup;
+}
+
+static int zclient_read_nexthop(struct zclient *zlookup,
+ struct pim_zlookup_nexthop nexthop_tab[],
+ const int tab_size,
+ struct in_addr addr)
+{
+ int num_ifindex = 0;
+ struct stream *s;
+ const uint16_t MIN_LEN = 14; /* getc=1 getc=1 getw=2 getipv4=4 getc=1 getl=4 getc=1 */
+ uint16_t length, len;
+ u_char marker;
+ u_char version;
+ uint16_t command;
+ int nbytes;
+ struct in_addr raddr;
+ uint8_t distance;
+ uint32_t metric;
+ int nexthop_num;
+ int i;
+
+ if (PIM_DEBUG_ZEBRA) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s: addr=%s",
+ __PRETTY_FUNCTION__,
+ addr_str);
+ }
+
+ s = zlookup->ibuf;
+ stream_reset(s);
+
+ nbytes = stream_read(s, zlookup->sock, 2);
+ if (nbytes < 2) {
+ zlog_err("%s %s: failure reading zclient lookup socket: nbytes=%d",
+ __FILE__, __PRETTY_FUNCTION__, nbytes);
+ close(zlookup->sock);
+ zlookup->sock = -1;
+ zclient_lookup_reconnect(zlookup);
+ return -1;
+ }
+ length = stream_getw(s);
+
+ len = length - 2;
+
+ if (len < MIN_LEN) {
+ zlog_err("%s %s: failure reading zclient lookup socket: len=%d < MIN_LEN=%d",
+ __FILE__, __PRETTY_FUNCTION__, len, MIN_LEN);
+ close(zlookup->sock);
+ zlookup->sock = -1;
+ zclient_lookup_reconnect(zlookup);
+ return -2;
+ }
+
+ nbytes = stream_read(s, zlookup->sock, len);
+ if (nbytes < (length - 2)) {
+ zlog_err("%s %s: failure reading zclient lookup socket: nbytes=%d < len=%d",
+ __FILE__, __PRETTY_FUNCTION__, nbytes, len);
+ close(zlookup->sock);
+ zlookup->sock = -1;
+ zclient_lookup_reconnect(zlookup);
+ return -3;
+ }
+ marker = stream_getc(s);
+ version = stream_getc(s);
+
+ if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) {
+ zlog_err("%s: socket %d version mismatch, marker %d, version %d",
+ __func__, zlookup->sock, marker, version);
+ return -4;
+ }
+
+ command = stream_getw(s);
+ if (command != ZEBRA_IPV4_NEXTHOP_LOOKUP_V2) {
+ zlog_err("%s: socket %d command mismatch: %d",
+ __func__, zlookup->sock, command);
+ return -5;
+ }
+
+ raddr.s_addr = stream_get_ipv4(s);
+
+ if (raddr.s_addr != addr.s_addr) {
+ char addr_str[100];
+ char raddr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ pim_inet4_dump("<raddr?>", raddr, raddr_str, sizeof(raddr_str));
+ zlog_warn("%s: address mismatch: addr=%s raddr=%s",
+ __PRETTY_FUNCTION__,
+ addr_str, raddr_str);
+ /* warning only */
+ }
+
+ distance = stream_getc(s);
+ metric = stream_getl(s);
+ nexthop_num = stream_getc(s);
+
+ if (nexthop_num < 1) {
+ zlog_err("%s: socket %d bad nexthop_num=%d",
+ __func__, zlookup->sock, nexthop_num);
+ return -6;
+ }
+
+ len -= MIN_LEN;
+
+ for (i = 0; i < nexthop_num; ++i) {
+ enum nexthop_types_t nexthop_type;
+
+ if (len < 1) {
+ zlog_err("%s: socket %d empty input expecting nexthop_type: len=%d",
+ __func__, zlookup->sock, len);
+ return -7;
+ }
+
+ nexthop_type = stream_getc(s);
+ --len;
+
+ switch (nexthop_type) {
+ case ZEBRA_NEXTHOP_IFINDEX:
+ case ZEBRA_NEXTHOP_IFNAME:
+ case ZEBRA_NEXTHOP_IPV4_IFINDEX:
+ if (num_ifindex >= tab_size) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: found too many nexthop ifindexes (%d > %d) for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ (num_ifindex + 1), tab_size, addr_str);
+ return num_ifindex;
+ }
+ if (nexthop_type == ZEBRA_NEXTHOP_IPV4_IFINDEX) {
+ if (len < 4) {
+ zlog_err("%s: socket %d short input expecting nexthop IPv4-addr: len=%d",
+ __func__, zlookup->sock, len);
+ return -8;
+ }
+ nexthop_tab[num_ifindex].nexthop_addr.s_addr = stream_get_ipv4(s);
+ len -= 4;
+ }
+ else {
+ nexthop_tab[num_ifindex].nexthop_addr.s_addr = PIM_NET_INADDR_ANY;
+ }
+ nexthop_tab[num_ifindex].ifindex = stream_getl(s);
+ nexthop_tab[num_ifindex].protocol_distance = distance;
+ nexthop_tab[num_ifindex].route_metric = metric;
+ ++num_ifindex;
+ break;
+ case ZEBRA_NEXTHOP_IPV4:
+ if (num_ifindex >= tab_size) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: found too many nexthop ifindexes (%d > %d) for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ (num_ifindex + 1), tab_size, addr_str);
+ return num_ifindex;
+ }
+ nexthop_tab[num_ifindex].nexthop_addr.s_addr = stream_get_ipv4(s);
+ len -= 4;
+ nexthop_tab[num_ifindex].ifindex = 0;
+ nexthop_tab[num_ifindex].protocol_distance = distance;
+ nexthop_tab[num_ifindex].route_metric = metric;
+ {
+ char addr_str[100];
+ char nexthop_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ pim_inet4_dump("<nexthop?>", nexthop_tab[num_ifindex].nexthop_addr, nexthop_str, sizeof(nexthop_str));
+ zlog_warn("%s %s: zebra returned recursive nexthop %s for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ nexthop_str, addr_str);
+ }
+ ++num_ifindex;
+ break;
+ default:
+ /* do nothing */
+ {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: found non-ifindex nexthop type=%d for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ nexthop_type, addr_str);
+ }
+ break;
+ }
+ }
+
+ return num_ifindex;
+}
+
+static int zclient_lookup_nexthop_once(struct zclient *zlookup,
+ struct pim_zlookup_nexthop nexthop_tab[],
+ const int tab_size,
+ struct in_addr addr)
+{
+ struct stream *s;
+ int ret;
+
+ if (PIM_DEBUG_ZEBRA) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_debug("%s: addr=%s",
+ __PRETTY_FUNCTION__,
+ addr_str);
+ }
+
+ /* Check socket. */
+ if (zlookup->sock < 0) {
+ zlog_err("%s %s: zclient lookup socket is not connected",
+ __FILE__, __PRETTY_FUNCTION__);
+ zclient_lookup_reconnect(zlookup);
+ return -1;
+ }
+
+ s = zlookup->obuf;
+ stream_reset(s);
+ zclient_create_header(s, ZEBRA_IPV4_NEXTHOP_LOOKUP_V2);
+ stream_put_in_addr(s, &addr);
+ stream_putw_at(s, 0, stream_get_endp(s));
+
+ ret = writen(zlookup->sock, s->data, stream_get_endp(s));
+ if (ret < 0) {
+ zlog_err("%s %s: writen() failure writing to zclient lookup socket",
+ __FILE__, __PRETTY_FUNCTION__);
+ close(zlookup->sock);
+ zlookup->sock = -1;
+ zclient_lookup_reconnect(zlookup);
+ return -2;
+ }
+ if (ret == 0) {
+ zlog_err("%s %s: connection closed on zclient lookup socket",
+ __FILE__, __PRETTY_FUNCTION__);
+ close(zlookup->sock);
+ zlookup->sock = -1;
+ zclient_lookup_reconnect(zlookup);
+ return -3;
+ }
+
+ return zclient_read_nexthop(zlookup, nexthop_tab,
+ tab_size, addr);
+}
+
+int zclient_lookup_nexthop(struct zclient *zlookup,
+ struct pim_zlookup_nexthop nexthop_tab[],
+ const int tab_size,
+ struct in_addr addr,
+ int max_lookup)
+{
+ int lookup;
+
+ for (lookup = 0; lookup < max_lookup; ++lookup) {
+ int num_ifindex;
+ int first_ifindex;
+ struct in_addr nexthop_addr;
+
+ num_ifindex = zclient_lookup_nexthop_once(qpim_zclient_lookup, nexthop_tab,
+ PIM_NEXTHOP_IFINDEX_TAB_SIZE, addr);
+ if (num_ifindex < 1) {
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: lookup=%d/%d: could not find nexthop ifindex for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ lookup, max_lookup, addr_str);
+ return -1;
+ }
+
+ /*
+ FIXME: Non-recursive nexthop ensured only for first ifindex.
+ However, recursive route lookup should really be fixed in zebra daemon.
+ See also TODO T24.
+ */
+ first_ifindex = nexthop_tab[0].ifindex;
+ nexthop_addr = nexthop_tab[0].nexthop_addr;
+ if (first_ifindex > 0) {
+ /* found: first ifindex is non-recursive nexthop */
+
+ if (lookup > 0) {
+ /* Report non-recursive success after first lookup */
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_info("%s %s: lookup=%d/%d: found non-recursive ifindex=%d for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ lookup, max_lookup, first_ifindex, addr_str);
+
+ /* use last address as nexthop address */
+ nexthop_tab[0].nexthop_addr = addr;
+ }
+
+ return num_ifindex;
+ }
+
+ {
+ char addr_str[100];
+ char nexthop_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ pim_inet4_dump("<nexthop?>", nexthop_addr, nexthop_str, sizeof(nexthop_str));
+ zlog_warn("%s %s: lookup=%d/%d: zebra returned recursive nexthop %s for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ lookup, max_lookup, nexthop_str, addr_str);
+ }
+
+ addr = nexthop_addr; /* use nexthop addr for recursive lookup */
+
+ } /* for (max_lookup) */
+
+ char addr_str[100];
+ pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+ zlog_warn("%s %s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ lookup, max_lookup, addr_str);
+
+ return -2;
+}
diff --git a/pimd/pim_zlookup.h b/pimd/pim_zlookup.h
new file mode 100644
index 00000000..1f184942
--- /dev/null
+++ b/pimd/pim_zlookup.h
@@ -0,0 +1,47 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIM_ZLOOKUP_H
+#define PIM_ZLOOKUP_H
+
+#include <zebra.h>
+
+#include "zclient.h"
+
+#define PIM_NEXTHOP_LOOKUP_MAX (3) /* max. recursive route lookup */
+
+struct pim_zlookup_nexthop {
+ struct in_addr nexthop_addr;
+ int ifindex;
+ uint32_t route_metric;
+ uint8_t protocol_distance;
+};
+
+struct zclient *zclient_lookup_new(void);
+
+int zclient_lookup_nexthop(struct zclient *zlookup,
+ struct pim_zlookup_nexthop nexthop_tab[],
+ const int tab_size,
+ struct in_addr addr,
+ int max_lookup);
+
+#endif /* PIM_ZLOOKUP_H */
diff --git a/pimd/pimd.c b/pimd/pimd.c
new file mode 100644
index 00000000..71b74e97
--- /dev/null
+++ b/pimd/pimd.c
@@ -0,0 +1,134 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <zebra.h>
+
+#include "log.h"
+#include "memory.h"
+
+#include "pimd.h"
+#include "pim_cmd.h"
+#include "pim_iface.h"
+#include "pim_zebra.h"
+#include "pim_str.h"
+#include "pim_oil.h"
+#include "pim_pim.h"
+#include "pim_upstream.h"
+#include "pim_rand.h"
+#include "pim_rpf.h"
+#include "pim_ssmpingd.h"
+
+const char *const PIM_ALL_SYSTEMS = MCAST_ALL_SYSTEMS;
+const char *const PIM_ALL_ROUTERS = MCAST_ALL_ROUTERS;
+const char *const PIM_ALL_PIM_ROUTERS = MCAST_ALL_PIM_ROUTERS;
+const char *const PIM_ALL_IGMP_ROUTERS = MCAST_ALL_IGMP_ROUTERS;
+
+struct thread_master *master = 0;
+uint32_t qpim_debugs = 0;
+int qpim_mroute_socket_fd = -1;
+int64_t qpim_mroute_socket_creation = 0; /* timestamp of creation */
+struct thread *qpim_mroute_socket_reader = 0;
+int qpim_mroute_oif_highest_vif_index = -1;
+struct list *qpim_channel_oil_list = 0;
+int qpim_t_periodic = PIM_DEFAULT_T_PERIODIC; /* Period between Join/Prune Messages */
+struct list *qpim_upstream_list = 0;
+struct zclient *qpim_zclient_lookup = 0;
+struct pim_assert_metric qpim_infinite_assert_metric;
+long qpim_rpf_cache_refresh_delay_msec = 10000;
+struct thread *qpim_rpf_cache_refresher = 0;
+int64_t qpim_rpf_cache_refresh_requests = 0;
+int64_t qpim_rpf_cache_refresh_events = 0;
+int64_t qpim_rpf_cache_refresh_last = 0;
+struct in_addr qpim_inaddr_any;
+struct list *qpim_ssmpingd_list = 0;
+struct in_addr qpim_ssmpingd_group_addr;
+
+static void pim_free()
+{
+ pim_ssmpingd_destroy();
+
+ if (qpim_channel_oil_list)
+ list_free(qpim_channel_oil_list);
+
+ if (qpim_upstream_list)
+ list_free(qpim_upstream_list);
+}
+
+void pim_init()
+{
+ pim_rand_init();
+
+ if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) {
+ zlog_err("%s %s: could not solve %s to group address: errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ PIM_ALL_PIM_ROUTERS, errno, safe_strerror(errno));
+ zassert(0);
+ return;
+ }
+
+ qpim_channel_oil_list = list_new();
+ if (!qpim_channel_oil_list) {
+ zlog_err("%s %s: failure: channel_oil_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ return;
+ }
+ qpim_channel_oil_list->del = (void (*)(void *)) pim_channel_oil_free;
+
+ qpim_upstream_list = list_new();
+ if (!qpim_upstream_list) {
+ zlog_err("%s %s: failure: upstream_list=list_new()",
+ __FILE__, __PRETTY_FUNCTION__);
+ pim_free();
+ return;
+ }
+ qpim_upstream_list->del = (void (*)(void *)) pim_upstream_free;
+
+ qpim_mroute_socket_fd = -1; /* mark mroute as disabled */
+ qpim_mroute_oif_highest_vif_index = -1;
+
+ zassert(!qpim_debugs);
+ zassert(!PIM_MROUTE_IS_ENABLED);
+
+ qpim_inaddr_any.s_addr = PIM_NET_INADDR_ANY;
+
+ /*
+ RFC 4601: 4.6.3. Assert Metrics
+
+ assert_metric
+ infinite_assert_metric() {
+ return {1,infinity,infinity,0}
+ }
+ */
+ qpim_infinite_assert_metric.rpt_bit_flag = 1;
+ qpim_infinite_assert_metric.metric_preference = PIM_ASSERT_METRIC_PREFERENCE_MAX;
+ qpim_infinite_assert_metric.route_metric = PIM_ASSERT_ROUTE_METRIC_MAX;
+ qpim_infinite_assert_metric.ip_address = qpim_inaddr_any;
+
+ pim_if_init();
+ pim_cmd_init();
+ pim_ssmpingd_init();
+}
+
+void pim_terminate()
+{
+ pim_free();
+}
diff --git a/pimd/pimd.conf.sample b/pimd/pimd.conf.sample
new file mode 100644
index 00000000..67530856
--- /dev/null
+++ b/pimd/pimd.conf.sample
@@ -0,0 +1,41 @@
+!
+! pimd sample configuration file
+! $QuaggaId: $Format:%an, %ai, %h$ $
+!
+hostname quagga-pimd-router
+password zebra
+!enable password zebra
+!
+!log file pimd.log
+log stdout
+!
+line vty
+ exec-timeout 60
+!
+!debug igmp
+!debug pim
+!debug pim zebra
+!
+ip multicast-routing
+!
+! ! You may want to enable ssmpingd for troubleshooting
+! ! See http://www.venaas.no/multicast/ssmping/
+! !
+! ip ssmpingd 1.1.1.1
+! ip ssmpingd 2.2.2.2
+!
+! ! HINTS:
+! ! - Enable "ip pim ssm" on the interface directly attached to the
+! ! multicast source host (if this is the first-hop router)
+! ! - Enable "ip pim ssm" on pim-routers-facing interfaces
+! ! - Enable "ip igmp" on IGMPv3-hosts-facing interfaces
+! ! - In order to inject IGMPv3 local membership information in the
+! ! PIM protocol state, enable both "ip pim ssm" and "ip igmp" on
+! ! the same interface; otherwise PIM won't advertise
+! ! IGMPv3-learned membership to other PIM routers
+!
+interface eth0
+ ip pim ssm
+ ip igmp
+
+! -x-
diff --git a/pimd/pimd.h b/pimd/pimd.h
new file mode 100644
index 00000000..1dcd8654
--- /dev/null
+++ b/pimd/pimd.h
@@ -0,0 +1,138 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#ifndef PIMD_H
+#define PIMD_H
+
+#include <stdint.h>
+
+#include "pim_mroute.h"
+#include "pim_assert.h"
+
+#define PIMD_PROGNAME "pimd"
+#define PIMD_DEFAULT_CONFIG "pimd.conf"
+#define PIMD_VTY_PORT 2611
+#define PIMD_BUG_ADDRESS "http://savannah.nongnu.org/projects/qpimd"
+
+#define PIM_IP_HEADER_MIN_LEN (20)
+#define PIM_IP_HEADER_MAX_LEN (60)
+#define PIM_IP_PROTO_IGMP (2)
+#define PIM_IP_PROTO_PIM (103)
+#define PIM_IGMP_MIN_LEN (8)
+#define PIM_MSG_HEADER_LEN (4)
+#define PIM_PIM_MIN_LEN PIM_MSG_HEADER_LEN
+#define PIM_PROTO_VERSION (2)
+
+#define MCAST_ALL_SYSTEMS "224.0.0.1"
+#define MCAST_ALL_ROUTERS "224.0.0.2"
+#define MCAST_ALL_PIM_ROUTERS "224.0.0.13"
+#define MCAST_ALL_IGMP_ROUTERS "224.0.0.22"
+
+#define PIM_FORCE_BOOLEAN(expr) ((expr) != 0)
+
+#define PIM_NET_INADDR_ANY (htonl(INADDR_ANY))
+#define PIM_INADDR_IS_ANY(addr) ((addr).s_addr == PIM_NET_INADDR_ANY) /* struct in_addr addr */
+#define PIM_INADDR_ISNOT_ANY(addr) ((addr).s_addr != PIM_NET_INADDR_ANY) /* struct in_addr addr */
+
+#define PIM_MASK_PIM_EVENTS (1 << 0)
+#define PIM_MASK_PIM_PACKETS (1 << 1)
+#define PIM_MASK_PIM_PACKETDUMP_SEND (1 << 2)
+#define PIM_MASK_PIM_PACKETDUMP_RECV (1 << 3)
+#define PIM_MASK_PIM_TRACE (1 << 4)
+#define PIM_MASK_IGMP_EVENTS (1 << 5)
+#define PIM_MASK_IGMP_PACKETS (1 << 6)
+#define PIM_MASK_IGMP_TRACE (1 << 7)
+#define PIM_MASK_ZEBRA (1 << 8)
+#define PIM_MASK_SSMPINGD (1 << 9)
+
+const char *const PIM_ALL_SYSTEMS;
+const char *const PIM_ALL_ROUTERS;
+const char *const PIM_ALL_PIM_ROUTERS;
+const char *const PIM_ALL_IGMP_ROUTERS;
+
+struct thread_master *master;
+uint32_t qpim_debugs;
+int qpim_mroute_socket_fd;
+int64_t qpim_mroute_socket_creation; /* timestamp of creation */
+struct thread *qpim_mroute_socket_reader;
+int qpim_mroute_oif_highest_vif_index;
+struct list *qpim_channel_oil_list; /* list of struct channel_oil */
+struct in_addr qpim_all_pim_routers_addr;
+int qpim_t_periodic; /* Period between Join/Prune Messages */
+struct list *qpim_upstream_list; /* list of struct pim_upstream */
+struct zclient *qpim_zclient_lookup;
+struct pim_assert_metric qpim_infinite_assert_metric;
+long qpim_rpf_cache_refresh_delay_msec;
+struct thread *qpim_rpf_cache_refresher;
+int64_t qpim_rpf_cache_refresh_requests;
+int64_t qpim_rpf_cache_refresh_events;
+int64_t qpim_rpf_cache_refresh_last;
+struct in_addr qpim_inaddr_any;
+struct list *qpim_ssmpingd_list; /* list of struct ssmpingd_sock */
+struct in_addr qpim_ssmpingd_group_addr;
+
+#define PIM_JP_HOLDTIME (qpim_t_periodic * 7 / 2)
+
+#define PIM_MROUTE_IS_ENABLED (qpim_mroute_socket_fd >= 0)
+#define PIM_MROUTE_IS_DISABLED (qpim_mroute_socket_fd < 0)
+
+#define PIM_DEBUG_PIM_EVENTS (qpim_debugs & PIM_MASK_PIM_EVENTS)
+#define PIM_DEBUG_PIM_PACKETS (qpim_debugs & PIM_MASK_PIM_PACKETS)
+#define PIM_DEBUG_PIM_PACKETDUMP_SEND (qpim_debugs & PIM_MASK_PIM_PACKETDUMP_SEND)
+#define PIM_DEBUG_PIM_PACKETDUMP_RECV (qpim_debugs & PIM_MASK_PIM_PACKETDUMP_RECV)
+#define PIM_DEBUG_PIM_TRACE (qpim_debugs & PIM_MASK_PIM_TRACE)
+#define PIM_DEBUG_IGMP_EVENTS (qpim_debugs & PIM_MASK_IGMP_EVENTS)
+#define PIM_DEBUG_IGMP_PACKETS (qpim_debugs & PIM_MASK_IGMP_PACKETS)
+#define PIM_DEBUG_IGMP_TRACE (qpim_debugs & PIM_MASK_IGMP_TRACE)
+#define PIM_DEBUG_ZEBRA (qpim_debugs & PIM_MASK_ZEBRA)
+#define PIM_DEBUG_SSMPINGD (qpim_debugs & PIM_MASK_SSMPINGD)
+
+#define PIM_DEBUG_EVENTS (qpim_debugs & (PIM_MASK_PIM_EVENTS | PIM_MASK_IGMP_EVENTS))
+#define PIM_DEBUG_PACKETS (qpim_debugs & (PIM_MASK_PIM_PACKETS | PIM_MASK_IGMP_PACKETS))
+#define PIM_DEBUG_TRACE (qpim_debugs & (PIM_MASK_PIM_TRACE | PIM_MASK_IGMP_TRACE))
+
+#define PIM_DO_DEBUG_PIM_EVENTS (qpim_debugs |= PIM_MASK_PIM_EVENTS)
+#define PIM_DO_DEBUG_PIM_PACKETS (qpim_debugs |= PIM_MASK_PIM_PACKETS)
+#define PIM_DO_DEBUG_PIM_PACKETDUMP_SEND (qpim_debugs |= PIM_MASK_PIM_PACKETDUMP_SEND)
+#define PIM_DO_DEBUG_PIM_PACKETDUMP_RECV (qpim_debugs |= PIM_MASK_PIM_PACKETDUMP_RECV)
+#define PIM_DO_DEBUG_PIM_TRACE (qpim_debugs |= PIM_MASK_PIM_TRACE)
+#define PIM_DO_DEBUG_IGMP_EVENTS (qpim_debugs |= PIM_MASK_IGMP_EVENTS)
+#define PIM_DO_DEBUG_IGMP_PACKETS (qpim_debugs |= PIM_MASK_IGMP_PACKETS)
+#define PIM_DO_DEBUG_IGMP_TRACE (qpim_debugs |= PIM_MASK_IGMP_TRACE)
+#define PIM_DO_DEBUG_ZEBRA (qpim_debugs |= PIM_MASK_ZEBRA)
+#define PIM_DO_DEBUG_SSMPINGD (qpim_debugs |= PIM_MASK_SSMPINGD)
+
+#define PIM_DONT_DEBUG_PIM_EVENTS (qpim_debugs &= ~PIM_MASK_PIM_EVENTS)
+#define PIM_DONT_DEBUG_PIM_PACKETS (qpim_debugs &= ~PIM_MASK_PIM_PACKETS)
+#define PIM_DONT_DEBUG_PIM_PACKETDUMP_SEND (qpim_debugs &= ~PIM_MASK_PIM_PACKETDUMP_SEND)
+#define PIM_DONT_DEBUG_PIM_PACKETDUMP_RECV (qpim_debugs &= ~PIM_MASK_PIM_PACKETDUMP_RECV)
+#define PIM_DONT_DEBUG_PIM_TRACE (qpim_debugs &= ~PIM_MASK_PIM_TRACE)
+#define PIM_DONT_DEBUG_IGMP_EVENTS (qpim_debugs &= ~PIM_MASK_IGMP_EVENTS)
+#define PIM_DONT_DEBUG_IGMP_PACKETS (qpim_debugs &= ~PIM_MASK_IGMP_PACKETS)
+#define PIM_DONT_DEBUG_IGMP_TRACE (qpim_debugs &= ~PIM_MASK_IGMP_TRACE)
+#define PIM_DONT_DEBUG_ZEBRA (qpim_debugs &= ~PIM_MASK_ZEBRA)
+#define PIM_DONT_DEBUG_SSMPINGD (qpim_debugs &= ~PIM_MASK_SSMPINGD)
+
+void pim_init(void);
+void pim_terminate(void);
+
+#endif /* PIMD_H */
diff --git a/pimd/quagga-bootstrap.sh b/pimd/quagga-bootstrap.sh
new file mode 100755
index 00000000..1ad9a121
--- /dev/null
+++ b/pimd/quagga-bootstrap.sh
@@ -0,0 +1,21 @@
+#! /bin/bash
+#
+# Bootstrap Quagga autotools for pimd.
+#
+# Run from quagga's top dir as:
+# ./pimd/quagga-bootstrap.sh
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+me=`basename $0`
+msg () {
+ echo >&2 $me: $*
+}
+
+if [ -f ./bootstrap.sh ]; then
+ msg found ./bootstrap.sh from quagga
+ ./bootstrap.sh
+else
+ msg missing ./bootstrap.sh from quagga
+ autoreconf -i --force
+fi
diff --git a/pimd/quagga-build.sh b/pimd/quagga-build.sh
new file mode 100755
index 00000000..2ad476d0
--- /dev/null
+++ b/pimd/quagga-build.sh
@@ -0,0 +1,10 @@
+#! /bin/bash
+#
+# Build minimum Quagga needed for pimd.
+#
+# Run from quagga's top dir as:
+# ./pimd/quagga-build.sh
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+./pimd/quagga-memtypes.sh && ./pimd/quagga-bootstrap.sh && ./pimd/quagga-configure.sh && make
diff --git a/pimd/quagga-configure.sh b/pimd/quagga-configure.sh
new file mode 100755
index 00000000..45d7be08
--- /dev/null
+++ b/pimd/quagga-configure.sh
@@ -0,0 +1,10 @@
+#! /bin/bash
+#
+# Configure for minimum Quagga build needed for pimd.
+#
+# Run from quagga's top dir as:
+# . pimd/quagga-configure.sh
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+./configure --disable-bgpd --disable-ripd --disable-ripngd --disable-ospfd --disable-ospf6d --disable-watchquagga --disable-bgp-announce --disable-ospfapi --disable-ospfclient --disable-rtadv --disable-irdp --enable-pimd --enable-tcp-zebra --enable-ipv6 --enable-vtysh
diff --git a/pimd/quagga-git-add.sh b/pimd/quagga-git-add.sh
new file mode 100755
index 00000000..3824e984
--- /dev/null
+++ b/pimd/quagga-git-add.sh
@@ -0,0 +1,12 @@
+#! /bin/bash
+#
+# Add to git new files created by qpimd patch
+#
+# Run from quagga's top dir as:
+# ./pimd/quagga-git-add.sh
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+chmod a+rx pimd/*.sh
+git add doc/pimd.8
+git add pimd
diff --git a/pimd/quagga-memtypes.sh b/pimd/quagga-memtypes.sh
new file mode 100755
index 00000000..e86f414b
--- /dev/null
+++ b/pimd/quagga-memtypes.sh
@@ -0,0 +1,22 @@
+#! /bin/bash
+#
+# Check lib/memtypes.h from Quagga
+#
+# Run from quagga's top dir as:
+# ./pimd/quagga-memtypes.sh
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+me=`basename $0`
+msg () {
+ echo >&2 $me: $*
+}
+
+memtypes_h=lib/memtypes.h
+if [ -e $memtypes_h ]; then
+ memtypes_h_size=`ls -s $memtypes_h | cut -d' ' -f1`
+ if [ "$memtypes_h_size" -lt 1 ]; then
+ msg WARNING: removing empty file: $memtypes_h -- awk failed?
+ rm $memtypes_h
+ fi
+fi
diff --git a/pimd/savannah-git-clone.sh b/pimd/savannah-git-clone.sh
new file mode 100755
index 00000000..1aad51bb
--- /dev/null
+++ b/pimd/savannah-git-clone.sh
@@ -0,0 +1,27 @@
+#! /bin/bash
+#
+# Savannah Developer Git Checkout
+#
+# Delete remote branch qpimd: git push origin :qpimd
+# (git push origin :refs/heads/branch_to_delete)
+# Delete remote tag v0.139: git push origin :v0.139
+# (git push origin :refs/tags/tag_to_delete)
+# Create remote-tracking branch: git checkout -b pim0.142 origin/pim0.142
+# Rename branch qpimd to pim: git branch -m qpimd pim
+# Commit changes: git commit -a
+# Send changes: git push --all
+#
+# Recipe to re-sync with Quagga repository:
+# git clone ssh://evertonm@git.sv.gnu.org/srv/git/qpimd.git quagga
+# cd quagga
+# git checkout master
+# git pull git://code.quagga.net/quagga.git master
+# git checkout -b pim origin/pim
+# git rebase master pim
+# # Test, then push back into Savannah repository:
+# git push origin :pim ;# delete remote branch pim
+# git push --all
+#
+# $QuaggaId: $Format:%an, %ai, %h$ $
+
+git clone ssh://evertonm@git.sv.gnu.org/srv/git/qpimd.git quagga
diff --git a/pimd/test_igmpv3_join.c b/pimd/test_igmpv3_join.c
new file mode 100644
index 00000000..179ac035
--- /dev/null
+++ b/pimd/test_igmpv3_join.c
@@ -0,0 +1,149 @@
+/*
+ PIM for Quagga
+ Copyright (C) 2008 Everton da Silva Marques
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+
+ $QuaggaId: $Format:%an, %ai, %h$ $
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+
+#include "pim_igmp_join.h"
+
+const char *prog_name = 0;
+
+static int iface_solve_index(const char *ifname)
+{
+ struct if_nameindex *ini;
+ int ifindex = -1;
+ int i;
+
+ if (!ifname)
+ return -1;
+
+ ini = if_nameindex();
+ if (!ini) {
+ int err = errno;
+ fprintf(stderr,
+ "%s: interface=%s: failure solving index: errno=%d: %s\n",
+ prog_name, ifname, err, strerror(err));
+ errno = err;
+ return -1;
+ }
+
+ for (i = 0; ini[i].if_index; ++i) {
+#if 0
+ fprintf(stderr,
+ "%s: interface=%s matching against local ifname=%s ifindex=%d\n",
+ prog_name, ifname, ini[i].if_name, ini[i].if_index);
+#endif
+ if (!strcmp(ini[i].if_name, ifname)) {
+ ifindex = ini[i].if_index;
+ break;
+ }
+ }
+
+ if_freenameindex(ini);
+
+ return ifindex;
+}
+
+int main(int argc, const char *argv[])
+{
+ struct in_addr group_addr;
+ struct in_addr source_addr;
+ const char *ifname;
+ const char *group;
+ const char *source;
+ int ifindex;
+ int result;
+ int fd;
+
+ prog_name = argv[0];
+
+ fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0) {
+ fprintf(stderr,
+ "%s: could not create socket: socket(): errno=%d: %s\n",
+ prog_name, errno, strerror(errno));
+ exit(1);
+ }
+
+ if (argc != 4) {
+ fprintf(stderr,
+ "usage: %s interface group source\n"
+ "example: %s eth0 232.1.1.1 1.1.1.1\n",
+ prog_name, prog_name);
+ exit(1);
+ }
+
+ ifname = argv[1];
+ group = argv[2];
+ source = argv[3];
+
+ ifindex = iface_solve_index(ifname);
+ if (ifindex < 0) {
+ fprintf(stderr, "%s: could not find interface: %s\n",
+ prog_name, ifname);
+ exit(1);
+ }
+
+ result = inet_pton(AF_INET, group, &group_addr);
+ if (result <= 0) {
+ fprintf(stderr, "%s: bad group address: %s\n",
+ prog_name, group);
+ exit(1);
+ }
+
+ result = inet_pton(AF_INET, source, &source_addr);
+ if (result <= 0) {
+ fprintf(stderr, "%s: bad source address: %s\n",
+ prog_name, source);
+ exit(1);
+ }
+
+ result = pim_igmp_join_source(fd, ifindex, group_addr, source_addr);
+ if (result) {
+ fprintf(stderr,
+ "%s: setsockopt(fd=%d) failure for IGMP group %s source %s ifindex %d on interface %s: errno=%d: %s\n",
+ prog_name, fd, group, source, ifindex, ifname,
+ errno, strerror(errno));
+ exit(1);
+ }
+
+ printf("%s: joined channel (S,G)=(%s,%s) on interface %s\n",
+ prog_name, source, group, ifname);
+
+ printf("%s: waiting...\n", prog_name);
+
+ getchar();
+
+ close(fd);
+
+ printf("%s: left channel (S,G)=(%s,%s) on interface %s\n",
+ prog_name, source, group, ifname);
+
+ exit(0);
+}
diff --git a/ports/Makefile b/ports/Makefile
index d085d06e..86f77bd0 100644
--- a/ports/Makefile
+++ b/ports/Makefile
@@ -54,5 +54,6 @@ post-install:
@echo " ripngd 2603/tcp # RIPngd vty";
@echo " ospfd 2604/tcp # OSPFd vty";
@echo " bgpd 2605/tcp # BGPd vty";
+ @echo " pimd 2611/tcp # PIMd vty";
.include <bsd.port.mk>
diff --git a/ports/pkg/DESCR b/ports/pkg/DESCR
index 0c8d01b7..aeb1950e 100644
--- a/ports/pkg/DESCR
+++ b/ports/pkg/DESCR
@@ -47,6 +47,7 @@ ripd 2602/tcp # RIPd vty
ripngd 2603/tcp # RIPngd vty
ospfd 2604/tcp # OSPFd vty
bgpd 2605/tcp # BGPd vty
+pimd 2611/tcp # PIMd vty
I recommend you to add upper list to /etc/services.
diff --git a/redhat/quagga.spec.in b/redhat/quagga.spec.in
index a8c7fbf3..2d1f2c06 100644
--- a/redhat/quagga.spec.in
+++ b/redhat/quagga.spec.in
@@ -48,16 +48,16 @@
%define quagga_buildreqs %{quagga_buildreqs} patch libcap-devel
# FC4 and 5 split texi2html out of tetex package.
-%if "%dist" != "fc2" || "%dist" != "fc3"
+%if "%dist" == "fc4" || "%dist" == "fc5"
%define quagga_buildreqs %{quagga_buildreqs} texi2html
%endif
# pam_stack is deprecated in FC5
# default to pam_stack, default should be changed later.
-%if "%dist" == "fc4" || "%dist" == "fc3"
-%define quagga_pam_source quagga.pam.stack
-%else
+%if "%dist" == "fc5"
%define quagga_pam_source quagga.pam
+%else
+%define quagga_pam_source quagga.pam.stack
%endif
############################################################################
@@ -303,6 +303,9 @@ zebra_spec_add_service ospfapi 2607/tcp "OSPF-API"
%if %{with_isisd}
zebra_spec_add_service isisd 2608/tcp "ISISd vty"
%endif
+%if %{with_pimd}
+zebra_spec_add_service pimd 2611/tcp "PIMd vty"
+%endif
for daemon in %daemon_list ; do
/sbin/chkconfig --add ${daemon}
diff --git a/ripd/Makefile.am b/ripd/Makefile.am
index 2fa26659..a6d3d398 100644
--- a/ripd/Makefile.am
+++ b/ripd/Makefile.am
@@ -1,7 +1,6 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
INSTALL_SDATA=@INSTALL@ -m 600
AM_CFLAGS = $(PICFLAGS)
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index 57b5f3af..72348a04 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -32,6 +32,7 @@
#include "log.h"
#include "privs.h"
#include "sigevent.h"
+#include "paths.h"
#include "ripd/ripd.h"
@@ -39,6 +40,7 @@
static struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
{ "config_file", required_argument, NULL, 'f'},
{ "pid_file", required_argument, NULL, 'i'},
{ "help", no_argument, NULL, 'h'},
@@ -76,7 +78,7 @@ struct zebra_privs_t ripd_privs =
};
/* Configuration file and directory. */
-char config_default[] = SYSCONFDIR RIPD_DEFAULT_CONFIG;
+char config_default[MAXPATHLEN];
char *config_file = NULL;
/* ripd program name */
@@ -93,8 +95,11 @@ int vty_port = RIP_VTY_PORT;
/* Master of threads. */
struct thread_master *master;
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
+
/* Process ID saved for use by init system */
-const char *pid_file = PATH_RIPD_PID;
+const char *pid_file = pid_file_default;
/* Help information display. */
static void
@@ -107,6 +112,7 @@ usage (char *progname, int status)
printf ("Usage : %s [OPTION...]\n\
Daemon which manages RIP version 1 and 2.\n\n\
-d, --daemon Runs in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
-f, --config_file Set configuration file name\n\
-i, --pid_file Set process identifier file name\n\
-A, --vty_addr Set vty's bind address\n\
@@ -137,7 +143,7 @@ sighup (void)
vty_read_config (config_file, config_default);
/* Create VTY's socket */
- vty_serv_sock (vty_addr, vty_port, RIP_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (RIPD_VTY_NAME));
/* Try to return to normal operation. */
}
@@ -206,7 +212,7 @@ main (int argc, char **argv)
{
int opt;
- opt = getopt_long (argc, argv, "df:i:hA:P:u:g:rvC", longopts, 0);
+ opt = getopt_long (argc, argv, "dN:f:i:hA:P:u:g:rvC", longopts, 0);
if (opt == EOF)
break;
@@ -218,6 +224,9 @@ main (int argc, char **argv)
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'f':
config_file = optarg;
break;
@@ -264,6 +273,9 @@ main (int argc, char **argv)
}
}
+ strcpy (config_default, path_config (RIPD_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (RIPD_PID_NAME));
+
/* Prepare master thread. */
master = thread_master_create ();
@@ -302,7 +314,7 @@ main (int argc, char **argv)
pid_output (pid_file);
/* Create VTY's socket */
- vty_serv_sock (vty_addr, vty_port, RIP_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (RIPD_VTY_NAME));
/* Print banner. */
zlog_notice ("RIPd %s starting: vty@%d", QUAGGA_VERSION, vty_port);
diff --git a/ripd/ripd.h b/ripd/ripd.h
index 45b07b9c..01ca562e 100644
--- a/ripd/ripd.h
+++ b/ripd/ripd.h
@@ -69,7 +69,9 @@
#define RIP_VTY_PORT 2602
/* Default configuration file name. */
-#define RIPD_DEFAULT_CONFIG "ripd.conf"
+#define RIPD_CONFIG_NAME "ripd.conf"
+#define RIPD_PID_NAME "ripd.pid"
+#define RIPD_VTY_NAME "ripd.vty"
/* RIP route types. */
#define RIP_ROUTE_RTE 0
diff --git a/ripngd/Makefile.am b/ripngd/Makefile.am
index c6bd4868..ba52dba7 100644
--- a/ripngd/Makefile.am
+++ b/ripngd/Makefile.am
@@ -1,7 +1,6 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
INSTALL_SDATA=@INSTALL@ -m 600
AM_CFLAGS = $(PICFLAGS)
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index 85209a15..62477b6f 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -34,17 +34,19 @@
#include "if.h"
#include "privs.h"
#include "sigevent.h"
+#include "paths.h"
#include "ripngd/ripngd.h"
/* Configuration filename and directory. */
-char config_default[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG;
+char config_default[MAXPATHLEN];
char *config_file = NULL;
/* RIPngd options. */
struct option longopts[] =
{
{ "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
{ "config_file", required_argument, NULL, 'f'},
{ "pid_file", required_argument, NULL, 'i'},
{ "dryrun", no_argument, NULL, 'C'},
@@ -96,8 +98,11 @@ int vty_port = RIPNG_VTY_PORT;
/* Master of threads. */
struct thread_master *master;
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
+
/* Process ID saved for use by init system */
-const char *pid_file = PATH_RIPNGD_PID;
+const char *pid_file = pid_file_default;
/* Help information display. */
static void
@@ -110,6 +115,7 @@ usage (char *progname, int status)
printf ("Usage : %s [OPTION...]\n\
Daemon which manages RIPng.\n\n\
-d, --daemon Runs in daemon mode\n\
+-N, --namespace Insert argument into all paths\n\
-f, --config_file Set configuration file name\n\
-i, --pid_file Set process identifier file name\n\
-A, --vty_addr Set vty's bind address\n\
@@ -137,7 +143,7 @@ sighup (void)
/* Reload config file. */
vty_read_config (config_file, config_default);
/* Create VTY's socket */
- vty_serv_sock (vty_addr, vty_port, RIPNG_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (RIPNG_VTY_NAME));
/* Try to return to normal operation. */
}
@@ -205,7 +211,7 @@ main (int argc, char **argv)
{
int opt;
- opt = getopt_long (argc, argv, "df:i:hA:P:u:g:vC", longopts, 0);
+ opt = getopt_long (argc, argv, "dN:f:i:hA:P:u:g:vC", longopts, 0);
if (opt == EOF)
break;
@@ -217,6 +223,9 @@ main (int argc, char **argv)
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'f':
config_file = optarg;
break;
@@ -263,6 +272,9 @@ main (int argc, char **argv)
}
}
+ strcpy (config_default, path_config (RIPNG_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (RIPNG_PID_NAME));
+
master = thread_master_create ();
/* Library inits. */
@@ -295,7 +307,7 @@ main (int argc, char **argv)
}
/* Create VTY socket */
- vty_serv_sock (vty_addr, vty_port, RIPNG_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (RIPNG_VTY_NAME));
/* Process id file create. */
pid_output (pid_file);
diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h
index ab06d81b..71615c3c 100644
--- a/ripngd/ripngd.h
+++ b/ripngd/ripngd.h
@@ -51,7 +51,9 @@
#define RIPNG_PEER_TIMER_DEFAULT 180
/* Default config file name. */
-#define RIPNG_DEFAULT_CONFIG "ripngd.conf"
+#define RIPNG_CONFIG_NAME "ripngd.conf"
+#define RIPNG_PID_NAME "ripngd.pid"
+#define RIPNG_VTY_NAME "ripngd.vty"
/* RIPng route types. */
#define RIPNG_ROUTE_RTE 0
diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am
index 791d95dd..5597251f 100644
--- a/vtysh/Makefile.am
+++ b/vtysh/Makefile.am
@@ -1,7 +1,6 @@
## Process this file with Automake to create Makefile.in
INCLUDES = @INCLUDES@ -I$(top_srcdir) -I$(top_srcdir)/lib
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\"
LIBS = @LIBS@ @CURSES@ @LIBPAM@
@@ -32,7 +31,7 @@ vtysh_cmd_FILES = $(top_srcdir)/bgpd/*.c $(top_srcdir)/isisd/*.c \
$(top_srcdir)/zebra/irdp_interface.c \
$(top_srcdir)/zebra/rtadv.c $(top_srcdir)/zebra/zebra_vty.c \
$(top_srcdir)/zebra/zserv.c $(top_srcdir)/zebra/router-id.c \
- $(top_srcdir)/zebra/zebra_routemap.c
+ $(top_srcdir)/zebra/zebra_routemap.c $(top_srcdir)/pimd/pim_cmd.c
vtysh_cmd.c: $(vtysh_cmd_FILES)
./$(EXTRA_DIST) $(vtysh_cmd_FILES) > vtysh_cmd.c
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 3f189adb..fbd1b16c 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -34,6 +34,7 @@
#include "memory.h"
#include "vtysh/vtysh.h"
#include "log.h"
+#include "paths.h"
#include "bgpd/bgp_vty.h"
/* Struct VTY. */
@@ -48,16 +49,16 @@ struct vtysh_client
int fd;
const char *name;
int flag;
- const char *path;
} vtysh_client[] =
{
- { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .path = ZEBRA_VTYSH_PATH},
- { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .path = RIP_VTYSH_PATH},
- { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .path = RIPNG_VTYSH_PATH},
- { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .path = OSPF_VTYSH_PATH},
- { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .path = OSPF6_VTYSH_PATH},
- { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .path = BGP_VTYSH_PATH},
- { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .path = ISIS_VTYSH_PATH},
+ { .fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA},
+ { .fd = -1, .name = "ripd", .flag = VTYSH_RIPD},
+ { .fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD},
+ { .fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD},
+ { .fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D},
+ { .fd = -1, .name = "bgpd", .flag = VTYSH_BGPD},
+ { .fd = -1, .name = "isisd", .flag = VTYSH_ISISD},
+ { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD},
};
#define VTYSH_INDEX_MAX (sizeof(vtysh_client)/sizeof(vtysh_client[0]))
@@ -2103,13 +2104,17 @@ vtysh_connect (struct vtysh_client *vclient)
int sock, len;
struct sockaddr_un addr;
struct stat s_stat;
+ char path[MAXPATHLEN];
+
+ /* figure out path to daemon VTY socket */
+ snprintf (path, sizeof(path), "%s.vty", path_state (vclient->name));
/* Stat socket to see if we have permission to access it. */
- ret = stat (vclient->path, &s_stat);
+ ret = stat (path, &s_stat);
if (ret < 0 && errno != ENOENT)
{
fprintf (stderr, "vtysh_connect(%s): stat = %s\n",
- vclient->path, safe_strerror(errno));
+ path, safe_strerror(errno));
exit(1);
}
@@ -2117,8 +2122,7 @@ vtysh_connect (struct vtysh_client *vclient)
{
if (! S_ISSOCK(s_stat.st_mode))
{
- fprintf (stderr, "vtysh_connect(%s): Not a socket\n",
- vclient->path);
+ fprintf (stderr, "vtysh_connect(%s): Not a socket\n", path);
exit (1);
}
@@ -2128,7 +2132,7 @@ vtysh_connect (struct vtysh_client *vclient)
if (sock < 0)
{
#ifdef DEBUG
- fprintf(stderr, "vtysh_connect(%s): socket = %s\n", vclient->path,
+ fprintf(stderr, "vtysh_connect(%s): socket = %s\n", path,
safe_strerror(errno));
#endif /* DEBUG */
return -1;
@@ -2136,7 +2140,7 @@ vtysh_connect (struct vtysh_client *vclient)
memset (&addr, 0, sizeof (struct sockaddr_un));
addr.sun_family = AF_UNIX;
- strncpy (addr.sun_path, vclient->path, strlen (vclient->path));
+ strncpy (addr.sun_path, path, sizeof (addr.sun_path));
#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
len = addr.sun_len = SUN_LEN(&addr);
#else
@@ -2147,7 +2151,7 @@ vtysh_connect (struct vtysh_client *vclient)
if (ret < 0)
{
#ifdef DEBUG
- fprintf(stderr, "vtysh_connect(%s): connect = %s\n", vclient->path,
+ fprintf(stderr, "vtysh_connect(%s): connect = %s\n", path,
safe_strerror(errno));
#endif /* DEBUG */
close (sock);
diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h
index e711d593..620d35a3 100644
--- a/vtysh/vtysh.h
+++ b/vtysh/vtysh.h
@@ -29,9 +29,10 @@
#define VTYSH_OSPF6D 0x10
#define VTYSH_BGPD 0x20
#define VTYSH_ISISD 0x40
-#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD
+#define VTYSH_PIMD 0x80
+#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD
#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD
-#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD
+#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD
/* vtysh local configuration file. */
#define VTYSH_DEFAULT_CONFIG "vtysh.conf"
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index 4a315a5c..bdff22de 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -33,6 +33,7 @@
#include "getopt.h"
#include "command.h"
#include "memory.h"
+#include "paths.h"
#include "vtysh/vtysh.h"
#include "vtysh/vtysh_user.h"
@@ -41,7 +42,6 @@
char *progname;
/* Configuration file name and directory. */
-char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG;
char history_file[MAXPATHLEN];
/* Flag for indicate executing child command. */
@@ -143,6 +143,7 @@ usage (int status)
"-d, --daemon Connect only to the specified daemon\n" \
"-E, --echo Echo prompt and command in -c mode\n" \
"-C, --dryrun Check configuration for validity and exit\n" \
+ "-N, --namespace Use prefixed daemon socket names\n" \
"-h, --help Display this help and exit\n\n" \
"Note that multiple commands may be executed from the command\n" \
"line by passing multiple -c args, or by embedding linefeed\n" \
@@ -162,6 +163,7 @@ struct option longopts[] =
{ "daemon", required_argument, NULL, 'd'},
{ "echo", no_argument, NULL, 'E'},
{ "dryrun", no_argument, NULL, 'C'},
+ { "namespace", required_argument, NULL, 'N'},
{ "help", no_argument, NULL, 'h'},
{ "noerror", no_argument, NULL, 'n'},
{ 0 }
@@ -237,7 +239,7 @@ main (int argc, char **argv, char **env)
/* Option handling. */
while (1)
{
- opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0);
+ opt = getopt_long (argc, argv, "be:c:d:nEhCN:", longopts, 0);
if (opt == EOF)
break;
@@ -278,6 +280,20 @@ main (int argc, char **argv, char **env)
case 'h':
usage (0);
break;
+ case 'N':
+ /* we're using this as a path component, so...
+ * for the daemons we can assume no malicious tampering
+ * with the cmdline, but for vtysh we have to check
+ */
+ if (strchr (optarg, '/') || optarg[0] == '.')
+ {
+ fprintf (stderr, "The namespace argument may not include "
+ "slashes or start with a dot.\n");
+ break;
+ }
+
+ path_set_namespace (optarg);
+ break;
default:
usage (1);
break;
@@ -302,7 +318,7 @@ main (int argc, char **argv, char **env)
sort_node ();
/* Read vtysh configuration file before connecting to daemons. */
- vtysh_read_config (config_default);
+ vtysh_read_config (path_config (VTYSH_DEFAULT_CONFIG));
/* Start execution only if not in dry-run mode */
if(dryrun)
diff --git a/zebra/Makefile.am b/zebra/Makefile.am
index 542f36f4..828e88ff 100644
--- a/zebra/Makefile.am
+++ b/zebra/Makefile.am
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in.
INCLUDES = @INCLUDES@ -I.. -I$(top_srcdir) -I$(top_srcdir)/lib @SNMP_INCLUDES@
-DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DMULTIPATH_NUM=@MULTIPATH_NUM@
+DEFS = @DEFS@ -DMULTIPATH_NUM=@MULTIPATH_NUM@
INSTALL_SDATA=@INSTALL@ -m 600
LIB_IPV6 = @LIB_IPV6@
diff --git a/zebra/connected.c b/zebra/connected.c
index 95399fa1..0c22582d 100644
--- a/zebra/connected.c
+++ b/zebra/connected.c
@@ -36,6 +36,53 @@
#include "zebra/interface.h"
#include "zebra/connected.h"
extern struct zebra_t zebrad;
+
+#ifdef HAVE_NETLINK
+static const struct message rtscope_str[] = {
+ {RT_SCOPE_UNIVERSE, "global"},
+ {RT_SCOPE_SITE, "site"},
+ {RT_SCOPE_LINK, "link"},
+ {RT_SCOPE_HOST, "host"},
+ {RT_SCOPE_NOWHERE, "nowhere"},
+ {0, NULL}
+};
+
+/* for use in show interface */
+const char *
+connected_scope_name(unsigned value)
+{
+ const char *str;
+ static char buf[16];
+
+ str = lookup (rtscope_str, value);
+ if (!str || !*str) {
+ snprintf (buf, sizeof(buf), "%d", value);
+ str = buf;
+ }
+ return str;
+}
+
+int
+connected_scope_number(const char *name)
+{
+ const struct message *m;
+ char *errptr;
+ unsigned value;
+
+ if (!name || !*name)
+ return -1;
+
+ for (m = rtscope_str; m->str; m++)
+ if (!strcmp (m->str, name))
+ return m->key;
+
+ value = strtoul (name, &errptr, 0);
+ if (*errptr || value > 255)
+ return -1;
+
+ return value;
+}
+#endif /* HAVE_NETLINK */
/* withdraw a connected address */
static void
@@ -112,6 +159,30 @@ connected_check (struct interface *ifp, struct prefix *p)
return NULL;
}
+/* same, but with peer address */
+struct connected *
+connected_check_ptp (struct interface *ifp, struct prefix *p, struct prefix *d)
+{
+ struct connected *ifc;
+ struct listnode *node;
+
+ /* ignore broadcast addresses */
+ if (p->prefixlen != IPV4_MAX_PREFIXLEN)
+ d = NULL;
+
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
+ {
+ if (!prefix_same (ifc->address, p))
+ continue;
+ if (!CONNECTED_PEER(ifc) && !d)
+ return ifc;
+ if (CONNECTED_PEER(ifc) && d && prefix_same (ifc->destination, d))
+ return ifc;
+ }
+
+ return NULL;
+}
+
/* Check if two ifc's describe the same address */
static int
connected_same (struct connected *ifc1, struct connected *ifc2)
@@ -148,7 +219,7 @@ connected_implicit_withdraw (struct interface *ifp, struct connected *ifc)
struct connected *current;
/* Check same connected route. */
- if ((current = connected_check (ifp, (struct prefix *) ifc->address)))
+ if ((current = connected_check_ptp (ifp, ifc->address, ifc->destination)))
{
if (CHECK_FLAG(current->conf, ZEBRA_IFC_CONFIGURED))
SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);
@@ -198,7 +269,7 @@ connected_up_ipv4 (struct interface *ifp, struct connected *ifc)
void
connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
u_char prefixlen, struct in_addr *broad,
- const char *label)
+ const char *label, unsigned scope, int preference)
{
struct prefix_ipv4 *p;
struct connected *ifc;
@@ -212,7 +283,8 @@ connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
p = prefix_ipv4_new ();
p->family = AF_INET;
p->prefix = *addr;
- p->prefixlen = prefixlen;
+ p->prefixlen = CHECK_FLAG(flags, ZEBRA_IFA_PEER)
+ ? IPV4_MAX_PREFIXLEN : prefixlen;
ifc->address = (struct prefix *) p;
/* If there is broadcast or peer address. */
@@ -269,6 +341,9 @@ connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
if (label)
ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
+ ifc->scope = scope;
+ ifc->preference = preference;
+
/* nothing to do? */
if ((ifc = connected_implicit_withdraw (ifp, ifc)) == NULL)
return;
@@ -305,15 +380,27 @@ void
connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
u_char prefixlen, struct in_addr *broad)
{
- struct prefix_ipv4 p;
+ struct prefix_ipv4 p, d;
struct connected *ifc;
memset (&p, 0, sizeof (struct prefix_ipv4));
p.family = AF_INET;
p.prefix = *addr;
- p.prefixlen = prefixlen;
+ p.prefixlen = CHECK_FLAG(flags, ZEBRA_IFA_PEER)
+ ? IPV4_MAX_PREFIXLEN : prefixlen;
+
+ if (broad)
+ {
+ memset (&d, 0, sizeof (struct prefix_ipv4));
+ d.family = AF_INET;
+ d.prefix = *broad;
+ d.prefixlen = prefixlen;
+ ifc = connected_check_ptp (ifp, (struct prefix *) &p,
+ (struct prefix *) &d);
+ }
+ else
+ ifc = connected_check_ptp (ifp, (struct prefix *) &p, NULL);
- ifc = connected_check (ifp, (struct prefix *) &p);
if (! ifc)
return;
@@ -352,7 +439,7 @@ connected_up_ipv6 (struct interface *ifp, struct connected *ifc)
void
connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *addr,
u_char prefixlen, struct in6_addr *broad,
- const char *label)
+ const char *label, unsigned scope)
{
struct prefix_ipv6 *p;
struct connected *ifc;
@@ -395,7 +482,9 @@ connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *addr,
/* Label of this address. */
if (label)
ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
-
+
+ ifc->scope = scope;
+
if ((ifc = connected_implicit_withdraw (ifp, ifc)) == NULL)
return;
diff --git a/zebra/connected.h b/zebra/connected.h
index 9595ddb1..ede75120 100644
--- a/zebra/connected.h
+++ b/zebra/connected.h
@@ -25,11 +25,13 @@
extern struct connected *
connected_check (struct interface *ifp, struct prefix *p);
+extern struct connected *
+connected_check_ptp (struct interface *ifp, struct prefix *p, struct prefix *d);
extern void
connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
u_char prefixlen, struct in_addr *broad,
- const char *label);
+ const char *label, unsigned scope, int preference);
extern void
connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr,
@@ -42,7 +44,7 @@ extern void connected_down_ipv4 (struct interface *, struct connected *);
extern void
connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *address,
u_char prefixlen, struct in6_addr *broad,
- const char *label);
+ const char *label, unsigned scope);
extern void
connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address,
u_char prefixlen, struct in6_addr *broad);
@@ -52,4 +54,9 @@ extern void connected_down_ipv6 (struct interface *ifp, struct connected *);
#endif /* HAVE_IPV6 */
+#ifdef HAVE_NETLINK
+extern const char *connected_scope_name (unsigned value);
+extern int connected_scope_number (const char *name);
+#endif /* HAVE_NETLINK */
+
#endif /*_ZEBRA_CONNECTED_H */
diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c
index f357e154..36732704 100644
--- a/zebra/if_ioctl.c
+++ b/zebra/if_ioctl.c
@@ -276,7 +276,7 @@ if_getaddrs (void)
}
connected_add_ipv4 (ifp, flags, &addr->sin_addr,
- prefixlen, dest_pnt, NULL);
+ prefixlen, dest_pnt, NULL, 0, 0);
}
#ifdef HAVE_IPV6
if (ifap->ifa_addr->sa_family == AF_INET6)
@@ -321,7 +321,7 @@ if_getaddrs (void)
#endif
connected_add_ipv6 (ifp, flags, &addr->sin6_addr, prefixlen,
- dest_pnt, NULL);
+ dest_pnt, NULL, 0);
}
#endif /* HAVE_IPV6 */
}
@@ -412,7 +412,7 @@ if_get_addr (struct interface *ifp)
/* Set address to the interface. */
- connected_add_ipv4 (ifp, flags, &addr.sin_addr, prefixlen, dest_pnt, NULL);
+ connected_add_ipv4 (ifp, flags, &addr.sin_addr, prefixlen, dest_pnt, NULL, 0, 0);
return 0;
}
diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c
index fc384ea2..736232e8 100644
--- a/zebra/if_ioctl_solaris.c
+++ b/zebra/if_ioctl_solaris.c
@@ -327,11 +327,11 @@ if_get_addr (struct interface *ifp, struct sockaddr *addr, const char *label)
/* Set address to the interface. */
if (af == AF_INET)
connected_add_ipv4 (ifp, flags, &SIN (addr)->sin_addr, prefixlen,
- (struct in_addr *) dest_pnt, label);
+ (struct in_addr *) dest_pnt, label, 0, 0);
#ifdef HAVE_IPV6
else if (af == AF_INET6)
connected_add_ipv6 (ifp, flags, &SIN6 (addr)->sin6_addr, prefixlen,
- (struct in6_addr *) dest_pnt, label);
+ (struct in6_addr *) dest_pnt, label, 0);
#endif /* HAVE_IPV6 */
return 0;
diff --git a/zebra/if_proc.c b/zebra/if_proc.c
index 3aec530b..6c538116 100644
--- a/zebra/if_proc.c
+++ b/zebra/if_proc.c
@@ -240,7 +240,7 @@ ifaddr_proc_ipv6 ()
str2in6_addr (addr, &p.prefix);
p.prefixlen = plen;
- connected_add_ipv6 (ifp, 0, &p.prefix, p.prefixlen, NULL, ifname);
+ connected_add_ipv6 (ifp, 0, &p.prefix, p.prefixlen, NULL, ifname, 0);
}
fclose (fp);
return 0;
diff --git a/zebra/interface.c b/zebra/interface.c
index ba4cf25f..e19648d7 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -83,6 +83,10 @@ if_zebra_new_hook (struct interface *ifp)
rtadv->DefaultPreference = RTADV_PREF_MEDIUM;
rtadv->AdvPrefixList = list_new ();
+
+ rtadv->AdvRDNSSFlag = 0;
+ rtadv->AdvRDNSSLifetime = RTADV_RDNSS_DEFAULT_LIFETIME;
+ rtadv->AdvRDNSSList = list_new ();
}
#endif /* RTADV */
@@ -127,7 +131,7 @@ if_subnet_add (struct interface *ifp, struct connected *ifc)
/* Get address derived subnet node and associated address list, while marking
address secondary attribute appropriately. */
- cp = *ifc->address;
+ cp = *CONNECTED_PREFIX(ifc);
apply_mask (&cp);
rn = route_node_get (zebra_if->ipv4_subnets, &cp);
@@ -154,12 +158,16 @@ if_subnet_delete (struct interface *ifp, struct connected *ifc)
struct route_node *rn;
struct zebra_if *zebra_if;
struct list *addr_list;
+ struct prefix cp;
assert (ifp && ifp->info && ifc);
zebra_if = ifp->info;
+ cp = *CONNECTED_PREFIX(ifc);
+ apply_mask (&cp);
+
/* Get address derived subnet node. */
- rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address);
+ rn = route_node_lookup (zebra_if->ipv4_subnets, &cp);
if (! (rn && rn->info))
return -1;
route_unlock_node (rn);
@@ -588,8 +596,18 @@ connected_dump_vty (struct vty *vty, struct connected *connected)
{
vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast "));
prefix_vty_out (vty, connected->destination);
+ vty_out (vty, "/%d", connected->destination->prefixlen);
}
+#ifdef HAVE_NETLINK
+ if (connected->scope != 0)
+ vty_out (vty, " scope %s", connected_scope_name (connected->scope));
+#endif
+#ifdef SIOCSIFADDRPREF
+ if (connected->preference != 0)
+ vty_out (vty, " preference %d", connected->preference);
+#endif
+
if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY))
vty_out (vty, " secondary");
@@ -641,6 +659,9 @@ nd_dump_vty (struct vty *vty, struct interface *ifp)
vty_out (vty, " ND router advertisements with "
"Home Agent flag bit set.%s",
VTY_NEWLINE);
+ if (rtadv->AdvRDNSSFlag)
+ vty_out (vty, " ND router advertisements with "
+ "RDNSS information.%s", VTY_NEWLINE);
if (rtadv->AdvIntervalOption)
vty_out (vty, " ND router advertisements with Adv. Interval option.%s",
VTY_NEWLINE);
@@ -1002,6 +1023,53 @@ DEFUN (no_multicast,
return CMD_SUCCESS;
}
+DEFUN (unnumbered,
+ unnumbered_cmd,
+ "unnumbered",
+ "Set interface to IP Unnumbered mode\n")
+{
+ int ret;
+ struct interface *ifp;
+ struct zebra_if *if_data;
+
+ ifp = (struct interface *) vty->index;
+
+ zlog_debug("VTY: interface %s, Setting ifp->status |= ZEBRA_INTERFACE_UNNUMBERED",
+ ifp->name);
+
+ SET_FLAG(ifp->status, ZEBRA_INTERFACE_UNNUMBERED);
+
+ /* force protocols to recalculate routes due to IP change */
+ if (if_is_operative (ifp))
+ zebra_interface_up_update (ifp);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_unnumbered,
+ no_unnumbered_cmd,
+ "no unnumbered",
+ NO_STR
+ "Set interface to IP Numbered mode\n")
+{
+ int ret;
+ struct interface *ifp;
+ struct zebra_if *if_data;
+
+ ifp = (struct interface *) vty->index;
+
+ zlog_debug("VTY: interface %s, Setting ifp->status &= ~ZEBRA_INTERFACE_UNNUMBERED;",
+ ifp->name);
+
+ UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_UNNUMBERED);
+
+ /* force protocols to recalculate routes due to IP change */
+ if (if_is_operative (ifp))
+ zebra_interface_up_update (ifp);
+
+ return CMD_SUCCESS;
+}
+
DEFUN (linkdetect,
linkdetect_cmd,
"link-detect",
@@ -1149,21 +1217,62 @@ ALIAS (no_bandwidth_if,
static int
ip_address_install (struct vty *vty, struct interface *ifp,
const char *addr_str, const char *peer_str,
- const char *label)
+ const char *label, const char *scope,
+ const char *preference)
{
- struct prefix_ipv4 cp;
+ struct prefix_ipv4 lp, pp;
struct connected *ifc;
struct prefix_ipv4 *p;
int ret;
+ int scopev = 0, preferencev = 0;
- ret = str2prefix_ipv4 (addr_str, &cp);
+ ret = str2prefix_ipv4 (addr_str, &lp);
if (ret <= 0)
+ {
+ vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (peer_str)
{
- vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
- return CMD_WARNING;
+ if (lp.prefixlen != 32)
+ {
+ vty_out (vty, "%% Local prefix length for P-t-P address "
+ "must be /32%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ ret = str2prefix_ipv4 (peer_str, &pp);
+ if (ret <= 0)
+ {
+ vty_out (vty, "%% Malformed peer address %s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
}
- ifc = connected_check (ifp, (struct prefix *) &cp);
+#ifdef HAVE_NETLINK
+ if (scope)
+ {
+ scopev = connected_scope_number (scope);
+ if (scopev < 0)
+ {
+ vty_out (vty, "%% Malformed scope %s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+#endif
+ if (preference)
+ {
+ preferencev = atoi (preference);
+ if (preferencev < -32768 || preferencev > 32767)
+ {
+ vty_out (vty, "%% Invalid preference %s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ ifc = connected_check_ptp (ifp, (struct prefix *) &lp,
+ (struct prefix *)(peer_str ? &pp : NULL));
if (! ifc)
{
ifc = connected_new ();
@@ -1171,14 +1280,23 @@ ip_address_install (struct vty *vty, struct interface *ifp,
/* Address. */
p = prefix_ipv4_new ();
- *p = cp;
+ *p = lp;
ifc->address = (struct prefix *) p;
+ ifc->scope = scopev;
+ ifc->preference = preferencev;
- /* Broadcast. */
- if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2)
+ if (peer_str)
{
+ SET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
p = prefix_ipv4_new ();
- *p = cp;
+ *p = pp;
+ ifc->destination = (struct prefix *) p;
+ }
+ else if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2)
+ {
+ /* Broadcast. */
+ p = prefix_ipv4_new ();
+ *p = lp;
p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen);
ifc->destination = (struct prefix *) p;
}
@@ -1233,23 +1351,40 @@ ip_address_install (struct vty *vty, struct interface *ifp,
static int
ip_address_uninstall (struct vty *vty, struct interface *ifp,
- const char *addr_str, const char *peer_str,
- const char *label)
+ const char *addr_str, const char *peer_str)
{
- struct prefix_ipv4 cp;
+ struct prefix_ipv4 lp, pp;
struct connected *ifc;
int ret;
/* Convert to prefix structure. */
- ret = str2prefix_ipv4 (addr_str, &cp);
+ ret = str2prefix_ipv4 (addr_str, &lp);
if (ret <= 0)
{
vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
return CMD_WARNING;
}
+ if (peer_str)
+ {
+ if (lp.prefixlen != 32)
+ {
+ vty_out (vty, "%% Local prefix length for P-t-P address "
+ "must be /32%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ ret = str2prefix_ipv4 (peer_str, &pp);
+ if (ret <= 0)
+ {
+ vty_out (vty, "%% Malformed peer address %s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
/* Check current interface address. */
- ifc = connected_check (ifp, (struct prefix *) &cp);
+ ifc = connected_check_ptp (ifp, (struct prefix *) &lp,
+ (struct prefix *)(peer_str ? &pp : NULL));
if (! ifc)
{
vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
@@ -1279,70 +1414,169 @@ ip_address_uninstall (struct vty *vty, struct interface *ifp,
safe_strerror(errno), VTY_NEWLINE);
return CMD_WARNING;
}
+ /* success! now update all internal state... */
+
+ /* Remove connected route. */
+ connected_down_ipv4 (ifp, ifc);
-#if 0
/* Redistribute this information. */
zebra_interface_address_delete_update (ifp, ifc);
- /* Remove connected route. */
- connected_down_ipv4 (ifp, ifc);
+ /* IP address propery set. */
+ UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
+
+ /* remove from interface, remark secondaries */
+ if_subnet_delete (ifp, ifc);
/* Free address information. */
listnode_delete (ifp->connected, ifc);
connected_free (ifc);
-#endif
return CMD_SUCCESS;
}
+#define IP_ADDR_STR \
+ "Interface Internet Protocol config commands\n" \
+ "Set the IP address of an interface\n" \
+ "IP address (e.g. 10.0.0.1/8)\n"
+#define IP_ADDR_PEER_STR \
+ "Interface Internet Protocol config commands\n" \
+ "Set the IP address of an interface\n" \
+ "Local IP (e.g. 10.0.0.1) for P-t-P address\n" \
+ "Specify P-t-P address\n" \
+ "Peer IP address (e.g. 10.0.0.1/8)\n"
+
DEFUN (ip_address,
ip_address_cmd,
"ip address A.B.C.D/M",
- "Interface Internet Protocol config commands\n"
- "Set the IP address of an interface\n"
- "IP address (e.g. 10.0.0.1/8)\n")
+ IP_ADDR_STR)
{
- return ip_address_install (vty, vty->index, argv[0], NULL, NULL);
+ return ip_address_install (vty, vty->index, argv[0], NULL,
+ NULL, NULL, NULL);
}
DEFUN (no_ip_address,
no_ip_address_cmd,
"no ip address A.B.C.D/M",
- NO_STR
- "Interface Internet Protocol config commands\n"
- "Set the IP address of an interface\n"
- "IP Address (e.g. 10.0.0.1/8)")
+ NO_STR IP_ADDR_STR)
+{
+ return ip_address_uninstall (vty, vty->index, argv[0], NULL);
+}
+
+DEFUN (ip_address_peer,
+ ip_address_peer_cmd,
+ "ip address A.B.C.D peer A.B.C.D/M",
+ IP_ADDR_PEER_STR)
+{
+ return ip_address_install (vty, vty->index, argv[0], argv[1],
+ NULL, NULL, NULL);
+}
+
+DEFUN (no_ip_address_peer,
+ no_ip_address_peer_cmd,
+ "no ip address A.B.C.D peer A.B.C.D/M",
+ NO_STR IP_ADDR_PEER_STR)
{
- return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL);
+ return ip_address_uninstall (vty, vty->index, argv[0], argv[1]);
}
#ifdef HAVE_NETLINK
DEFUN (ip_address_label,
ip_address_label_cmd,
"ip address A.B.C.D/M label LINE",
- "Interface Internet Protocol config commands\n"
- "Set the IP address of an interface\n"
- "IP address (e.g. 10.0.0.1/8)\n"
+ IP_ADDR_STR
"Label of this address\n"
"Label\n")
{
- return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]);
+ return ip_address_install (vty, vty->index, argv[0], NULL,
+ argv[1], NULL, NULL);
}
-DEFUN (no_ip_address_label,
- no_ip_address_label_cmd,
- "no ip address A.B.C.D/M label LINE",
- NO_STR
- "Interface Internet Protocol config commands\n"
- "Set the IP address of an interface\n"
- "IP address (e.g. 10.0.0.1/8)\n"
+DEFUN (ip_address_peer_label,
+ ip_address_peer_label_cmd,
+ "ip address A.B.C.D peer A.B.C.D/M label LINE",
+ IP_ADDR_PEER_STR
"Label of this address\n"
"Label\n")
{
- return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]);
+ return ip_address_install (vty, vty->index, argv[0], argv[1],
+ argv[2], NULL, NULL);
+}
+
+DEFUN (ip_address_scope,
+ ip_address_scope_cmd,
+ "ip address A.B.C.D/M scope WORD",
+ IP_ADDR_STR
+ "Scope of this address\n"
+ "Scope (e.g. 0-255 or global,site,link,host,nowhere)\n")
+{
+ return ip_address_install (vty, vty->index, argv[0], NULL,
+ NULL, argv[1], NULL);
+}
+
+DEFUN (ip_address_peer_scope,
+ ip_address_peer_scope_cmd,
+ "ip address A.B.C.D peer A.B.C.D/M scope WORD",
+ IP_ADDR_PEER_STR
+ "Scope of this address\n"
+ "Scope (e.g. 0-255 or global,site,link,host,nowhere)\n")
+{
+ return ip_address_install (vty, vty->index, argv[0], argv[1],
+ NULL, argv[2], NULL);
}
+
+DEFUN (ip_address_scope_label,
+ ip_address_scope_label_cmd,
+ "ip address A.B.C.D/M scope WORD label LINE",
+ IP_ADDR_STR
+ "Scope of this address\n"
+ "Scope (e.g. 0-255 or global,site,link,host,nowhere)\n"
+ "Label of this address\n"
+ "Label\n")
+{
+ return ip_address_install (vty, vty->index, argv[0], NULL,
+ argv[2], argv[1], NULL);
+}
+
+DEFUN (ip_address_peer_scope_label,
+ ip_address_peer_scope_label_cmd,
+ "ip address A.B.C.D peer A.B.C.D/M scope WORD label LINE",
+ IP_ADDR_PEER_STR
+ "Scope of this address\n"
+ "Scope (e.g. 0-255 or global,site,link,host,nowhere)\n"
+ "Label of this address\n"
+ "Label\n")
+{
+ return ip_address_install (vty, vty->index, argv[0], argv[1],
+ argv[3], argv[2], NULL);
+}
+
#endif /* HAVE_NETLINK */
+#ifdef SIOCSIFADDRPREF
+DEFUN (ip_address_pref,
+ ip_address_pref_cmd,
+ "ip address A.B.C.D/M preference WORD",
+ IP_ADDR_STR
+ "specify IPSRCSEL preference\n"
+ "preference value, higher is preferred\n")
+{
+ return ip_address_install (vty, vty->index, argv[0], NULL,
+ NULL, NULL, argv[1]);
+}
+
+DEFUN (ip_address_peer_pref,
+ ip_address_peer_pref_cmd,
+ "ip address A.B.C.D peer A.B.C.D/M preference WORD",
+ IP_ADDR_PEER_STR
+ "specify IPSRCSEL preference\n"
+ "preference value, higher is preferred\n")
+{
+ return ip_address_install (vty, vty->index, argv[0], argv[1],
+ NULL, NULL, argv[2]);
+}
+#endif
+
#ifdef HAVE_IPV6
static int
ipv6_address_install (struct vty *vty, struct interface *ifp,
@@ -1531,6 +1765,9 @@ if_config_write (struct vty *vty)
if (ifp->bandwidth != 0)
vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
+ if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_UNNUMBERED))
+ vty_out (vty, " unnumbered%s", VTY_NEWLINE);
+
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
vty_out(vty, " link-detect%s", VTY_NEWLINE);
@@ -1540,14 +1777,27 @@ if_config_write (struct vty *vty)
{
char buf[INET6_ADDRSTRLEN];
p = ifc->address;
- vty_out (vty, " ip%s address %s/%d",
+ vty_out (vty, " ip%s address %s",
p->family == AF_INET ? "" : "v6",
- inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)),
- p->prefixlen);
+ inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)));
+ if (CONNECTED_PEER (ifc))
+ {
+ p = ifc->destination;
+ vty_out (vty, " peer %s",
+ inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)));
+ }
+ vty_out (vty, "/%d", p->prefixlen);
+#ifdef HAVE_NETLINK
+ if (ifc->scope)
+ vty_out (vty, " scope %s", connected_scope_name (ifc->scope));
if (ifc->label)
vty_out (vty, " label %s", ifc->label);
-
+#endif
+#ifdef SIOCSIFADDRPREF
+ if (ifc->preference)
+ vty_out (vty, " preference %d", ifc->preference);
+#endif
vty_out (vty, "%s", VTY_NEWLINE);
}
}
@@ -1598,6 +1848,8 @@ zebra_if_init (void)
install_element (INTERFACE_NODE, &no_interface_desc_cmd);
install_element (INTERFACE_NODE, &multicast_cmd);
install_element (INTERFACE_NODE, &no_multicast_cmd);
+ install_element (INTERFACE_NODE, &unnumbered_cmd);
+ install_element (INTERFACE_NODE, &no_unnumbered_cmd);
install_element (INTERFACE_NODE, &linkdetect_cmd);
install_element (INTERFACE_NODE, &no_linkdetect_cmd);
install_element (INTERFACE_NODE, &shutdown_if_cmd);
@@ -1607,12 +1859,22 @@ zebra_if_init (void)
install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
install_element (INTERFACE_NODE, &ip_address_cmd);
install_element (INTERFACE_NODE, &no_ip_address_cmd);
+ install_element (INTERFACE_NODE, &ip_address_peer_cmd);
+ install_element (INTERFACE_NODE, &no_ip_address_peer_cmd);
#ifdef HAVE_IPV6
install_element (INTERFACE_NODE, &ipv6_address_cmd);
install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
#endif /* HAVE_IPV6 */
#ifdef HAVE_NETLINK
install_element (INTERFACE_NODE, &ip_address_label_cmd);
- install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
+ install_element (INTERFACE_NODE, &ip_address_scope_cmd);
+ install_element (INTERFACE_NODE, &ip_address_scope_label_cmd);
+ install_element (INTERFACE_NODE, &ip_address_peer_label_cmd);
+ install_element (INTERFACE_NODE, &ip_address_peer_scope_cmd);
+ install_element (INTERFACE_NODE, &ip_address_peer_scope_label_cmd);
#endif /* HAVE_NETLINK */
+#ifdef SIOCSIFADDRPREF
+ install_element (INTERFACE_NODE, &ip_address_pref_cmd);
+ install_element (INTERFACE_NODE, &ip_address_peer_pref_cmd);
+#endif
}
diff --git a/zebra/interface.h b/zebra/interface.h
index 0cf66403..305abaac 100644
--- a/zebra/interface.h
+++ b/zebra/interface.h
@@ -178,6 +178,20 @@ struct rtadvconf
Default: 0 (medium) */
int DefaultPreference;
#define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */
+
+ /* A list of Recursive DNS server addresses specified in
+ RFC 5006 */
+ int AdvRDNSSFlag;
+ struct list *AdvRDNSSList;
+
+ /* the maximum lifetime in seconds over which the RDNSS entry
+ * may be used. After this time a host may send a router solicitation
+ * message to refresh the RDNSS information.
+ *
+ * Default is infinity lifetime (0xffffffff) */
+ uint32_t AdvRDNSSLifetime;
+#define RTADV_RDNSS_INFINITY_LIFETIME (0xffffffff)
+#define RTADV_RDNSS_DEFAULT_LIFETIME RTADV_RDNSS_INFINITY_LIFETIME
};
#endif /* RTADV */
diff --git a/zebra/ioctl.c b/zebra/ioctl.c
index d783b0a3..6cb428a7 100644
--- a/zebra/ioctl.c
+++ b/zebra/ioctl.c
@@ -191,10 +191,16 @@ if_set_prefix (struct interface *ifp, struct connected *ifc)
{
int ret;
struct ifaliasreq addreq;
- struct sockaddr_in addr;
- struct sockaddr_in mask;
+ struct sockaddr_in addr, mask, peer;
struct prefix_ipv4 *p;
+ /* don't configure PtP addresses on broadcast ifs or reverse */
+ if (!(ifp->flags & IFF_POINTOPOINT) != !CONNECTED_PEER (ifc))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
p = (struct prefix_ipv4 *) ifc->address;
rib_lookup_and_pushup (p);
@@ -209,6 +215,18 @@ if_set_prefix (struct interface *ifp, struct connected *ifc)
#endif
memcpy (&addreq.ifra_addr, &addr, sizeof (struct sockaddr_in));
+ if (CONNECTED_PEER (ifc))
+ {
+ p = (struct prefix_ipv4 *) ifc->destination;
+ memset (&mask, 0, sizeof (struct sockaddr_in));
+ peer.sin_addr = p->prefix;
+ peer.sin_family = p->family;
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
+ peer.sin_len = sizeof (struct sockaddr_in);
+#endif
+ memcpy (&addreq.ifra_broadaddr, &peer, sizeof (struct sockaddr_in));
+ }
+
memset (&mask, 0, sizeof (struct sockaddr_in));
masklen2ip (p->prefixlen, &mask.sin_addr);
mask.sin_family = p->family;
@@ -216,10 +234,27 @@ if_set_prefix (struct interface *ifp, struct connected *ifc)
mask.sin_len = sizeof (struct sockaddr_in);
#endif
memcpy (&addreq.ifra_mask, &mask, sizeof (struct sockaddr_in));
-
+
ret = if_ioctl (SIOCAIFADDR, (caddr_t) &addreq);
if (ret < 0)
return ret;
+
+#ifdef SIOCSIFADDRPREF
+ if (ifc->preference != 0)
+ {
+ struct if_addrprefreq ifapr;
+
+ memset (&ifapr, 0, sizeof ifapr);
+ strncpy ((char *)&ifapr.ifap_name, ifp->name, sizeof ifapr.ifap_name);
+ ifapr.ifap_preference = ifc->preference;
+ memcpy (&ifapr.ifap_addr, &addr, sizeof (struct sockaddr_in));
+
+ ret = if_ioctl (SIOCSIFADDRPREF, (caddr_t) &ifapr);
+ if (ret < 0)
+ zlog_err("if_ioctl(SIOCSIFADDRPREF) failed: %s",
+ safe_strerror(errno));
+ }
+#endif
return 0;
}
@@ -230,10 +265,16 @@ if_unset_prefix (struct interface *ifp, struct connected *ifc)
{
int ret;
struct ifaliasreq addreq;
- struct sockaddr_in addr;
- struct sockaddr_in mask;
+ struct sockaddr_in addr, mask, peer;
struct prefix_ipv4 *p;
+ /* this would probably wreak havoc */
+ if (!(ifp->flags & IFF_POINTOPOINT) != !CONNECTED_PEER (ifc))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
p = (struct prefix_ipv4 *)ifc->address;
memset (&addreq, 0, sizeof addreq);
@@ -247,6 +288,18 @@ if_unset_prefix (struct interface *ifp, struct connected *ifc)
#endif
memcpy (&addreq.ifra_addr, &addr, sizeof (struct sockaddr_in));
+ if (CONNECTED_PEER (ifc))
+ {
+ p = (struct prefix_ipv4 *) ifc->destination;
+ memset (&mask, 0, sizeof (struct sockaddr_in));
+ peer.sin_addr = p->prefix;
+ peer.sin_family = p->family;
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
+ peer.sin_len = sizeof (struct sockaddr_in);
+#endif
+ memcpy (&addreq.ifra_broadaddr, &peer, sizeof (struct sockaddr_in));
+ }
+
memset (&mask, 0, sizeof (struct sockaddr_in));
masklen2ip (p->prefixlen, &mask.sin_addr);
mask.sin_family = p->family;
diff --git a/zebra/kernel_null.c b/zebra/kernel_null.c
index 6b96c6df..f83c2345 100644
--- a/zebra/kernel_null.c
+++ b/zebra/kernel_null.c
@@ -25,7 +25,7 @@ int kernel_address_add_ipv4 (struct interface *a, struct connected *b)
SET_FLAG (b->conf, ZEBRA_IFC_REAL);
connected_add_ipv4 (a, 0, &b->address->u.prefix4, b->address->prefixlen,
(b->destination ? &b->destination->u.prefix4 : NULL),
- NULL);
+ NULL, 0, 0);
return 0;
}
diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c
index feeaf5d0..d0908115 100644
--- a/zebra/kernel_socket.c
+++ b/zebra/kernel_socket.c
@@ -253,6 +253,25 @@ rtm_flag_dump (int flag)
zlog_debug ("Kernel: %s", buf);
}
+/* NetBSD IPSRCSEL preference readback */
+static int
+if_get_addrpref (const char *ifname, struct sockaddr_in *addr)
+{
+#ifdef SIOCSIFADDRPREF
+ int ret;
+ struct if_addrprefreq ifapr;
+
+ memset (&ifapr, 0, sizeof ifapr);
+ strncpy ((char *)&ifapr.ifap_name, ifname, sizeof ifapr.ifap_name);
+ memcpy (&ifapr.ifap_addr, addr, sizeof (struct sockaddr_in));
+
+ ret = if_ioctl (SIOCGIFADDRPREF, (caddr_t) &ifapr);
+ if (ret == 0)
+ return ifapr.ifap_preference;
+#endif
+ return 0;
+}
+
#ifdef RTM_IFANNOUNCE
/* Interface adding function */
static int
@@ -319,6 +338,7 @@ int
ifm_read (struct if_msghdr *ifm)
{
struct interface *ifp = NULL;
+ struct sockaddr_dl *sdl;
char ifname[IFNAMSIZ];
short ifnlen = 0;
caddr_t *cp;
@@ -356,6 +376,7 @@ ifm_read (struct if_msghdr *ifm)
RTA_ADDR_GET (NULL, RTA_GATEWAY, ifm->ifm_addrs, cp);
RTA_ATTR_GET (NULL, RTA_NETMASK, ifm->ifm_addrs, cp);
RTA_ADDR_GET (NULL, RTA_GENMASK, ifm->ifm_addrs, cp);
+ sdl = (struct sockaddr_dl *)cp;
RTA_NAME_GET (ifname, RTA_IFP, ifm->ifm_addrs, cp, ifnlen);
RTA_ADDR_GET (NULL, RTA_IFA, ifm->ifm_addrs, cp);
RTA_ADDR_GET (NULL, RTA_AUTHOR, ifm->ifm_addrs, cp);
@@ -454,6 +475,16 @@ ifm_read (struct if_msghdr *ifm)
#endif /* __bsdi__ */
if_get_metric (ifp);
+ /*
+ * XXX sockaddr_dl contents can be larger than the structure
+ * definition, so the user of the stored structure must be
+ * careful not to read off the end.
+ *
+ * a nonzero ifnlen from RTA_NAME_GET() means sdl is valid
+ */
+ if (ifnlen)
+ memcpy (&ifp->sdl, sdl, sizeof (struct sockaddr_dl));
+
if_add_update (ifp);
}
else
@@ -619,6 +650,7 @@ ifam_read (struct ifa_msghdr *ifam)
short ifnlen = 0;
char isalias = 0;
int flags = 0;
+ int preference = 0;
ifname[0] = ifname[INTERFACE_NAMSIZ - 1] = '\0';
@@ -649,6 +681,9 @@ ifam_read (struct ifa_msghdr *ifam)
*/
ifp->metric = ifam->ifam_metric;
#endif
+ if (sockunion_family (&addr) == AF_INET
+ && ifam->ifam_type == RTM_NEWADDR)
+ preference = if_get_addrpref (ifp->name, &addr.sin);
/* Add connected address. */
switch (sockunion_family (&addr))
@@ -658,7 +693,7 @@ ifam_read (struct ifa_msghdr *ifam)
connected_add_ipv4 (ifp, flags, &addr.sin.sin_addr,
ip_masklen (mask.sin.sin_addr),
&brd.sin.sin_addr,
- (isalias ? ifname : NULL));
+ (isalias ? ifname : NULL), 0, preference);
else
connected_delete_ipv4 (ifp, flags, &addr.sin.sin_addr,
ip_masklen (mask.sin.sin_addr),
@@ -675,7 +710,7 @@ ifam_read (struct ifa_msghdr *ifam)
connected_add_ipv6 (ifp, flags, &addr.sin6.sin6_addr,
ip6_masklen (mask.sin6.sin6_addr),
&brd.sin6.sin6_addr,
- (isalias ? ifname : NULL));
+ (isalias ? ifname : NULL), 0);
else
connected_delete_ipv6 (ifp,
&addr.sin6.sin6_addr,
@@ -804,9 +839,9 @@ rtm_read (struct rt_msghdr *rtm)
/* This is a reject or blackhole route */
if (flags & RTF_REJECT)
- SET_FLAG (zebra_flags, ZEBRA_FLAG_REJECT);
+ SET_FLAG (zebra_flags, RIB_ZF_REJECT << 8);
if (flags & RTF_BLACKHOLE)
- SET_FLAG (zebra_flags, ZEBRA_FLAG_BLACKHOLE);
+ SET_FLAG (zebra_flags, RIB_ZF_BLACKHOLE << 8);
if (dest.sa.sa_family == AF_INET)
{
@@ -1037,11 +1072,12 @@ rtm_write (int message,
msg.rtm.rtm_flags |= (RTF_PROTO1);
/* Additional flags. */
- if (zebra_flags & ZEBRA_FLAG_BLACKHOLE)
- msg.rtm.rtm_flags |= RTF_BLACKHOLE;
- if (zebra_flags & ZEBRA_FLAG_REJECT)
- msg.rtm.rtm_flags |= RTF_REJECT;
-
+ if (RIB_ZF_BLACKHOLE_FLAGS (zebra_flags >> 8))
+ {
+ unsigned bh_type = RIB_ZF_BLACKHOLE_FLAGS(zebra_flags >> 8);
+ msg.rtm.rtm_flags |= (bh_type == RIB_ZF_REJECT)
+ ? RTF_REJECT : RTF_BLACKHOLE;
+ }
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
#define SOCKADDRSET(X,R) \
diff --git a/zebra/main.c b/zebra/main.c
index d829c046..b58fed12 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -32,6 +32,7 @@
#include "plist.h"
#include "privs.h"
#include "sigevent.h"
+#include "paths.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -68,6 +69,7 @@ struct option longopts[] =
{
{ "batch", no_argument, NULL, 'b'},
{ "daemon", no_argument, NULL, 'd'},
+ { "namespace", required_argument, NULL, 'N'},
{ "keep_kernel", no_argument, NULL, 'k'},
{ "config_file", required_argument, NULL, 'f'},
{ "pid_file", required_argument, NULL, 'i'},
@@ -108,10 +110,13 @@ struct zebra_privs_t zserv_privs =
};
/* Default configuration file path. */
-char config_default[] = SYSCONFDIR DEFAULT_CONFIG_FILE;
+char config_default[MAXPATHLEN];
+
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
/* Process ID saved for use by init system */
-const char *pid_file = PATH_ZEBRA_PID;
+const char *pid_file = pid_file_default;
/* Help information display. */
static void
@@ -126,6 +131,7 @@ usage (char *progname, int status)
"redistribution between different routing protocols.\n\n"\
"-b, --batch Runs in batch mode\n"\
"-d, --daemon Runs in daemon mode\n"\
+ "-N, --namespace Insert argument into all paths\n"\
"-f, --config_file Set configuration file name\n"\
"-i, --pid_file Set process identifier file name\n"\
"-k, --keep_kernel Don't delete old routes which installed by "\
@@ -229,9 +235,9 @@ main (int argc, char **argv)
int opt;
#ifdef HAVE_NETLINK
- opt = getopt_long (argc, argv, "bdkf:i:hA:P:ru:g:vs:C", longopts, 0);
+ opt = getopt_long (argc, argv, "bdN:kf:i:hA:P:ru:g:vs:C", longopts, 0);
#else
- opt = getopt_long (argc, argv, "bdkf:i:hA:P:ru:g:vC", longopts, 0);
+ opt = getopt_long (argc, argv, "bdN:kf:i:hA:P:ru:g:vC", longopts, 0);
#endif /* HAVE_NETLINK */
if (opt == EOF)
@@ -246,6 +252,9 @@ main (int argc, char **argv)
case 'd':
daemon_mode = 1;
break;
+ case 'N':
+ path_set_namespace (optarg);
+ break;
case 'k':
keep_kernel_mode = 1;
break;
@@ -300,6 +309,9 @@ main (int argc, char **argv)
}
}
+ strcpy (config_default, path_config (ZEBRA_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (ZEBRA_PID_NAME));
+
/* Make master thread emulator. */
zebrad.master = thread_master_create ();
@@ -389,7 +401,7 @@ main (int argc, char **argv)
zebra_zserv_socket_init ();
/* Make vty server socket. */
- vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH);
+ vty_serv_sock (vty_addr, vty_port, path_state (ZEBRA_VTY_NAME));
/* Print banner. */
zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION, vty_port);
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index a8107aeb..4276f1d0 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -245,26 +245,15 @@ zebra_redistribute_add (int command, struct zserv *client, int length)
type = stream_getc (client->ibuf);
- switch (type)
+ if (type == 0 || type >= ZEBRA_ROUTE_MAX)
+ return;
+
+ if (! client->redist[type])
{
- case ZEBRA_ROUTE_KERNEL:
- case ZEBRA_ROUTE_CONNECT:
- case ZEBRA_ROUTE_STATIC:
- case ZEBRA_ROUTE_RIP:
- case ZEBRA_ROUTE_RIPNG:
- case ZEBRA_ROUTE_OSPF:
- case ZEBRA_ROUTE_OSPF6:
- case ZEBRA_ROUTE_BGP:
- if (! client->redist[type])
- {
- client->redist[type] = 1;
- zebra_redistribute (client, type);
- }
- break;
- default:
- break;
+ client->redist[type] = 1;
+ zebra_redistribute (client, type);
}
-}
+}
void
zebra_redistribute_delete (int command, struct zserv *client, int length)
@@ -273,22 +262,11 @@ zebra_redistribute_delete (int command, struct zserv *client, int length)
type = stream_getc (client->ibuf);
- switch (type)
- {
- case ZEBRA_ROUTE_KERNEL:
- case ZEBRA_ROUTE_CONNECT:
- case ZEBRA_ROUTE_STATIC:
- case ZEBRA_ROUTE_RIP:
- case ZEBRA_ROUTE_RIPNG:
- case ZEBRA_ROUTE_OSPF:
- case ZEBRA_ROUTE_OSPF6:
- case ZEBRA_ROUTE_BGP:
- client->redist[type] = 0;
- break;
- default:
- break;
- }
-}
+ if (type == 0 || type >= ZEBRA_ROUTE_MAX)
+ return;
+
+ client->redist[type] = 0;
+}
void
zebra_redistribute_default_add (int command, struct zserv *client, int length)
diff --git a/zebra/rib.h b/zebra/rib.h
index 887ed3c2..2abfed19 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -73,6 +73,15 @@ struct rib
*/
u_char flags;
+ /* flags internal to zebra, not sent to clients */
+ unsigned zflags;
+ /* blackhole route zflags, for static routes: */
+#define RIB_ZF_REJECT 1
+#define RIB_ZF_PROHIBIT 2
+#define RIB_ZF_BLACKHOLE 3
+
+#define RIB_ZF_BLACKHOLE_FLAGS(zflags) ((zflags) & RIB_ZF_BLACKHOLE)
+
/* RIB internal status */
u_char status;
#define RIB_ENTRY_REMOVED (1 << 0)
@@ -120,12 +129,8 @@ struct static_ipv4
char *ifname;
} gate;
- /* bit flags */
- u_char flags;
-/*
- see ZEBRA_FLAG_REJECT
- ZEBRA_FLAG_BLACKHOLE
- */
+ /* zflags for rib */
+ unsigned zflags;
};
#ifdef HAVE_IPV6
@@ -144,17 +149,14 @@ struct static_ipv6
#define STATIC_IPV6_GATEWAY 1
#define STATIC_IPV6_GATEWAY_IFNAME 2
#define STATIC_IPV6_IFNAME 3
+#define STATIC_IPV6_BLACKHOLE 4
/* Nexthop value. */
struct in6_addr ipv6;
char *ifname;
- /* bit flags */
- u_char flags;
-/*
- see ZEBRA_FLAG_REJECT
- ZEBRA_FLAG_BLACKHOLE
- */
+ /* zflags for rib */
+ unsigned zflags;
};
#endif /* HAVE_IPV6 */
@@ -262,6 +264,7 @@ extern struct rib *rib_match_ipv4 (struct in_addr);
extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *);
extern void rib_update (void);
+extern void rib_update_background (void);
extern void rib_weed_tables (void);
extern void rib_sweep_route (void);
extern void rib_close (void);
@@ -269,7 +272,7 @@ extern void rib_init (void);
extern int
static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
- u_char flags, u_char distance, u_int32_t vrf_id);
+ unsigned zflags, u_char distance, u_int32_t vrf_id);
extern int
static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
@@ -293,7 +296,7 @@ extern struct route_table *rib_table_ipv6;
extern int
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
- const char *ifname, u_char flags, u_char distance,
+ const char *ifname, unsigned zflags, u_char distance,
u_int32_t vrf_id);
extern int
diff --git a/zebra/rt_ioctl.c b/zebra/rt_ioctl.c
index a5d588c7..390e6a1d 100644
--- a/zebra/rt_ioctl.c
+++ b/zebra/rt_ioctl.c
@@ -183,7 +183,7 @@ kernel_ioctl_ipv4 (u_long cmd, struct prefix *p, struct rib *rib, int family)
#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
sin_dest.sin_addr = p->u.prefix4;
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
+ if (RIB_ZF_BLACKHOLE_FLAGS (rib->zflags))
{
SET_FLAG (rtentry.rt_flags, RTF_REJECT);
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index 7652f80a..23acd5f3 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -85,6 +85,28 @@ extern struct zebra_privs_t zserv_privs;
extern u_int32_t nl_rcvbufsize;
+/* dispatch rtm_type field, return 1 if we want to process this */
+static int
+get_discard_or_unicast (unsigned char rtm_type, unsigned *zflags)
+{
+ switch (rtm_type)
+ {
+ case RTN_UNICAST:
+ *zflags = 0;
+ return 1;
+ case RTN_UNREACHABLE:
+ *zflags = RIB_ZF_REJECT;
+ return 1;
+ case RTN_PROHIBIT:
+ *zflags = RIB_ZF_PROHIBIT;
+ return 1;
+ case RTN_BLACKHOLE:
+ *zflags = RIB_ZF_BLACKHOLE;
+ return 1;
+ }
+ return 0;
+}
+
/* Note: on netlink systems, there should be a 1-to-1 mapping between interface
names and ifindex values. */
static void
@@ -549,6 +571,7 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
char buf[BUFSIZ];
zlog_debug ("netlink_interface_addr %s %s:",
lookup (nlmsg_str, h->nlmsg_type), ifp->name);
+ zlog_debug (" ifa_scope %s", connected_scope_name (ifa->ifa_scope));
if (tb[IFA_LOCAL])
zlog_debug (" IFA_LOCAL %s/%d",
inet_ntop (ifa->ifa_family, RTA_DATA (tb[IFA_LOCAL]),
@@ -616,7 +639,7 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
if (h->nlmsg_type == RTM_NEWADDR)
connected_add_ipv4 (ifp, flags,
(struct in_addr *) addr, ifa->ifa_prefixlen,
- (struct in_addr *) broad, label);
+ (struct in_addr *) broad, label, ifa->ifa_scope, 0);
else
connected_delete_ipv4 (ifp, flags,
(struct in_addr *) addr, ifa->ifa_prefixlen,
@@ -628,7 +651,7 @@ netlink_interface_addr (struct sockaddr_nl *snl, struct nlmsghdr *h)
if (h->nlmsg_type == RTM_NEWADDR)
connected_add_ipv6 (ifp, flags,
(struct in6_addr *) addr, ifa->ifa_prefixlen,
- (struct in6_addr *) broad, label);
+ (struct in6_addr *) broad, label, ifa->ifa_scope);
else
connected_delete_ipv6 (ifp,
(struct in6_addr *) addr, ifa->ifa_prefixlen,
@@ -647,6 +670,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
struct rtmsg *rtm;
struct rtattr *tb[RTA_MAX + 1];
u_char flags = 0;
+ unsigned discard = 0;
char anyaddr[16] = { 0 };
@@ -662,7 +686,8 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
if (h->nlmsg_type != RTM_NEWROUTE)
return 0;
- if (rtm->rtm_type != RTN_UNICAST)
+
+ if (!get_discard_or_unicast (rtm->rtm_type, &discard))
return 0;
table = rtm->rtm_table;
@@ -723,7 +748,8 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
memcpy (&p.prefix, dest, 4);
p.prefixlen = rtm->rtm_dst_len;
- rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, flags, &p, gate, src, index, table, metric, 0);
+ rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, flags | (discard << 8), &p,
+ gate, src, index, table, metric, 0);
}
#ifdef HAVE_IPV6
if (rtm->rtm_family == AF_INET6)
@@ -733,8 +759,8 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
memcpy (&p.prefix, dest, 16);
p.prefixlen = rtm->rtm_dst_len;
- rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, flags, &p, gate, index, table,
- metric, 0);
+ rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, flags | (discard << 8), &p,
+ gate, index, table, metric, 0);
}
#endif /* HAVE_IPV6 */
@@ -771,6 +797,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
void *dest;
void *gate;
void *src;
+ unsigned discard = 0;
rtm = NLMSG_DATA (h);
@@ -787,10 +814,10 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
h->nlmsg_type ==
RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
rtm->rtm_family == AF_INET ? "ipv4" : "ipv6",
- rtm->rtm_type == RTN_UNICAST ? "unicast" : "multicast",
+ rtm->rtm_type == RTN_UNICAST ? "unicast" : "!unicast",
lookup (rtproto_str, rtm->rtm_protocol));
- if (rtm->rtm_type != RTN_UNICAST)
+ if (!get_discard_or_unicast (rtm->rtm_type, &discard))
{
return 0;
}
@@ -861,9 +888,11 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
}
if (h->nlmsg_type == RTM_NEWROUTE)
- rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, src, index, table, 0, 0);
+ rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, discard << 8, &p,
+ gate, src, index, table, 0, 0);
else
- rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, table);
+ rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, discard << 8, &p,
+ gate, index, table);
}
#ifdef HAVE_IPV6
@@ -889,9 +918,11 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
}
if (h->nlmsg_type == RTM_NEWROUTE)
- rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, table, 0, 0);
+ rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, discard << 8, &p,
+ gate, index, table, 0, 0);
else
- rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, &p, gate, index, table);
+ rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, discard << 8, &p,
+ gate, index, table);
}
#endif /* HAVE_IPV6 */
@@ -1218,80 +1249,6 @@ netlink_talk (struct nlmsghdr *n, struct nlsock *nl)
/* Routing table change via netlink interface. */
static int
-netlink_route (int cmd, int family, void *dest, int length, void *gate,
- int index, int zebra_flags, int table)
-{
- int ret;
- int bytelen;
- struct sockaddr_nl snl;
- int discard;
-
- struct
- {
- struct nlmsghdr n;
- struct rtmsg r;
- char buf[1024];
- } req;
-
- memset (&req, 0, sizeof req);
-
- bytelen = (family == AF_INET ? 4 : 16);
-
- req.n.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtmsg));
- req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
- req.n.nlmsg_type = cmd;
- req.r.rtm_family = family;
- req.r.rtm_table = table;
- req.r.rtm_dst_len = length;
- req.r.rtm_protocol = RTPROT_ZEBRA;
- req.r.rtm_scope = RT_SCOPE_UNIVERSE;
-
- if ((zebra_flags & ZEBRA_FLAG_BLACKHOLE)
- || (zebra_flags & ZEBRA_FLAG_REJECT))
- discard = 1;
- else
- discard = 0;
-
- if (cmd == RTM_NEWROUTE)
- {
- if (discard)
- {
- if (zebra_flags & ZEBRA_FLAG_BLACKHOLE)
- req.r.rtm_type = RTN_BLACKHOLE;
- else if (zebra_flags & ZEBRA_FLAG_REJECT)
- req.r.rtm_type = RTN_UNREACHABLE;
- else
- assert (RTN_BLACKHOLE != RTN_UNREACHABLE); /* false */
- }
- else
- req.r.rtm_type = RTN_UNICAST;
- }
-
- if (dest)
- addattr_l (&req.n, sizeof req, RTA_DST, dest, bytelen);
-
- if (!discard)
- {
- if (gate)
- addattr_l (&req.n, sizeof req, RTA_GATEWAY, gate, bytelen);
- if (index > 0)
- addattr32 (&req.n, sizeof req, RTA_OIF, index);
- }
-
- /* Destination netlink address. */
- memset (&snl, 0, sizeof snl);
- snl.nl_family = AF_NETLINK;
-
- /* Talk to netlink socket. */
- ret = netlink_talk (&req.n, &netlink_cmd);
- if (ret < 0)
- return -1;
-
- return 0;
-}
-
-/* Routing table change via netlink interface. */
-static int
netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
int family)
{
@@ -1299,7 +1256,7 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
struct sockaddr_nl snl;
struct nexthop *nexthop = NULL;
int nexthop_num = 0;
- int discard;
+ unsigned discard;
struct
{
@@ -1321,24 +1278,29 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
req.r.rtm_protocol = RTPROT_ZEBRA;
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
- if ((rib->flags & ZEBRA_FLAG_BLACKHOLE) || (rib->flags & ZEBRA_FLAG_REJECT))
- discard = 1;
- else
- discard = 0;
+ discard = RIB_ZF_BLACKHOLE_FLAGS (rib->zflags);
if (cmd == RTM_NEWROUTE)
{
- if (discard)
- {
- if (rib->flags & ZEBRA_FLAG_BLACKHOLE)
- req.r.rtm_type = RTN_BLACKHOLE;
- else if (rib->flags & ZEBRA_FLAG_REJECT)
- req.r.rtm_type = RTN_UNREACHABLE;
- else
- assert (RTN_BLACKHOLE != RTN_UNREACHABLE); /* false */
- }
- else
- req.r.rtm_type = RTN_UNICAST;
+ switch (discard)
+ {
+ case RIB_ZF_REJECT:
+ req.r.rtm_type = RTN_UNREACHABLE;
+ break;
+ /* IPv6 only supports RTN_UNREACHABLE on Linux, it seems */
+ case RIB_ZF_PROHIBIT:
+ req.r.rtm_type = RTN_PROHIBIT;
+ if (family == AF_INET6)
+ req.r.rtm_type = RTN_UNREACHABLE;
+ break;
+ case RIB_ZF_BLACKHOLE:
+ req.r.rtm_type = RTN_BLACKHOLE;
+ if (family == AF_INET6)
+ req.r.rtm_type = RTN_UNREACHABLE;
+ break;
+ default:
+ req.r.rtm_type = RTN_UNICAST;
+ }
}
addattr_l (&req.n, sizeof req, RTA_DST, &p->u.prefix, bytelen);
@@ -1742,13 +1704,50 @@ kernel_delete_ipv6 (struct prefix *p, struct rib *rib)
return netlink_route_multipath (RTM_DELROUTE, p, rib, AF_INET6);
}
-/* Delete IPv6 route from the kernel. */
+/* Delete IPv6 route from the kernel.
+ * only called from rib_bogus_ipv6 */
int
kernel_delete_ipv6_old (struct prefix_ipv6 *dest, struct in6_addr *gate,
unsigned int index, int flags, int table)
{
- return netlink_route (RTM_DELROUTE, AF_INET6, &dest->prefix,
- dest->prefixlen, gate, index, flags, table);
+ int ret;
+ struct sockaddr_nl snl;
+
+ struct
+ {
+ struct nlmsghdr n;
+ struct rtmsg r;
+ char buf[1024];
+ } req;
+
+ memset (&req, 0, sizeof req);
+
+ req.n.nlmsg_len = NLMSG_LENGTH (sizeof (struct rtmsg));
+ req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
+ req.n.nlmsg_type = RTM_DELROUTE;
+ req.r.rtm_family = AF_INET6;
+ req.r.rtm_table = table;
+ req.r.rtm_dst_len = dest->prefixlen;
+ req.r.rtm_protocol = RTPROT_ZEBRA;
+ req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+
+ addattr_l (&req.n, sizeof req, RTA_DST, &dest->prefix, 16);
+
+ if (gate)
+ addattr_l (&req.n, sizeof req, RTA_GATEWAY, gate, 16);
+ if (index > 0)
+ addattr32 (&req.n, sizeof req, RTA_OIF, index);
+
+ /* Destination netlink address. */
+ memset (&snl, 0, sizeof snl);
+ snl.nl_family = AF_NETLINK;
+
+ /* Talk to netlink socket. */
+ ret = netlink_talk (&req.n, &netlink_cmd);
+ if (ret < 0)
+ return -1;
+
+ return 0;
}
#endif /* HAVE_IPV6 */
@@ -1778,20 +1777,30 @@ netlink_address (int cmd, int family, struct interface *ifp,
req.ifa.ifa_family = family;
req.ifa.ifa_index = ifp->ifindex;
- req.ifa.ifa_prefixlen = p->prefixlen;
+ req.ifa.ifa_scope = ifc->scope;
addattr_l (&req.n, sizeof req, IFA_LOCAL, &p->u.prefix, bytelen);
- if (family == AF_INET && cmd == RTM_NEWADDR)
+ if (family == AF_INET)
{
- if (!CONNECTED_PEER(ifc) && ifc->destination)
+ if (CONNECTED_PEER(ifc))
{
p = ifc->destination;
- addattr_l (&req.n, sizeof req, IFA_BROADCAST, &p->u.prefix,
+ addattr_l (&req.n, sizeof req, IFA_ADDRESS, &p->u.prefix,
bytelen);
}
+ else
+ if (cmd == RTM_NEWADDR && ifc->destination)
+ {
+ p = ifc->destination;
+ addattr_l (&req.n, sizeof req, IFA_BROADCAST, &p->u.prefix,
+ bytelen);
+ }
}
+ /* p is now either ifc->address or ifc->destination */
+ req.ifa.ifa_prefixlen = p->prefixlen;
+
if (CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
SET_FLAG (req.ifa.ifa_flags, IFA_F_SECONDARY);
diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c
index 1b8ded7e..4fadc7e9 100644
--- a/zebra/rt_socket.c
+++ b/zebra/rt_socket.c
@@ -163,7 +163,7 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib, int family)
(union sockunion *)mask,
gate ? (union sockunion *)&sin_gate : NULL,
ifindex,
- rib->flags,
+ rib->flags | (rib->zflags << 8),
rib->metric);
if (IS_ZEBRA_DEBUG_RIB)
@@ -286,7 +286,8 @@ sin6_masklen (struct in6_addr mask)
return len;
}
-/* Interface between zebra message and rtm message. */
+/* Interface between zebra message and rtm message.
+ * only called by kernel_delete_ipv6_old by rib_bogus_ipv6 */
static int
kernel_rtm_ipv6 (int message, struct prefix_ipv6 *dest,
struct in6_addr *gate, int index, int flags)
@@ -453,7 +454,7 @@ kernel_rtm_ipv6_multipath (int cmd, struct prefix *p, struct rib *rib,
(union sockunion *) mask,
gate ? (union sockunion *)&sin_gate : NULL,
ifindex,
- rib->flags,
+ rib->flags | (rib->zflags << 8),
rib->metric);
#if 0
diff --git a/zebra/rtadv.c b/zebra/rtadv.c
index 8cc3c4cb..e8c223f2 100644
--- a/zebra/rtadv.c
+++ b/zebra/rtadv.c
@@ -233,6 +233,32 @@ rtadv_send_packet (int sock, struct interface *ifp)
len += sizeof(struct nd_opt_homeagent_info);
}
+ if (zif->rtadv.AdvRDNSSFlag)
+ {
+ char *addr_ptr;
+ struct nd_opt_rdnss *ndopt_rdnss;
+ struct prefix *rdnss_prefix;
+ unsigned int rdnss_entries = 1;
+
+ ndopt_rdnss = (struct nd_opt_rdnss *) (buf + len);
+ ndopt_rdnss->nd_opt_rdnss_type = ND_OPT_RDNSS;
+ ndopt_rdnss->nd_opt_rdnss_reserved = 0;
+ ndopt_rdnss->nd_opt_rdnss_lifetime = htonl(zif->rtadv.AdvRDNSSLifetime);
+
+ len += sizeof(struct nd_opt_rdnss);
+
+ /* Fill in all RDNS server entries */
+ for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvRDNSSList, node, rdnss_prefix))
+ {
+ addr_ptr = (char *)(buf + len);
+ memcpy(addr_ptr, &rdnss_prefix->u.prefix6, sizeof (struct in6_addr));
+ len += sizeof (struct in6_addr);
+ rdnss_entries += 2;
+ }
+
+ ndopt_rdnss->nd_opt_rdnss_len = rdnss_entries;
+ }
+
if (zif->rtadv.AdvIntervalOption)
{
struct nd_opt_adv_interval *ndopt_adv =
@@ -1430,6 +1456,115 @@ DEFUN (no_ipv6_nd_router_preference,
return CMD_SUCCESS;
}
+static struct prefix *
+rtadv_rdnss_lookup (struct list *list, struct prefix *p)
+{
+ struct listnode *node;
+ struct prefix *prefix;
+
+ for (ALL_LIST_ELEMENTS_RO (list, node, prefix))
+ if (prefix_same (prefix, p))
+ return prefix;
+ return NULL;
+}
+
+static void
+rtadv_rdnss_set (struct zebra_if *zif, struct prefix *p)
+{
+ struct prefix *prefix;
+ struct list *rdnsslist = zif->rtadv.AdvRDNSSList;
+
+ prefix = rtadv_rdnss_lookup (rdnsslist, p);
+ if (prefix)
+ return;
+
+ prefix = prefix_new ();
+ memcpy (prefix, p, sizeof (struct prefix));
+ listnode_add (rdnsslist, prefix);
+
+ return;
+}
+
+static int
+rtadv_rdnss_reset (struct zebra_if *zif, struct prefix *rp)
+{
+ struct prefix *prefix;
+
+ prefix = rtadv_rdnss_lookup(zif->rtadv.AdvRDNSSList, rp);
+ if (prefix != NULL)
+ {
+ listnode_delete (zif->rtadv.AdvRDNSSList, (void *) prefix);
+ prefix_free (prefix);
+ return 1;
+ }
+ else
+ return 0;
+}
+
+DEFUN (ipv6_nd_rdnss,
+ ipv6_nd_rdnss_cmd,
+ "ipv6 nd rdnss X:X::X:X (<0-4294967295>|infinite)",
+ "Interface IPv6 config commands\n"
+ "Neighbor discovery\n"
+ "RDNSS Option\n"
+ "IPv6 address of recursive DNS server\n")
+{
+ int ret;
+ char *pnt;
+ struct interface *ifp;
+ struct zebra_if *zif;
+ struct prefix rp;
+
+ ifp = (struct interface *) vty->index;
+ zif = ifp->info;
+
+ /* make sure no slash exists in the argument */
+ pnt = strchr (argv[0], '/');
+ if (pnt != NULL)
+ {
+ vty_out (vty, "Malformed IPv6 RDNS address - no prefix notation allowed%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ /* now we can abuse str2prefix_ipv6 for a sanity check
+ * because IPv6 addresses with missing prefix
+ * slashes '/' are treated as host routes */
+ ret = str2prefix_ipv6 (argv[0], (struct prefix_ipv6 *) &rp);
+ if (!ret)
+ {
+ vty_out (vty, "Malformed IPv6 RDNS address%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ rtadv_rdnss_set(zif, &rp);
+ zif->rtadv.AdvRDNSSFlag = 1;
+
+ if (argc > 1)
+ {
+ if ( strncmp (argv[1], "i", 1) == 0)
+ {
+ zif->rtadv.AdvRDNSSLifetime = RTADV_RDNSS_INFINITY_LIFETIME;
+ }
+ else
+ {
+ zif->rtadv.AdvRDNSSLifetime =
+ (u_int32_t) strtoll (argv[1], (char **)NULL, 10);
+ }
+ }
+
+ return CMD_SUCCESS;
+}
+
+ALIAS (ipv6_nd_rdnss,
+ ipv6_nd_rdnss_nolife_cmd,
+ "ipv6 nd rdnss X:X::X:X",
+ "Interface IPv6 config commands\n"
+ "Neighbor discovery\n"
+ "RDNSS Option\n"
+ "IPv6 address of recursive DNS server\n")
+
+
/* Write configuration about router advertisement. */
void
rtadv_config_write (struct vty *vty, struct interface *ifp)
@@ -1605,6 +1740,8 @@ rtadv_init (void)
install_element (INTERFACE_NODE, &no_ipv6_nd_prefix_cmd);
install_element (INTERFACE_NODE, &ipv6_nd_router_preference_cmd);
install_element (INTERFACE_NODE, &no_ipv6_nd_router_preference_cmd);
+ install_element (INTERFACE_NODE, &ipv6_nd_rdnss_cmd);
+ install_element (INTERFACE_NODE, &ipv6_nd_rdnss_nolife_cmd);
}
static int
diff --git a/zebra/rtadv.h b/zebra/rtadv.h
index d8d263d0..6bd342e3 100644
--- a/zebra/rtadv.h
+++ b/zebra/rtadv.h
@@ -66,6 +66,9 @@ extern void rtadv_init (void);
#ifndef ND_OPT_HA_INFORMATION
#define ND_OPT_HA_INFORMATION 8 /* HA Information Option */
#endif
+#ifndef ND_OPT_RDNSS
+#define ND_OPT_RDNSS 25 /* RDNSS option (RFC 5006) */
+#endif
#ifndef HAVE_STRUCT_ND_OPT_ADV_INTERVAL
struct nd_opt_adv_interval { /* Advertisement interval option */
@@ -94,6 +97,17 @@ struct nd_opt_homeagent_info { /* Home Agent info */
} __attribute__((__packed__));
#endif
+#ifndef HAVE_STRUCT_ND_OPT_RDNSS
+/* see RFC 5006, section 5.1 */
+struct nd_opt_rdnss {
+ uint8_t nd_opt_rdnss_type;
+ uint8_t nd_opt_rdnss_len;
+ uint16_t nd_opt_rdnss_reserved;
+ uint32_t nd_opt_rdnss_lifetime;
+ /* followed by n (16 byte) entries */
+} __attribute__((__packed__));
+#endif
+
extern const char *rtadv_pref_strs[];
#endif /* _ZEBRA_RTADV_H */
diff --git a/zebra/test_main.c b/zebra/test_main.c
index 70a1a3a6..4e1002e8 100644
--- a/zebra/test_main.c
+++ b/zebra/test_main.c
@@ -29,6 +29,7 @@
#include "log.h"
#include "privs.h"
#include "sigevent.h"
+#include "paths.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
@@ -73,10 +74,13 @@ zebra_capabilities_t _caps_p [] =
};
/* Default configuration file path. */
-char config_default[] = SYSCONFDIR DEFAULT_CONFIG_FILE;
+char config_default[MAXPATHLEN];
+
+/* pid_file default value */
+static char pid_file_default[MAXPATHLEN];
/* Process ID saved for use by init system */
-const char *pid_file = PATH_ZEBRA_PID;
+const char *pid_file = pid_file_default;
/* Help information display. */
static void
@@ -276,6 +280,9 @@ main (int argc, char **argv)
usage (progname, 1);
}
+ strcpy (config_default, path_config (ZEBRA_CONFIG_NAME));
+ strcpy (pid_file_default, path_state (ZEBRA_PID_NAME));
+
/* Make master thread emulator. */
zebrad.master = thread_master_create ();
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 12f3fa5a..a10ca84b 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -67,6 +67,7 @@ static const struct
{ZEBRA_ROUTE_OSPF6, 110},
{ZEBRA_ROUTE_ISIS, 115},
{ZEBRA_ROUTE_BGP, 20 /* IBGP is 200. */}
+ /* no entry/default: 150 */
};
/* Vector for routing table. */
@@ -298,7 +299,6 @@ nexthop_blackhole_add (struct rib *rib)
nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
nexthop->type = NEXTHOP_TYPE_BLACKHOLE;
- SET_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE);
nexthop_add (rib, nexthop);
@@ -352,6 +352,17 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
break;
}
+ if (IS_ZEBRA_DEBUG_RIB) {
+ char buf[INET6_ADDRSTRLEN];
+ inet_ntop(rn->p.family, &rn->p.u.prefix, buf, INET6_ADDRSTRLEN);
+ zlog_debug("%s: %s/%d: nexthop match %p: %s type=%d sel=%d int=%d",
+ __func__, buf, rn->p.prefixlen, match,
+ match ? zebra_route_string(match->type) : "<?>",
+ match ? match->type : -1,
+ match ? CHECK_FLAG(match->flags, ZEBRA_FLAG_SELECTED) : -1,
+ match ? CHECK_FLAG(match->flags, ZEBRA_FLAG_INTERNAL) : -1);
+ }
+
/* If there is no selected route or matched route is EGP, go up
tree. */
if (! match
@@ -365,7 +376,8 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
}
else
{
- if (match->type == ZEBRA_ROUTE_CONNECT)
+ if (match->type == ZEBRA_ROUTE_CONNECT
+ || (match->nexthop && match->nexthop->type == NEXTHOP_TYPE_IFINDEX))
{
/* Directly point connected route. */
newhop = match->nexthop;
@@ -374,7 +386,8 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
return 1;
}
- else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL))
+ else if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_INTERNAL) ||
+ match->type == ZEBRA_ROUTE_KERNEL)
{
for (newhop = match->nexthop; newhop; newhop = newhop->next)
if (CHECK_FLAG (newhop->flags, NEXTHOP_FLAG_FIB)
@@ -755,6 +768,43 @@ rib_match_ipv6 (struct in6_addr *addr)
}
#endif /* HAVE_IPV6 */
+static void nexthop_dump(struct nexthop *nexthop,
+ char *type_str_buf,
+ int type_str_buf_size,
+ char *addr_str_buf,
+ int addr_str_buf_size,
+ char *via_str_buf,
+ int via_str_buf_size)
+{
+ switch (nexthop->type) {
+ case NEXTHOP_TYPE_IPV4:
+ case NEXTHOP_TYPE_IPV4_IFINDEX:
+ snprintf(type_str_buf, type_str_buf_size, "ipv4");
+ snprintf(addr_str_buf, addr_str_buf_size, "%s", inet_ntoa(nexthop->gate.ipv4));
+ snprintf(via_str_buf, via_str_buf_size, "%s", nexthop->ifindex ? ifindex2ifname(nexthop->ifindex) : "<?>");
+ break;
+ case NEXTHOP_TYPE_IFINDEX:
+ snprintf(type_str_buf, type_str_buf_size, "connected");
+ snprintf(addr_str_buf, addr_str_buf_size, "<connected>");
+ snprintf(via_str_buf, via_str_buf_size, "%s", ifindex2ifname(nexthop->ifindex));
+ break;
+ case NEXTHOP_TYPE_IFNAME:
+ snprintf(type_str_buf, type_str_buf_size, "connected");
+ snprintf(addr_str_buf, addr_str_buf_size, "<connected>");
+ snprintf(via_str_buf, via_str_buf_size, "%s", nexthop->ifname);
+ break;
+ case NEXTHOP_TYPE_BLACKHOLE:
+ snprintf(type_str_buf, type_str_buf_size, "blackhole");
+ snprintf(addr_str_buf, addr_str_buf_size, "<blackhole>");
+ snprintf(via_str_buf, via_str_buf_size, "Null0");
+ break;
+ default:
+ snprintf(type_str_buf, type_str_buf_size, "unknown");
+ snprintf(addr_str_buf, addr_str_buf_size, "<unknown>");
+ snprintf(via_str_buf, via_str_buf_size, "<?>");
+ }
+}
+
#define RIB_SYSTEM_ROUTE(R) \
((R)->type == ZEBRA_ROUTE_KERNEL || (R)->type == ZEBRA_ROUTE_CONNECT)
@@ -808,10 +858,27 @@ nexthop_active_check (struct route_node *rn, struct rib *rib,
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
family = AFI_IP;
- if (nexthop_active_ipv4 (rib, nexthop, set, rn))
- SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
- else
- UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
+ {
+ int nh_active = nexthop_active_ipv4 (rib, nexthop, set, rn);
+ if (IS_ZEBRA_DEBUG_RIB) {
+ char type_str_buf[100];
+ char addr_str_buf[100];
+ char via_str_buf[100];
+ nexthop_dump(nexthop,
+ type_str_buf, sizeof(type_str_buf),
+ addr_str_buf, sizeof(addr_str_buf),
+ via_str_buf, sizeof(via_str_buf));
+ zlog_debug("%s: rib %p nexthop %p type=%d %s %s via %s ifindex=%d nexthop_active_ipv4=%d",
+ __func__, rib, nexthop,
+ nexthop->type, type_str_buf,
+ addr_str_buf, via_str_buf, nexthop->ifindex,
+ nh_active);
+ }
+ if (nh_active)
+ SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
+ else
+ UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
+ }
break;
#ifdef HAVE_IPV6
case NEXTHOP_TYPE_IPV6:
@@ -891,8 +958,23 @@ nexthop_active_update (struct route_node *rn, struct rib *rib, int set)
{
prev_active = CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
prev_index = nexthop->ifindex;
- if ((new_active = nexthop_active_check (rn, rib, nexthop, set)))
+ new_active = nexthop_active_check (rn, rib, nexthop, set);
+ if (new_active)
rib->nexthop_active_num++;
+ if (IS_ZEBRA_DEBUG_RIB) {
+ char type_str_buf[100];
+ char addr_str_buf[100];
+ char via_str_buf[100];
+ nexthop_dump(nexthop,
+ type_str_buf, sizeof(type_str_buf),
+ addr_str_buf, sizeof(addr_str_buf),
+ via_str_buf, sizeof(via_str_buf));
+ zlog_debug("%s: rib %p nexthop %p type=%d %s %s via %s ifindex=%d act=%d total_act=%d",
+ __func__, rib, nexthop,
+ nexthop->type, type_str_buf,
+ addr_str_buf, via_str_buf, nexthop->ifindex,
+ new_active, rib->nexthop_active_num);
+ }
if (prev_active != new_active ||
prev_index != nexthop->ifindex)
SET_FLAG (rib->flags, ZEBRA_FLAG_CHANGED);
@@ -992,6 +1074,15 @@ rib_process (struct route_node *rn)
* may be passed to rib_unlink() in the middle of iteration.
*/
next = rib->next;
+
+ if (IS_ZEBRA_DEBUG_RIB) {
+ zlog_debug("%s: %s/%d: scan rib %p: type=%d sel=%d rem=%d nh_act=%d dist=%d",
+ __func__, buf, rn->p.prefixlen, rib, rib->type,
+ CHECK_FLAG(rib->flags, ZEBRA_FLAG_SELECTED),
+ CHECK_FLAG(rib->status, RIB_ENTRY_REMOVED),
+ nexthop_active_update(rn, rib, 0),
+ rib->distance);
+ }
/* Currently installed rib. */
if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
@@ -1332,7 +1423,6 @@ rib_queue_init (struct zebra_t *zebra)
zebra->ribq->spec.errorfunc = NULL;
/* XXX: TODO: These should be runtime configurable via vty */
zebra->ribq->spec.max_retries = 3;
- zebra->ribq->spec.hold = rib_process_hold_time;
if (!(zebra->mq = meta_queue_new ()))
zlog_err ("%s: could not initialise meta queue!", __func__);
@@ -1511,7 +1601,10 @@ rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
/* Set default distance by route type. */
if (distance == 0)
{
- distance = route_info[type].distance;
+ if ((unsigned)type >= sizeof(route_info) / sizeof(route_info[0]))
+ distance = 150;
+ else
+ distance = route_info[type].distance;
/* iBGP distance is 200. */
if (type == ZEBRA_ROUTE_BGP && CHECK_FLAG (flags, ZEBRA_FLAG_IBGP))
@@ -1551,13 +1644,16 @@ rib_add_ipv4 (int type, int flags, struct prefix_ipv4 *p,
rib->type = type;
rib->distance = distance;
rib->flags = flags;
+ rib->zflags = flags >> 8;
rib->metric = metric;
rib->table = vrf_id;
rib->nexthop_num = 0;
rib->uptime = time (NULL);
/* Nexthop settings. */
- if (gate)
+ if (RIB_ZF_BLACKHOLE_FLAGS (rib->zflags))
+ nexthop_blackhole_add (rib);
+ else if (gate)
{
if (ifindex)
nexthop_ipv4_ifindex_add (rib, gate, src, ifindex);
@@ -1830,6 +1926,7 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
struct nexthop *nexthop;
char buf1[INET_ADDRSTRLEN];
char buf2[INET_ADDRSTRLEN];
+ unsigned discard = RIB_ZF_BLACKHOLE_FLAGS (flags >> 8);
/* Lookup table. */
table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
@@ -1839,12 +1936,19 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
/* Apply mask. */
apply_mask_ipv4 (p);
- if (IS_ZEBRA_DEBUG_KERNEL && gate)
- zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d",
- inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN),
- p->prefixlen,
- inet_ntoa (*gate),
- ifindex);
+ if (IS_ZEBRA_DEBUG_KERNEL)
+ if (gate)
+ zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d",
+ inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
+ p->prefixlen,
+ inet_ntoa (*gate),
+ ifindex);
+ else
+ zlog_debug ("rib_delete_ipv4(): route delete %s/%d ifname %s ifindex %d",
+ inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ),
+ p->prefixlen,
+ ifindex2ifname(ifindex),
+ ifindex);
/* Lookup route node. */
rn = route_node_lookup (table, (struct prefix *) p);
@@ -1878,11 +1982,37 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
if (rib->type != type)
continue;
- if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) &&
- nexthop->type == NEXTHOP_TYPE_IFINDEX && nexthop->ifindex == ifindex)
+
+ if (rib->zflags == discard)
{
- if (rib->refcnt)
+ same = rib;
+ break;
+ }
+ if (gate)
+ {
+ for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
+ if (IPV4_ADDR_SAME (&nexthop->gate.ipv4, gate) ||
+ IPV4_ADDR_SAME (&nexthop->rgate.ipv4, gate))
+ /* make sure ifindex matches if specified */
+ if (!ifindex || ifindex == nexthop->ifindex)
+ break;
+
+ if (nexthop)
{
+ same = rib;
+ break;
+ }
+ }
+ else
+ {
+ nexthop = rib->nexthop;
+ if (nexthop && nexthop->ifindex != ifindex)
+ continue;
+ if (nexthop &&
+ rib->type == ZEBRA_ROUTE_CONNECT &&
+ nexthop->type == NEXTHOP_TYPE_IFINDEX &&
+ rib->refcnt)
+ { /* Duplicated connected route. */
rib->refcnt--;
route_unlock_node (rn);
route_unlock_node (rn);
@@ -1891,15 +2021,6 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p,
same = rib;
break;
}
- /* Make sure that the route found has the same gateway. */
- else if (gate == NULL ||
- ((nexthop = rib->nexthop) &&
- (IPV4_ADDR_SAME (&nexthop->gate.ipv4, gate) ||
- IPV4_ADDR_SAME (&nexthop->rgate.ipv4, gate))))
- {
- same = rib;
- break;
- }
}
/* If same type of route can't be found and this message is from
@@ -2011,7 +2132,7 @@ static_install_ipv4 (struct prefix *p, struct static_ipv4 *si)
}
/* Save the flags of this static routes (reject, blackhole) */
- rib->flags = si->flags;
+ rib->zflags = si->zflags;
/* Link this rib to the tree. */
rib_addnode (rn, rib);
@@ -2099,7 +2220,7 @@ static_uninstall_ipv4 (struct prefix *p, struct static_ipv4 *si)
/* Add static route into static route configuration. */
int
static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
- u_char flags, u_char distance, u_int32_t vrf_id)
+ unsigned zflags, u_char distance, u_int32_t vrf_id)
{
u_char type = 0;
struct route_node *rn;
@@ -2118,12 +2239,14 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
rn = route_node_get (stable, p);
/* Make flags. */
- if (gate)
+ if (RIB_ZF_BLACKHOLE_FLAGS (zflags))
+ type = STATIC_IPV4_BLACKHOLE;
+ else if (gate)
type = STATIC_IPV4_GATEWAY;
else if (ifname)
type = STATIC_IPV4_IFNAME;
else
- type = STATIC_IPV4_BLACKHOLE;
+ return -1;
/* Do nothing if there is a same static route. */
for (si = rn->info; si; si = si->next)
@@ -2151,7 +2274,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
si->type = type;
si->distance = distance;
- si->flags = flags;
+ si->zflags = zflags;
if (gate)
si->gate.ipv4 = *gate;
@@ -2340,6 +2463,7 @@ rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
rib->type = type;
rib->distance = distance;
rib->flags = flags;
+ rib->zflags = flags >> 8;
rib->metric = metric;
rib->table = vrf_id;
rib->nexthop_num = 0;
@@ -2385,6 +2509,7 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
struct nexthop *nexthop;
char buf1[INET6_ADDRSTRLEN];
char buf2[INET6_ADDRSTRLEN];
+ unsigned discard = RIB_ZF_BLACKHOLE_FLAGS (flags >> 8);
/* Apply mask. */
apply_mask_ipv6 (p);
@@ -2426,11 +2551,37 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
if (rib->type != type)
continue;
- if (rib->type == ZEBRA_ROUTE_CONNECT && (nexthop = rib->nexthop) &&
- nexthop->type == NEXTHOP_TYPE_IFINDEX && nexthop->ifindex == ifindex)
+
+ if (rib->zflags == discard)
+ {
+ same = rib;
+ break;
+ }
+ if (gate)
{
- if (rib->refcnt)
+ for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
+ if (IPV6_ADDR_SAME (&nexthop->gate.ipv6, gate) ||
+ IPV6_ADDR_SAME (&nexthop->rgate.ipv6, gate))
+ /* make sure ifindex matches if specified */
+ if (!ifindex || ifindex == nexthop->ifindex)
+ break;
+
+ if (nexthop)
{
+ same = rib;
+ break;
+ }
+ }
+ else
+ {
+ nexthop = rib->nexthop;
+ if (nexthop && nexthop->ifindex != ifindex)
+ continue;
+ if (nexthop &&
+ rib->type == ZEBRA_ROUTE_CONNECT &&
+ nexthop->type == NEXTHOP_TYPE_IFINDEX &&
+ rib->refcnt)
+ { /* Duplicated connected route. */
rib->refcnt--;
route_unlock_node (rn);
route_unlock_node (rn);
@@ -2439,15 +2590,7 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
same = rib;
break;
}
- /* Make sure that the route found has the same gateway. */
- else if (gate == NULL ||
- ((nexthop = rib->nexthop) &&
- (IPV6_ADDR_SAME (&nexthop->gate.ipv6, gate) ||
- IPV6_ADDR_SAME (&nexthop->rgate.ipv6, gate))))
- {
- same = rib;
- break;
- }
+
}
/* If same type of route can't be found and this message is from
@@ -2533,6 +2676,9 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si)
case STATIC_IPV6_GATEWAY_IFNAME:
nexthop_ipv6_ifname_add (rib, &si->ipv6, si->ifname);
break;
+ case STATIC_IPV6_BLACKHOLE:
+ nexthop_blackhole_add (rib);
+ break;
}
rib_queue_add (&zebrad, rn);
}
@@ -2557,10 +2703,13 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si)
case STATIC_IPV6_GATEWAY_IFNAME:
nexthop_ipv6_ifname_add (rib, &si->ipv6, si->ifname);
break;
+ case STATIC_IPV6_BLACKHOLE:
+ nexthop_blackhole_add (rib);
+ break;
}
/* Save the flags of this static routes (reject, blackhole) */
- rib->flags = si->flags;
+ rib->zflags = si->zflags;
/* Link this rib to the tree. */
rib_addnode (rn, rib);
@@ -2583,6 +2732,9 @@ static_ipv6_nexthop_same (struct nexthop *nexthop, struct static_ipv6 *si)
&& IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->ipv6)
&& strcmp (nexthop->ifname, si->ifname) == 0)
return 1;
+ if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE
+ && si->type == STATIC_IPV6_BLACKHOLE)
+ return 1;
return 0;
}
@@ -2651,7 +2803,7 @@ static_uninstall_ipv6 (struct prefix *p, struct static_ipv6 *si)
/* Add static route into static route configuration. */
int
static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
- const char *ifname, u_char flags, u_char distance,
+ const char *ifname, unsigned zflags, u_char distance,
u_int32_t vrf_id)
{
struct route_node *rn;
@@ -2694,7 +2846,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
si->type = type;
si->distance = distance;
- si->flags = flags;
+ si->zflags = zflags;
switch (type)
{
@@ -2708,6 +2860,8 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
si->ipv6 = *gate;
si->ifname = XSTRDUP (0, ifname);
break;
+ case STATIC_IPV6_BLACKHOLE:
+ break;
}
/* Add new static route information to the tree with sort by
@@ -2791,23 +2945,45 @@ static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
#endif /* HAVE_IPV6 */
/* RIB update function. */
-void
-rib_update (void)
+static void
+rib_update_table (struct table *table)
{
struct route_node *rn;
- struct route_table *table;
-
- table = vrf_table (AFI_IP, SAFI_UNICAST, 0);
if (table)
for (rn = route_top (table); rn; rn = route_next (rn))
if (rn->info)
rib_queue_add (&zebrad, rn);
+}
- table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);
- if (table)
- for (rn = route_top (table); rn; rn = route_next (rn))
- if (rn->info)
- rib_queue_add (&zebrad, rn);
+void
+rib_update (void)
+{
+ if (zebrad.update)
+ {
+ thread_cancel (zebrad.update);
+ zebrad.update = NULL;
+ }
+
+ rib_update_table (vrf_table (AFI_IP, SAFI_UNICAST, 0));
+
+#ifdef HAVE_IPV6
+ rib_update_table (vrf_table (AFI_IP6, SAFI_UNICAST, 0));
+#endif
+}
+
+static int
+rib_update_thread (struct thread *self)
+{
+ rib_update ();
+ return 0;
+}
+
+void
+rib_update_background (void)
+{
+ if (!zebrad.update)
+ zebrad.update = thread_add_background (zebrad.master, rib_update_thread,
+ NULL, rib_process_hold_time);
}
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index ecb5d10a..db56a335 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -30,6 +30,50 @@
#include "zebra/zserv.h"
+/* small helper for blackhole routes */
+static const struct message blackhole_str[] = {
+ {RIB_ZF_REJECT, "reject"},
+ {RIB_ZF_PROHIBIT, "prohibit"},
+ {RIB_ZF_BLACKHOLE, "blackhole"},
+ {0, NULL}
+};
+
+#define BLACKHOLE_NAME(type) \
+ lookup (blackhole_str, RIB_ZF_BLACKHOLE_FLAGS(type))
+
+#define BLACKHOLE_CMD "(reject|prohibit|blackhole)"
+#define BLACKHOLE_STR \
+ "Emit ICMP unreachable when matched\n" \
+ "Emit ICMP prohibited when matched\n" \
+ "Silently discard packets\n"
+
+static unsigned
+zebra_static_parse_flags (const char *gate_str, const char *flag_str)
+{
+ unsigned zflags = 0;
+
+ /* Null0 static route. */
+ if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
+ zflags = RIB_ZF_BLACKHOLE;
+
+ /* Route flags. override RIB_ZF_BLACKHOLE from above if given. */
+ if (flag_str) {
+ switch (tolower (flag_str[0])) {
+ case 'r':
+ zflags = RIB_ZF_REJECT;
+ break;
+ case 'p':
+ zflags = RIB_ZF_PROHIBIT;
+ break;
+ case 'b':
+ zflags = RIB_ZF_BLACKHOLE;
+ break;
+ /* syntax checking happens in vty code */
+ }
+ }
+ return zflags;
+}
+
/* General fucntion for static route. */
static int
zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
@@ -42,7 +86,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
struct in_addr gate;
struct in_addr mask;
const char *ifname;
- u_char flag = 0;
+ unsigned zflags;
ret = str2prefix (dest_str, &p);
if (ret <= 0)
@@ -72,42 +116,13 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
else
distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
- /* Null0 static route. */
- if ((gate_str != NULL) && (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0))
- {
- if (flag_str)
- {
- vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
- return CMD_WARNING;
- }
- if (add_cmd)
- static_add_ipv4 (&p, NULL, NULL, ZEBRA_FLAG_BLACKHOLE, distance, 0);
- else
- static_delete_ipv4 (&p, NULL, NULL, distance, 0);
- return CMD_SUCCESS;
- }
-
- /* Route flags */
- if (flag_str) {
- switch(flag_str[0]) {
- case 'r':
- case 'R': /* XXX */
- SET_FLAG (flag, ZEBRA_FLAG_REJECT);
- break;
- case 'b':
- case 'B': /* XXX */
- SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
- break;
- default:
- vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
- return CMD_WARNING;
- }
- }
+ zflags = zebra_static_parse_flags (gate_str, flag_str);
- if (gate_str == NULL)
+ /* blackhole with nexthop makes no sense, don't add nexthop */
+ if (gate_str == NULL || RIB_ZF_BLACKHOLE_FLAGS (zflags))
{
if (add_cmd)
- static_add_ipv4 (&p, NULL, NULL, flag, distance, 0);
+ static_add_ipv4 (&p, NULL, NULL, zflags, distance, 0);
else
static_delete_ipv4 (&p, NULL, NULL, distance, 0);
@@ -123,7 +138,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str,
ifname = gate_str;
if (add_cmd)
- static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, flag, distance, 0);
+ static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, 0, distance, 0);
else
static_delete_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0);
@@ -146,26 +161,25 @@ DEFUN (ip_route,
DEFUN (ip_route_flags,
ip_route_flags_cmd,
- "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
+ "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD,
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ "Null interface\n"
+ BLACKHOLE_STR)
{
return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], NULL);
}
DEFUN (ip_route_flags2,
ip_route_flags2_cmd,
- "ip route A.B.C.D/M (reject|blackhole)",
+ "ip route A.B.C.D/M " BLACKHOLE_CMD,
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ BLACKHOLE_STR)
{
return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], NULL);
}
@@ -187,28 +201,27 @@ DEFUN (ip_route_mask,
DEFUN (ip_route_mask_flags,
ip_route_mask_flags_cmd,
- "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
+ "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD,
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ "Null interface\n"
+ BLACKHOLE_STR)
{
return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
}
DEFUN (ip_route_mask_flags2,
ip_route_mask_flags2_cmd,
- "ip route A.B.C.D A.B.C.D (reject|blackhole)",
+ "ip route A.B.C.D A.B.C.D " BLACKHOLE_CMD,
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ BLACKHOLE_STR)
{
return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
}
@@ -230,14 +243,14 @@ DEFUN (ip_route_distance,
DEFUN (ip_route_flags_distance,
ip_route_flags_distance_cmd,
- "ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
+ "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD " <1-255>",
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ "Null interface\n"
+ BLACKHOLE_STR
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], argv[2], argv[3]);
@@ -245,12 +258,11 @@ DEFUN (ip_route_flags_distance,
DEFUN (ip_route_flags_distance2,
ip_route_flags_distance2_cmd,
- "ip route A.B.C.D/M (reject|blackhole) <1-255>",
+ "ip route A.B.C.D/M " BLACKHOLE_CMD " <1-255>",
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ BLACKHOLE_STR
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], NULL, NULL, argv[1], argv[2]);
@@ -273,30 +285,29 @@ DEFUN (ip_route_mask_distance,
DEFUN (ip_route_mask_flags_distance,
ip_route_mask_flags_distance_cmd,
- "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
+ "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD " <1-255>",
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Distance value for this route\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ "Null interface\n"
+ BLACKHOLE_STR
+ "Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
}
DEFUN (ip_route_mask_flags_distance2,
ip_route_mask_flags_distance2_cmd,
- "ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
+ "ip route A.B.C.D A.B.C.D " BLACKHOLE_CMD " <1-255>",
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
- "Distance value for this route\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ BLACKHOLE_STR
+ "Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
}
@@ -317,25 +328,24 @@ DEFUN (no_ip_route,
ALIAS (no_ip_route,
no_ip_route_flags_cmd,
- "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole)",
+ "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD,
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ "Null interface\n"
+ BLACKHOLE_STR)
DEFUN (no_ip_route_flags2,
no_ip_route_flags2_cmd,
- "no ip route A.B.C.D/M (reject|blackhole)",
+ "no ip route A.B.C.D/M " BLACKHOLE_CMD,
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ BLACKHOLE_STR)
{
return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, NULL, NULL);
}
@@ -357,7 +367,7 @@ DEFUN (no_ip_route_mask,
ALIAS (no_ip_route_mask,
no_ip_route_mask_flags_cmd,
- "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole)",
+ "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD,
NO_STR
IP_STR
"Establish static routes\n"
@@ -365,19 +375,18 @@ ALIAS (no_ip_route_mask,
"IP destination prefix mask\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ "Null interface\n"
+ BLACKHOLE_STR)
DEFUN (no_ip_route_mask_flags2,
no_ip_route_mask_flags2_cmd,
- "no ip route A.B.C.D A.B.C.D (reject|blackhole)",
+ "no ip route A.B.C.D A.B.C.D " BLACKHOLE_CMD,
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
+ BLACKHOLE_STR)
{
return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
}
@@ -399,15 +408,15 @@ DEFUN (no_ip_route_distance,
DEFUN (no_ip_route_flags_distance,
no_ip_route_flags_distance_cmd,
- "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
+ "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD " <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ "Null interface\n"
+ BLACKHOLE_STR
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], argv[2], argv[3]);
@@ -415,13 +424,12 @@ DEFUN (no_ip_route_flags_distance,
DEFUN (no_ip_route_flags_distance2,
no_ip_route_flags_distance2_cmd,
- "no ip route A.B.C.D/M (reject|blackhole) <1-255>",
+ "no ip route A.B.C.D/M " BLACKHOLE_CMD " <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ BLACKHOLE_STR
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], NULL, NULL, argv[1], argv[2]);
@@ -445,7 +453,7 @@ DEFUN (no_ip_route_mask_distance,
DEFUN (no_ip_route_mask_flags_distance,
no_ip_route_mask_flags_distance_cmd,
- "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) (reject|blackhole) <1-255>",
+ "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) " BLACKHOLE_CMD " <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
@@ -453,8 +461,8 @@ DEFUN (no_ip_route_mask_flags_distance,
"IP destination prefix mask\n"
"IP gateway address\n"
"IP gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ "Null interface\n"
+ BLACKHOLE_STR
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
@@ -462,14 +470,13 @@ DEFUN (no_ip_route_mask_flags_distance,
DEFUN (no_ip_route_mask_flags_distance2,
no_ip_route_mask_flags_distance2_cmd,
- "no ip route A.B.C.D A.B.C.D (reject|blackhole) <1-255>",
+ "no ip route A.B.C.D A.B.C.D " BLACKHOLE_CMD " <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ BLACKHOLE_STR
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
@@ -546,10 +553,6 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
vty_out (vty, ", best");
if (rib->refcnt)
vty_out (vty, ", refcnt %ld", rib->refcnt);
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
- vty_out (vty, ", blackhole");
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
- vty_out (vty, ", reject");
vty_out (vty, "%s", VTY_NEWLINE);
#define ONE_DAY_SECOND 60*60*24
@@ -603,10 +606,10 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn)
case NEXTHOP_TYPE_IFNAME:
vty_out (vty, " directly connected, %s", nexthop->ifname);
break;
- case NEXTHOP_TYPE_BLACKHOLE:
- vty_out (vty, " directly connected, Null0");
- break;
- default:
+ case NEXTHOP_TYPE_BLACKHOLE:
+ vty_out (vty, " Null0, %s", BLACKHOLE_NAME (rib->zflags));
+ break;
+ default:
break;
}
if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
@@ -713,10 +716,10 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
case NEXTHOP_TYPE_IFNAME:
vty_out (vty, " is directly connected, %s", nexthop->ifname);
break;
- case NEXTHOP_TYPE_BLACKHOLE:
- vty_out (vty, " is directly connected, Null0");
- break;
- default:
+ case NEXTHOP_TYPE_BLACKHOLE:
+ vty_out (vty, " Null0, %s", BLACKHOLE_NAME (rib->zflags));
+ break;
+ default:
break;
}
if (! CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
@@ -767,11 +770,6 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
break;
}
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
- vty_out (vty, ", bh");
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
- vty_out (vty, ", rej");
-
if (rib->type == ZEBRA_ROUTE_RIP
|| rib->type == ZEBRA_ROUTE_OSPF
|| rib->type == ZEBRA_ROUTE_ISIS
@@ -802,10 +800,6 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib)
}
}
-#define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \
- "S - static, R - RIP, O - OSPF,%s I - ISIS, B - BGP, " \
- "> - selected route, * - FIB route%s%s"
-
DEFUN (show_ip_route,
show_ip_route_cmd,
"show ip route",
@@ -828,8 +822,7 @@ DEFUN (show_ip_route,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE, VTY_NEWLINE,
- VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V4_HEADER);
first = 0;
}
vty_show_ip_route (vty, rn, rib);
@@ -871,8 +864,7 @@ DEFUN (show_ip_route_prefix_longer,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE,
- VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V4_HEADER);
first = 0;
}
vty_show_ip_route (vty, rn, rib);
@@ -910,8 +902,7 @@ DEFUN (show_ip_route_supernets,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V4_HEADER, VTY_NEWLINE,
- VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V4_HEADER);
first = 0;
}
vty_show_ip_route (vty, rn, rib);
@@ -922,17 +913,11 @@ DEFUN (show_ip_route_supernets,
DEFUN (show_ip_route_protocol,
show_ip_route_protocol_cmd,
- "show ip route (bgp|connected|isis|kernel|ospf|rip|static)",
+ "show ip route " QUAGGA_IP_REDIST_STR_ZEBRA,
SHOW_STR
IP_STR
"IP routing table\n"
- "Border Gateway Protocol (BGP)\n"
- "Connected\n"
- "ISO IS-IS (ISIS)\n"
- "Kernel\n"
- "Open Shortest Path First (OSPF)\n"
- "Routing Information Protocol (RIP)\n"
- "Static routes\n")
+ QUAGGA_IP_REDIST_HELP_STR_ZEBRA)
{
int type;
struct route_table *table;
@@ -940,21 +925,8 @@ DEFUN (show_ip_route_protocol,
struct rib *rib;
int first = 1;
- if (strncmp (argv[0], "b", 1) == 0)
- type = ZEBRA_ROUTE_BGP;
- else if (strncmp (argv[0], "c", 1) == 0)
- type = ZEBRA_ROUTE_CONNECT;
- else if (strncmp (argv[0], "k", 1) ==0)
- type = ZEBRA_ROUTE_KERNEL;
- else if (strncmp (argv[0], "o", 1) == 0)
- type = ZEBRA_ROUTE_OSPF;
- else if (strncmp (argv[0], "i", 1) == 0)
- type = ZEBRA_ROUTE_ISIS;
- else if (strncmp (argv[0], "r", 1) == 0)
- type = ZEBRA_ROUTE_RIP;
- else if (strncmp (argv[0], "s", 1) == 0)
- type = ZEBRA_ROUTE_STATIC;
- else
+ type = proto_redistnum (AFI_IP, argv[0]);
+ if (type < 0)
{
vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -971,8 +943,7 @@ DEFUN (show_ip_route_protocol,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V4_HEADER,
- VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V4_HEADER);
first = 0;
}
vty_show_ip_route (vty, rn, rib);
@@ -1168,19 +1139,9 @@ static_config_ipv4 (struct vty *vty)
case STATIC_IPV4_IFNAME:
vty_out (vty, " %s", si->gate.ifname);
break;
- case STATIC_IPV4_BLACKHOLE:
- vty_out (vty, " Null0");
- break;
- }
-
- /* flags are incompatible with STATIC_IPV4_BLACKHOLE */
- if (si->type != STATIC_IPV4_BLACKHOLE)
- {
- if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
- vty_out (vty, " %s", "reject");
-
- if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
- vty_out (vty, " %s", "blackhole");
+ case STATIC_IPV4_BLACKHOLE:
+ vty_out (vty, " Null0 %s", BLACKHOLE_NAME (si->zflags));
+ break;
}
if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
@@ -1237,7 +1198,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
struct in6_addr gate_addr;
u_char type = 0;
int table = 0;
- u_char flag = 0;
+ unsigned zflags;
ret = str2prefix (dest_str, &p);
if (ret <= 0)
@@ -1249,22 +1210,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
/* Apply mask for given prefix. */
apply_mask (&p);
- /* Route flags */
- if (flag_str) {
- switch(flag_str[0]) {
- case 'r':
- case 'R': /* XXX */
- SET_FLAG (flag, ZEBRA_FLAG_REJECT);
- break;
- case 'b':
- case 'B': /* XXX */
- SET_FLAG (flag, ZEBRA_FLAG_BLACKHOLE);
- break;
- default:
- vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
- return CMD_WARNING;
- }
- }
+ zflags = zebra_static_parse_flags (gate_str, flag_str);
/* Administrative distance. */
if (distance_str)
@@ -1272,6 +1218,17 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
else
distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
+ /* blackhole routes don't have nexthops */
+ if (RIB_ZF_BLACKHOLE_FLAGS (zflags))
+ {
+ type = STATIC_IPV6_BLACKHOLE;
+ if (add_cmd)
+ static_add_ipv6 (&p, type, NULL, NULL, zflags, distance, table);
+ else
+ static_delete_ipv6 (&p, type, NULL, NULL, distance, table);
+ return CMD_SUCCESS;
+ }
+
/* When gateway is valid IPv6 addrees, then gate is treated as
nexthop address other case gate is treated as interface name. */
ret = inet_pton (AF_INET6, gate_str, &gate_addr);
@@ -1303,7 +1260,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
}
if (add_cmd)
- static_add_ipv6 (&p, type, gate, ifname, flag, distance, table);
+ static_add_ipv6 (&p, type, gate, ifname, zflags, distance, table);
else
static_delete_ipv6 (&p, type, gate, ifname, distance, table);
@@ -1322,20 +1279,6 @@ DEFUN (ipv6_route,
return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, NULL);
}
-DEFUN (ipv6_route_flags,
- ipv6_route_flags_cmd,
- "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
- IP_STR
- "Establish static routes\n"
- "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
-{
- return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
-}
-
DEFUN (ipv6_route_ifname,
ipv6_route_ifname_cmd,
"ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
@@ -1348,20 +1291,6 @@ DEFUN (ipv6_route_ifname,
return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
}
-DEFUN (ipv6_route_ifname_flags,
- ipv6_route_ifname_flags_cmd,
- "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
- IP_STR
- "Establish static routes\n"
- "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
-{
- return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], NULL);
-}
-
DEFUN (ipv6_route_pref,
ipv6_route_pref_cmd,
"ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
@@ -1375,21 +1304,6 @@ DEFUN (ipv6_route_pref,
return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, NULL, argv[2]);
}
-DEFUN (ipv6_route_flags_pref,
- ipv6_route_flags_pref_cmd,
- "ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
- IP_STR
- "Establish static routes\n"
- "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
- "Distance value for this prefix\n")
-{
- return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
-}
-
DEFUN (ipv6_route_ifname_pref,
ipv6_route_ifname_pref_cmd,
"ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
@@ -1403,21 +1317,6 @@ DEFUN (ipv6_route_ifname_pref,
return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
}
-DEFUN (ipv6_route_ifname_flags_pref,
- ipv6_route_ifname_flags_pref_cmd,
- "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
- IP_STR
- "Establish static routes\n"
- "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
- "Distance value for this prefix\n")
-{
- return static_ipv6_func (vty, 1, argv[0], argv[1], argv[2], argv[3], argv[4]);
-}
-
DEFUN (no_ipv6_route,
no_ipv6_route_cmd,
"no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE)",
@@ -1431,18 +1330,6 @@ DEFUN (no_ipv6_route,
return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, NULL);
}
-ALIAS (no_ipv6_route,
- no_ipv6_route_flags_cmd,
- "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole)",
- NO_STR
- IP_STR
- "Establish static routes\n"
- "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
-
DEFUN (no_ipv6_route_ifname,
no_ipv6_route_ifname_cmd,
"no ipv6 route X:X::X:X/M X:X::X:X INTERFACE",
@@ -1456,18 +1343,6 @@ DEFUN (no_ipv6_route_ifname,
return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
}
-ALIAS (no_ipv6_route_ifname,
- no_ipv6_route_ifname_flags_cmd,
- "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole)",
- NO_STR
- IP_STR
- "Establish static routes\n"
- "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n")
-
DEFUN (no_ipv6_route_pref,
no_ipv6_route_pref_cmd,
"no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) <1-255>",
@@ -1482,53 +1357,70 @@ DEFUN (no_ipv6_route_pref,
return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, NULL, argv[2]);
}
-DEFUN (no_ipv6_route_flags_pref,
- no_ipv6_route_flags_pref_cmd,
- "no ipv6 route X:X::X:X/M (X:X::X:X|INTERFACE) (reject|blackhole) <1-255>",
+DEFUN (no_ipv6_route_ifname_pref,
+ no_ipv6_route_ifname_pref_cmd,
+ "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
"IPv6 gateway address\n"
"IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
"Distance value for this prefix\n")
{
- /* We do not care about argv[2] */
- return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], argv[3]);
+ return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
}
-DEFUN (no_ipv6_route_ifname_pref,
- no_ipv6_route_ifname_pref_cmd,
- "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE <1-255>",
- NO_STR
+DEFUN (ipv6_route_blackhole,
+ ipv6_route_blackhole_cmd,
+ "ipv6 route X:X::X:X/M Null0 " BLACKHOLE_CMD,
IP_STR
"Establish static routes\n"
"IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
+ "Specify blackhole route\n"
+ BLACKHOLE_STR)
+{
+ return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], NULL);
+}
+
+DEFUN (ipv6_route_blackhole_pref,
+ ipv6_route_blackhole_pref_cmd,
+ "ipv6 route X:X::X:X/M Null0 " BLACKHOLE_CMD " <1-255>",
+ IP_STR
+ "Establish static routes\n"
+ "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
+ "Specify blackhole route\n"
+ BLACKHOLE_STR
"Distance value for this prefix\n")
{
- return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
+ return static_ipv6_func (vty, 1, argv[0], argv[1], NULL, argv[2], argv[3]);
}
-DEFUN (no_ipv6_route_ifname_flags_pref,
- no_ipv6_route_ifname_flags_pref_cmd,
- "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (reject|blackhole) <1-255>",
+DEFUN (no_ipv6_route_blackhole_pref,
+ no_ipv6_route_blackhole_pref_cmd,
+ "no ipv6 route X:X::X:X/M Null0 " BLACKHOLE_CMD " <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
- "IPv6 gateway address\n"
- "IPv6 gateway interface name\n"
- "Emit an ICMP unreachable when matched\n"
- "Silently discard pkts when matched\n"
+ "Specify blackhole route\n"
+ BLACKHOLE_STR
"Distance value for this prefix\n")
{
- return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
+ const char *dist = argc > 3 ? argv[3] : NULL;
+ return static_ipv6_func (vty, 0, argv[0], argv[1], NULL, argv[2], dist);
}
+ALIAS (no_ipv6_route_blackhole_pref,
+ no_ipv6_route_blackhole_cmd,
+ "no ipv6 route X:X::X:X/M Null0 " BLACKHOLE_CMD,
+ NO_STR
+ IP_STR
+ "Establish static routes\n"
+ "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
+ "Specify blackhole route\n"
+ BLACKHOLE_STR)
+
/* New RIB. Detailed information for IPv6 route. */
static void
vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
@@ -1549,10 +1441,6 @@ vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
vty_out (vty, ", best");
if (rib->refcnt)
vty_out (vty, ", refcnt %ld", rib->refcnt);
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
- vty_out (vty, ", blackhole");
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
- vty_out (vty, ", reject");
vty_out (vty, "%s", VTY_NEWLINE);
#define ONE_DAY_SECOND 60*60*24
@@ -1700,6 +1588,9 @@ vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
vty_out (vty, " is directly connected, %s",
nexthop->ifname);
break;
+ case NEXTHOP_TYPE_BLACKHOLE:
+ vty_out (vty, " Null0, %s", BLACKHOLE_NAME (rib->zflags));
+ break;
default:
break;
}
@@ -1731,11 +1622,6 @@ vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
}
}
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE))
- vty_out (vty, ", bh");
- if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_REJECT))
- vty_out (vty, ", rej");
-
if (rib->type == ZEBRA_ROUTE_RIPNG
|| rib->type == ZEBRA_ROUTE_OSPF6
|| rib->type == ZEBRA_ROUTE_ISIS
@@ -1766,8 +1652,6 @@ vty_show_ipv6_route (struct vty *vty, struct route_node *rn,
}
}
-#define SHOW_ROUTE_V6_HEADER "Codes: K - kernel route, C - connected, S - static, R - RIPng, O - OSPFv3,%s I - ISIS, B - BGP, * - FIB route.%s%s"
-
DEFUN (show_ipv6_route,
show_ipv6_route_cmd,
"show ipv6 route",
@@ -1790,7 +1674,7 @@ DEFUN (show_ipv6_route,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V6_HEADER);
first = 0;
}
vty_show_ipv6_route (vty, rn, rib);
@@ -1832,7 +1716,7 @@ DEFUN (show_ipv6_route_prefix_longer,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V6_HEADER);
first = 0;
}
vty_show_ipv6_route (vty, rn, rib);
@@ -1842,17 +1726,11 @@ DEFUN (show_ipv6_route_prefix_longer,
DEFUN (show_ipv6_route_protocol,
show_ipv6_route_protocol_cmd,
- "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)",
+ "show ipv6 route " QUAGGA_IP6_REDIST_STR_ZEBRA,
SHOW_STR
IP_STR
"IP routing table\n"
- "Border Gateway Protocol (BGP)\n"
- "Connected\n"
- "ISO IS-IS (ISIS)\n"
- "Kernel\n"
- "Open Shortest Path First (OSPFv3)\n"
- "Routing Information Protocol (RIPng)\n"
- "Static routes\n")
+ QUAGGA_IP6_REDIST_HELP_STR_ZEBRA)
{
int type;
struct route_table *table;
@@ -1860,21 +1738,8 @@ DEFUN (show_ipv6_route_protocol,
struct rib *rib;
int first = 1;
- if (strncmp (argv[0], "b", 1) == 0)
- type = ZEBRA_ROUTE_BGP;
- else if (strncmp (argv[0], "c", 1) == 0)
- type = ZEBRA_ROUTE_CONNECT;
- else if (strncmp (argv[0], "k", 1) ==0)
- type = ZEBRA_ROUTE_KERNEL;
- else if (strncmp (argv[0], "o", 1) == 0)
- type = ZEBRA_ROUTE_OSPF6;
- else if (strncmp (argv[0], "i", 1) == 0)
- type = ZEBRA_ROUTE_ISIS;
- else if (strncmp (argv[0], "r", 1) == 0)
- type = ZEBRA_ROUTE_RIPNG;
- else if (strncmp (argv[0], "s", 1) == 0)
- type = ZEBRA_ROUTE_STATIC;
- else
+ type = proto_redistnum (AFI_IP6, argv[0]);
+ if (type < 0)
{
vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -1891,7 +1756,7 @@ DEFUN (show_ipv6_route_protocol,
{
if (first)
{
- vty_out (vty, SHOW_ROUTE_V6_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
+ vty_out (vty, SHOW_ROUTE_V6_HEADER);
first = 0;
}
vty_show_ipv6_route (vty, rn, rib);
@@ -2031,14 +1896,11 @@ static_config_ipv6 (struct vty *vty)
vty_out (vty, " %s %s",
inet_ntop (AF_INET6, &si->ipv6, buf, BUFSIZ), si->ifname);
break;
+ case STATIC_IPV6_BLACKHOLE:
+ vty_out (vty, " Null0 %s", BLACKHOLE_NAME (si->zflags));
+ break;
}
- if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
- vty_out (vty, " %s", "reject");
-
- if (CHECK_FLAG(si->flags, ZEBRA_FLAG_BLACKHOLE))
- vty_out (vty, " %s", "blackhole");
-
if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT)
vty_out (vty, " %d", si->distance);
vty_out (vty, "%s", VTY_NEWLINE);
@@ -2139,21 +2001,17 @@ zebra_vty_init (void)
#ifdef HAVE_IPV6
install_element (CONFIG_NODE, &ipv6_route_cmd);
- install_element (CONFIG_NODE, &ipv6_route_flags_cmd);
install_element (CONFIG_NODE, &ipv6_route_ifname_cmd);
- install_element (CONFIG_NODE, &ipv6_route_ifname_flags_cmd);
install_element (CONFIG_NODE, &no_ipv6_route_cmd);
- install_element (CONFIG_NODE, &no_ipv6_route_flags_cmd);
install_element (CONFIG_NODE, &no_ipv6_route_ifname_cmd);
- install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd);
install_element (CONFIG_NODE, &ipv6_route_pref_cmd);
- install_element (CONFIG_NODE, &ipv6_route_flags_pref_cmd);
install_element (CONFIG_NODE, &ipv6_route_ifname_pref_cmd);
- install_element (CONFIG_NODE, &ipv6_route_ifname_flags_pref_cmd);
install_element (CONFIG_NODE, &no_ipv6_route_pref_cmd);
- install_element (CONFIG_NODE, &no_ipv6_route_flags_pref_cmd);
install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_cmd);
- install_element (CONFIG_NODE, &no_ipv6_route_ifname_flags_pref_cmd);
+ install_element (CONFIG_NODE, &ipv6_route_blackhole_cmd);
+ install_element (CONFIG_NODE, &ipv6_route_blackhole_pref_cmd);
+ install_element (CONFIG_NODE, &no_ipv6_route_blackhole_cmd);
+ install_element (CONFIG_NODE, &no_ipv6_route_blackhole_pref_cmd);
install_element (VIEW_NODE, &show_ipv6_route_cmd);
install_element (VIEW_NODE, &show_ipv6_route_summary_cmd);
install_element (VIEW_NODE, &show_ipv6_route_protocol_cmd);
diff --git a/zebra/zserv.c b/zebra/zserv.c
index cb5e411c..ced8fa5a 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -1,5 +1,6 @@
/* Zebra daemon server routine.
* Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
+ * Portions Copyright (c) 2008 Everton da Silva Marques <everton.marques@gmail.com>
*
* This file is part of GNU Zebra.
*
@@ -36,6 +37,7 @@
#include "privs.h"
#include "network.h"
#include "buffer.h"
+#include "paths.h"
#include "zebra/zserv.h"
#include "zebra/router-id.h"
@@ -595,6 +597,77 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr)
return zebra_server_send_message(client);
}
+/*
+ Modified version of zsend_ipv4_nexthop_lookup():
+ 1) Returns both nexthop address and nexthop ifindex
+ (with ZEBRA_NEXTHOP_IPV4_IFINDEX).
+ 2) Returns both route metric and protocol distance.
+*/
+static int
+zsend_ipv4_nexthop_lookup_v2 (struct zserv *client, struct in_addr addr)
+{
+ struct stream *s;
+ struct rib *rib;
+ unsigned long nump;
+ u_char num;
+ struct nexthop *nexthop;
+
+ /* Lookup nexthop. */
+ rib = rib_match_ipv4 (addr);
+
+ /* Get output stream. */
+ s = client->obuf;
+ stream_reset (s);
+
+ /* Fill in result. */
+ zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP_V2);
+ stream_put_in_addr (s, &addr);
+
+ if (rib)
+ {
+ stream_putc (s, rib->distance);
+ stream_putl (s, rib->metric);
+ num = 0;
+ nump = stream_get_endp(s); /* remember position for nexthop_num */
+ stream_putc (s, 0); /* reserve room for nexthop_num */
+ for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
+ if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB))
+ {
+ stream_putc (s, nexthop->type);
+ switch (nexthop->type)
+ {
+ case ZEBRA_NEXTHOP_IPV4:
+ stream_put_in_addr (s, &nexthop->gate.ipv4);
+ break;
+ case ZEBRA_NEXTHOP_IFINDEX:
+ case ZEBRA_NEXTHOP_IFNAME:
+ stream_putl (s, nexthop->ifindex);
+ break;
+ case ZEBRA_NEXTHOP_IPV4_IFINDEX:
+ stream_put_in_addr (s, &nexthop->gate.ipv4);
+ stream_putl (s, nexthop->ifindex);
+ break;
+ default:
+ /* do nothing */
+ break;
+ }
+ num++;
+ }
+
+ stream_putc_at (s, nump, num); /* store nexthop_num */
+ }
+ else
+ {
+ stream_putc (s, 0); /* distance */
+ stream_putl (s, 0); /* metric */
+ stream_putc (s, 0); /* nexthop_num */
+ }
+
+ stream_putw_at (s, 0, stream_get_endp (s));
+
+ return zebra_server_send_message(client);
+}
+
static int
zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p)
{
@@ -804,6 +877,8 @@ zread_ipv4_add (struct zserv *client, u_short length)
/* Table */
rib->table=zebrad.rtm_table_default;
rib_add_ipv4_multipath (&p, rib);
+
+ rib_update_background ();
return 0;
}
@@ -878,6 +953,8 @@ zread_ipv4_delete (struct zserv *client, u_short length)
rib_delete_ipv4 (api.type, api.flags, &p, &nexthop, ifindex,
client->rtm_table);
+
+ rib_update_background ();
return 0;
}
@@ -891,6 +968,16 @@ zread_ipv4_nexthop_lookup (struct zserv *client, u_short length)
return zsend_ipv4_nexthop_lookup (client, addr);
}
+/* Nexthop lookup v2 for IPv4. */
+static int
+zread_ipv4_nexthop_lookup_v2 (struct zserv *client, u_short length)
+{
+ struct in_addr addr;
+
+ addr.s_addr = stream_get_ipv4 (client->ibuf);
+ return zsend_ipv4_nexthop_lookup_v2 (client, addr);
+}
+
/* Nexthop lookup for IPv4. */
static int
zread_ipv4_import_lookup (struct zserv *client, u_short length)
@@ -969,6 +1056,8 @@ zread_ipv6_add (struct zserv *client, u_short length)
else
rib_add_ipv6 (api.type, api.flags, &p, &nexthop, ifindex, zebrad.rtm_table_default, api.metric,
api.distance);
+
+ rib_update_background ();
return 0;
}
@@ -1033,6 +1122,8 @@ zread_ipv6_delete (struct zserv *client, u_short length)
rib_delete_ipv6 (api.type, api.flags, &p, NULL, ifindex, client->rtm_table);
else
rib_delete_ipv6 (api.type, api.flags, &p, &nexthop, ifindex, client->rtm_table);
+
+ rib_update_background ();
return 0;
}
@@ -1275,6 +1366,9 @@ zebra_client_read (struct thread *thread)
case ZEBRA_IPV4_NEXTHOP_LOOKUP:
zread_ipv4_nexthop_lookup (client, length);
break;
+ case ZEBRA_IPV4_NEXTHOP_LOOKUP_V2:
+ zread_ipv4_nexthop_lookup_v2 (client, length);
+ break;
#ifdef HAVE_IPV6
case ZEBRA_IPV6_NEXTHOP_LOOKUP:
zread_ipv6_nexthop_lookup (client, length);
@@ -1738,6 +1832,6 @@ zebra_zserv_socket_init (void)
#ifdef HAVE_TCP_ZEBRA
zebra_serv ();
#else
- zebra_serv_un (ZEBRA_SERV_PATH);
+ zebra_serv_un (path_state (ZEBRA_SERV_NAME));
#endif /* HAVE_TCP_ZEBRA */
}
diff --git a/zebra/zserv.h b/zebra/zserv.h
index a7371830..340e7f5d 100644
--- a/zebra/zserv.h
+++ b/zebra/zserv.h
@@ -30,7 +30,9 @@
#define ZEBRA_VTY_PORT 2601
/* Default configuration filename. */
-#define DEFAULT_CONFIG_FILE "zebra.conf"
+#define ZEBRA_CONFIG_NAME "zebra.conf"
+#define ZEBRA_PID_NAME "zebra.pid"
+#define ZEBRA_VTY_NAME "zebra.vty"
/* Client structure. */
struct zserv
@@ -81,6 +83,9 @@ struct zebra_t
/* rib work queue */
struct work_queue *ribq;
struct meta_queue *mq;
+
+ /* rib update thread */
+ struct thread *update;
};
/* Count prefix size from mask length */