openbox lab initialized

This commit is contained in:
2025-11-06 00:01:42 +08:00
parent 0fe20bb24c
commit edb0725375
2508 changed files with 670396 additions and 66 deletions

View File

@@ -0,0 +1,102 @@
/*
* Buffering to output and input.
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_BUFFER_H
#define _ZEBRA_BUFFER_H
/* Create a new buffer. Memory will be allocated in chunks of the given
size. If the argument is 0, the library will supply a reasonable
default size suitable for buffering socket I/O. */
extern struct buffer *buffer_new (size_t);
/* Free all data in the buffer. */
extern void buffer_reset (struct buffer *);
/* This function first calls buffer_reset to release all buffered data.
Then it frees the struct buffer itself. */
extern void buffer_free (struct buffer *);
/* Add the given data to the end of the buffer. */
extern void buffer_put (struct buffer *, const void *, size_t);
/* Add a single character to the end of the buffer. */
extern void buffer_putc (struct buffer *, u_char);
/* Add a NUL-terminated string to the end of the buffer. */
extern void buffer_putstr (struct buffer *, const char *);
/* Combine all accumulated (and unflushed) data inside the buffer into a
single NUL-terminated string allocated using XMALLOC(MTYPE_TMP). Note
that this function does not alter the state of the buffer, so the data
is still inside waiting to be flushed. */
char *buffer_getstr (struct buffer *);
/* Returns 1 if there is no pending data in the buffer. Otherwise returns 0. */
int buffer_empty (struct buffer *);
typedef enum
{
/* An I/O error occurred. The buffer should be destroyed and the
file descriptor should be closed. */
BUFFER_ERROR = -1,
/* The data was written successfully, and the buffer is now empty
(there is no pending data waiting to be flushed). */
BUFFER_EMPTY = 0,
/* There is pending data in the buffer waiting to be flushed. Please
try flushing the buffer when select indicates that the file descriptor
is writeable. */
BUFFER_PENDING = 1
} buffer_status_t;
/* Try to write this data to the file descriptor. Any data that cannot
be written immediately is added to the buffer queue. */
extern buffer_status_t buffer_write(struct buffer *, int fd,
const void *, size_t);
/* This function attempts to flush some (but perhaps not all) of
the queued data to the given file descriptor. */
extern buffer_status_t buffer_flush_available(struct buffer *, int fd);
/* The following 2 functions (buffer_flush_all and buffer_flush_window)
are for use in lib/vty.c only. They should not be used elsewhere. */
/* Call buffer_flush_available repeatedly until either all data has been
flushed, or an I/O error has been encountered, or the operation would
block. */
extern buffer_status_t buffer_flush_all (struct buffer *, int fd);
/* Attempt to write enough data to the given fd to fill a window of the
given width and height (and remove the data written from the buffer).
If !no_more, then a message saying " --More-- " is appended.
If erase is true, then first overwrite the previous " --More-- " message
with spaces.
Any write error (including EAGAIN or EINTR) will cause this function
to return -1 (because the logic for handling the erase and more features
is too complicated to retry the write later).
*/
extern buffer_status_t buffer_flush_window (struct buffer *, int fd, int width,
int height, int erase, int no_more);
#endif /* _ZEBRA_BUFFER_H */

View File

@@ -0,0 +1,3 @@
extern int in_cksum(void *, int);
#define FLETCHER_CHECKSUM_VALIDATE 0xffff
extern u_int16_t fletcher_checksum(u_char *, const size_t len, const uint16_t offset);

View File

@@ -0,0 +1,545 @@
/*
* Zebra configuration command interface routine
* Copyright (C) 1997, 98 Kunihiro Ishiguro
*
* 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_COMMAND_H
#define _ZEBRA_COMMAND_H
#include "vector.h"
#include "vty.h"
#include "lib/route_types.h"
/* Host configuration variable */
struct host
{
/* Host name of this router. */
char *name;
/* Password for vty interface. */
char *password;
char *password_encrypt;
/* Enable password */
char *enable;
char *enable_encrypt;
/* System wide terminal lines. */
int lines;
/* Log filename. */
char *logfile;
/* config file name of this host */
char *config;
/* Flags for services */
int advanced;
int encrypt;
/* Banner configuration. */
const char *motd;
char *motdfile;
};
/* There are some command levels which called from command node. */
enum node_type
{
AUTH_NODE, /* Authentication mode of vty interface. */
RESTRICTED_NODE, /* Restricted view mode */
VIEW_NODE, /* View node. Default mode of vty interface. */
AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
ENABLE_NODE, /* Enable node. */
CONFIG_NODE, /* Config node. Default mode of config file. */
SERVICE_NODE, /* Service node. */
DEBUG_NODE, /* Debug node. */
AAA_NODE, /* AAA node. */
KEYCHAIN_NODE, /* Key-chain node. */
KEYCHAIN_KEY_NODE, /* Key-chain key node. */
INTERFACE_NODE, /* Interface mode node. */
ZEBRA_NODE, /* zebra connection node. */
TABLE_NODE, /* rtm_table selection node. */
RIP_NODE, /* RIP protocol mode node. */
RIPNG_NODE, /* RIPng protocol mode node. */
BABEL_NODE, /* Babel protocol mode node. */
BGP_NODE, /* BGP protocol mode which includes BGP4+ */
BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
BGP_IPV6_NODE, /* BGP IPv6 address family */
BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
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. */
ACCESS_NODE, /* Access list node. */
PREFIX_NODE, /* Prefix list node. */
ACCESS_IPV6_NODE, /* Access list node. */
PREFIX_IPV6_NODE, /* Prefix list node. */
AS_LIST_NODE, /* AS list node. */
COMMUNITY_LIST_NODE, /* Community list node. */
RMAP_NODE, /* Route map node. */
SMUX_NODE, /* SNMP configuration node. */
DUMP_NODE, /* Packet dump node. */
FORWARDING_NODE, /* IP forwarding node. */
PROTOCOL_NODE, /* protocol filtering node */
VTY_NODE, /* Vty node. */
};
/* Node which has some commands and prompt string and configuration
function pointer . */
struct cmd_node
{
/* Node index. */
enum node_type node;
/* Prompt character at vty interface. */
const char *prompt;
/* Is this node's configuration goes to vtysh ? */
int vtysh;
/* Node's configuration write function */
int (*func) (struct vty *);
/* Vector of this node's command list. */
vector cmd_vector;
};
enum
{
CMD_ATTR_DEPRECATED = 1,
CMD_ATTR_HIDDEN,
};
/* Structure of command element. */
struct cmd_element
{
const char *string; /* Command specification by string. */
int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
const char *doc; /* Documentation of this command. */
int daemon; /* Daemon to which this command belong. */
vector tokens; /* Vector of cmd_tokens */
u_char attr; /* Command attributes */
};
enum cmd_token_type
{
TOKEN_TERMINAL = 0,
TOKEN_MULTIPLE,
TOKEN_KEYWORD,
};
/* Command description structure. */
struct cmd_token
{
enum cmd_token_type type;
/* Used for type == MULTIPLE */
vector multiple; /* vector of cmd_token, type == FINAL */
/* Used for type == KEYWORD */
vector keyword; /* vector of vector of cmd_tokens */
/* Used for type == TERMINAL */
char *cmd; /* Command string. */
char *desc; /* Command's description. */
};
/* Return value of the commands. */
#define CMD_SUCCESS 0
#define CMD_WARNING 1
#define CMD_ERR_NO_MATCH 2
#define CMD_ERR_AMBIGUOUS 3
#define CMD_ERR_INCOMPLETE 4
#define CMD_ERR_EXEED_ARGC_MAX 5
#define CMD_ERR_NOTHING_TODO 6
#define CMD_COMPLETE_FULL_MATCH 7
#define CMD_COMPLETE_MATCH 8
#define CMD_COMPLETE_LIST_MATCH 9
#define CMD_SUCCESS_DAEMON 10
/* Argc max counts. */
#define CMD_ARGC_MAX 25
/* Turn off these macros when uisng cpp with extract.pl */
#ifndef VTYSH_EXTRACT_PL
/* helper defines for end-user DEFUN* macros */
#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
struct cmd_element cmdname = \
{ \
.string = cmdstr, \
.func = funcname, \
.doc = helpstr, \
.attr = attrs, \
.daemon = dnum, \
};
#define DEFUN_CMD_FUNC_DECL(funcname) \
static int funcname (struct cmd_element *, struct vty *, int, const char *[]);
#define DEFUN_CMD_FUNC_TEXT(funcname) \
static int funcname \
(struct cmd_element *self __attribute__ ((unused)), \
struct vty *vty __attribute__ ((unused)), \
int argc __attribute__ ((unused)), \
const char *argv[] __attribute__ ((unused)) )
/* DEFUN for vty command interafce. Little bit hacky ;-).
*
* DEFUN(funcname, cmdname, cmdstr, helpstr)
*
* funcname
* ========
*
* Name of the function that will be defined.
*
* cmdname
* =======
*
* Name of the struct that will be defined for the command.
*
* cmdstr
* ======
*
* The cmdstr defines the command syntax. It is used by the vty subsystem
* and vtysh to perform matching and completion in the cli. So you have to take
* care to construct it adhering to the following grammar. The names used
* for the production rules losely represent the names used in lib/command.c
*
* cmdstr = cmd_token , { " " , cmd_token } ;
*
* cmd_token = cmd_terminal
* | cmd_multiple
* | cmd_keyword ;
*
* cmd_terminal_fixed = fixed_string
* | variable
* | range
* | ipv4
* | ipv4_prefix
* | ipv6
* | ipv6_prefix ;
*
* cmd_terminal = cmd_terminal_fixed
* | option
* | vararg ;
*
* multiple_part = cmd_terminal_fixed ;
* cmd_multiple = "(" , multiple_part , ( "|" | { "|" , multiple_part } ) , ")" ;
*
* keyword_part = fixed_string , { " " , ( cmd_terminal_fixed | cmd_multiple ) } ;
* cmd_keyword = "{" , keyword_part , { "|" , keyword_part } , "}" ;
*
* lowercase = "a" | ... | "z" ;
* uppercase = "A" | ... | "Z" ;
* digit = "0" | ... | "9" ;
* number = digit , { digit } ;
*
* fixed_string = (lowercase | digit) , { lowercase | digit | uppercase | "-" | "_" } ;
* variable = uppercase , { uppercase | "_" } ;
* range = "<" , number , "-" , number , ">" ;
* ipv4 = "A.B.C.D" ;
* ipv4_prefix = "A.B.C.D/M" ;
* ipv6 = "X:X::X:X" ;
* ipv6_prefix = "X:X::X:X/M" ;
* option = "[" , variable , "]" ;
* vararg = "." , variable ;
*
* To put that all in a textual description: A cmdstr is a sequence of tokens,
* separated by spaces.
*
* Terminal Tokens:
*
* A very simple cmdstring would be something like: "show ip bgp". It consists
* of three Terminal Tokens, each containing a fixed string. When this command
* is called, no arguments will be passed down to the function implementing it,
* as it only consists of fixed strings.
*
* Apart from fixed strings, Terminal Tokens can also contain variables:
* An example would be "show ip bgp A.B.C.D". This command expects an IPv4
* as argument. As this is a variable, the IP address entered by the user will
* be passed down as an argument. Apart from two exceptions, the other options
* for Terminal Tokens behave exactly as we just discussed and only make a
* difference for the CLI. The two exceptions will be discussed in the next
* paragraphs.
*
* A Terminal Token can contain a so called option match. This is a simple
* string variable that the user may omit. An example would be:
* "show interface [IFNAME]". If the user calls this without an interface as
* argument, no arguments will be passed down to the function implementing
* this command. Otherwise, the interface name will be provided to the function
* as a regular argument.
* Also, a Terminal Token can contain a so called vararg. This is used e.g. in
* "show ip bgp regexp .LINE". The last token is a vararg match and will
* consume all the arguments the user inputs on the command line and append
* those to the list of arguments passed down to the function implementing this
* command. (Therefore, it doesn't make much sense to have any tokens after a
* vararg because the vararg will already consume all the words the user entered
* in the CLI)
*
* Multiple Tokens:
*
* The Multiple Token type can be used if there are multiple possibilities what
* arguments may be used for a command, but it should map to the same function
* nonetheless. An example would be "ip route A.B.C.D/M (reject|blackhole)"
* In that case both "reject" and "blackhole" would be acceptable as last
* arguments. The words matched by Multiple Tokens are always added to the
* argument list, even if they are matched by fixed strings. Such a Multiple
* Token can contain almost any type of token that would also be acceptable
* for a Terminal Token, the exception are optional variables and varag.
*
* There is one special case that is used in some places of Quagga that should be
* pointed out here shortly. An example would be "password (8|) WORD". This
* construct is used to have fixed strings communicated as arguments. (The "8"
* will be passed down as an argument in this case) It does not mean that
* the "8" is optional. Another historic and possibly surprising property of
* this construct is that it consumes two parts of helpstr. (Help
* strings will be explained later)
*
* Keyword Tokens:
*
* There are commands that take a lot of different and possibly optional arguments.
* An example from ospf would be the "default-information originate" command. This
* command takes a lot of optional arguments that may be provided in any order.
* To accomodate such commands, the Keyword Token has been implemented.
* Using the keyword token, the "default-information originate" command and all
* its possible options can be represented using this single cmdstr:
* "default-information originate \
* {always|metric <0-16777214>|metric-type (1|2)|route-map WORD}"
*
* Keywords always start with a fixed string and may be followed by arguments.
* Except optional variables and vararg, everything is permitted here.
*
* For the special case of a keyword without arguments, either NULL or the
* keyword itself will be pushed as an argument, depending on whether the
* keyword is present.
* For the other keywords, arguments will be only pushed for
* variables/Multiple Tokens. If the keyword is not present, the arguments that
* would have been pushed will be substituted by NULL.
*
* A few examples:
* "default information originate metric-type 1 metric 1000"
* would yield the following arguments:
* { NULL, "1000", "1", NULL }
*
* "default information originate always route-map RMAP-DEFAULT"
* would yield the following arguments:
* { "always", NULL, NULL, "RMAP-DEFAULT" }
*
* helpstr
* =======
*
* The helpstr is used to show a short explantion for the commands that
* are available when the user presses '?' on the CLI. It is the concatenation
* of the helpstrings for all the tokens that make up the command.
*
* There should be one helpstring for each token in the cmdstr except those
* containing other tokens, like Multiple or Keyword Tokens. For those, there
* will only be the helpstrings of the contained tokens.
*
* The individual helpstrings are expected to be in the same order as their
* respective Tokens appear in the cmdstr. They should each be terminated with
* a linefeed. The last helpstring should be terminated with a linefeed as well.
*
* Care should also be taken to avoid having similar tokens with different
* helpstrings. Imagine e.g. the commands "show ip ospf" and "show ip bgp".
* they both contain a helpstring for "show", but only one will be displayed
* when the user enters "sh?". If those two helpstrings differ, it is not
* defined which one will be shown and the behavior is therefore unpredictable.
*/
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_FUNC_DECL(funcname) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
DEFUN_CMD_FUNC_TEXT(funcname)
#define DEFUN_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
DEFUN_CMD_FUNC_DECL(funcname) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0) \
DEFUN_CMD_FUNC_TEXT(funcname)
#define DEFUN_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
#define DEFUN_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
DEFUN_ATTR (funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED) \
/* DEFUN_NOSH for commands that vtysh should ignore */
#define DEFUN_NOSH(funcname, cmdname, cmdstr, helpstr) \
DEFUN(funcname, cmdname, cmdstr, helpstr)
/* DEFSH for vtysh. */
#define DEFSH(daemon, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(NULL, cmdname, cmdstr, helpstr, 0, daemon) \
/* DEFUN + DEFSH */
#define DEFUNSH(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_FUNC_DECL(funcname) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon) \
DEFUN_CMD_FUNC_TEXT(funcname)
/* DEFUN + DEFSH with attributes */
#define DEFUNSH_ATTR(daemon, funcname, cmdname, cmdstr, helpstr, attr) \
DEFUN_CMD_FUNC_DECL(funcname) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, daemon) \
DEFUN_CMD_FUNC_TEXT(funcname)
#define DEFUNSH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN)
#define DEFUNSH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUNSH_ATTR (daemon, funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED)
/* ALIAS macro which define existing command's alias. */
#define ALIAS(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0)
#define ALIAS_ATTR(funcname, cmdname, cmdstr, helpstr, attr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attr, 0)
#define ALIAS_HIDDEN(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, 0)
#define ALIAS_DEPRECATED(funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, 0)
#define ALIAS_SH(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, daemon)
#define ALIAS_SH_HIDDEN(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_HIDDEN, daemon)
#define ALIAS_SH_DEPRECATED(daemon, funcname, cmdname, cmdstr, helpstr) \
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, CMD_ATTR_DEPRECATED, daemon)
#endif /* VTYSH_EXTRACT_PL */
/* Some macroes */
#define CMD_OPTION(S) ((S[0]) == '[')
#define CMD_VARIABLE(S) (((S[0]) >= 'A' && (S[0]) <= 'Z') || ((S[0]) == '<'))
#define CMD_VARARG(S) ((S[0]) == '.')
#define CMD_RANGE(S) ((S[0] == '<'))
#define CMD_IPV4(S) ((strcmp ((S), "A.B.C.D") == 0))
#define CMD_IPV4_PREFIX(S) ((strcmp ((S), "A.B.C.D/M") == 0))
#define CMD_IPV6(S) ((strcmp ((S), "X:X::X:X") == 0))
#define CMD_IPV6_PREFIX(S) ((strcmp ((S), "X:X::X:X/M") == 0))
/* Common descriptions. */
#define SHOW_STR "Show running system information\n"
#define IP_STR "IP information\n"
#define IPV6_STR "IPv6 information\n"
#define NO_STR "Negate a command or set its defaults\n"
#define REDIST_STR "Redistribute information from another routing protocol\n"
#define CLEAR_STR "Reset functions\n"
#define RIP_STR "RIP information\n"
#define BGP_STR "BGP information\n"
#define OSPF_STR "OSPF information\n"
#define NEIGHBOR_STR "Specify neighbor router\n"
#define DEBUG_STR "Debugging functions (see also 'undebug')\n"
#define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n"
#define ROUTER_STR "Enable a routing process\n"
#define AS_STR "AS number\n"
#define MBGP_STR "MBGP information\n"
#define MATCH_STR "Match values from routing table\n"
#define SET_STR "Set values in destination routing protocol\n"
#define OUT_STR "Filter outgoing routing updates\n"
#define IN_STR "Filter incoming routing updates\n"
#define V4NOTATION_STR "specify by IPv4 address notation(e.g. 0.0.0.0)\n"
#define OSPF6_NUMBER_STR "Specify by number\n"
#define INTERFACE_STR "Interface infomation\n"
#define IFNAME_STR "Interface name(e.g. ep0)\n"
#define IP6_STR "IPv6 Information\n"
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
#define OSPF6_ROUTER_STR "Enable a routing process\n"
#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
#define SECONDS_STR "<1-65535> Seconds\n"
#define ROUTE_STR "Routing Table\n"
#define PREFIX_LIST_STR "Build a prefix list\n"
#define OSPF6_DUMP_TYPE_LIST \
"(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
#define ISIS_STR "IS-IS information\n"
#define AREA_TAG_STR "[area tag]\n"
#define CONF_BACKUP_EXT ".sav"
/* IPv4 only machine should not accept IPv6 address for peer's IP
address. So we replace VTY command string like below. */
#ifdef HAVE_IPV6
#define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
#define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nNeighbor tag\n"
#else
#define NEIGHBOR_CMD "neighbor A.B.C.D "
#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
#define NEIGHBOR_ADDR_STR "Neighbor address\n"
#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
#endif /* HAVE_IPV6 */
/* Prototypes. */
extern void install_node (struct cmd_node *, int (*) (struct vty *));
extern void install_default (enum node_type);
extern void install_element (enum node_type, struct cmd_element *);
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
string with a space between each element (allocated using
XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
extern char *argv_concat (const char **argv, int argc, int shift);
extern vector cmd_make_strvec (const char *);
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 *, 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 **);
extern void cmd_init (int);
extern void cmd_terminate (void);
/* Export typical functions. */
extern struct cmd_element config_end_cmd;
extern struct cmd_element config_exit_cmd;
extern struct cmd_element config_quit_cmd;
extern struct cmd_element config_help_cmd;
extern struct cmd_element config_list_cmd;
extern char *host_config_file (void);
extern void host_config_set (char *);
extern void print_version (const char *);
/* struct host global, ick */
extern struct host host;
/* "<cr>" global */
extern char *command_cr;
#endif /* _ZEBRA_COMMAND_H */

View File

@@ -0,0 +1,60 @@
/* Distribute list functions header
* Copyright (C) 1999 Kunihiro Ishiguro
*
* 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_DISTRIBUTE_H
#define _ZEBRA_DISTRIBUTE_H
#include <zebra.h>
#include "if.h"
/* Disctirubte list types. */
enum distribute_type
{
DISTRIBUTE_IN,
DISTRIBUTE_OUT,
DISTRIBUTE_MAX
};
struct distribute
{
/* Name of the interface. */
char *ifname;
/* Filter name of `in' and `out' */
char *list[DISTRIBUTE_MAX];
/* prefix-list name of `in' and `out' */
char *prefix[DISTRIBUTE_MAX];
};
/* Prototypes for distribute-list. */
extern void distribute_list_init (int);
extern void distribute_list_reset (void);
extern void distribute_list_add_hook (void (*) (struct distribute *));
extern void distribute_list_delete_hook (void (*) (struct distribute *));
extern struct distribute *distribute_lookup (const char *);
extern int config_write_distribute (struct vty *);
extern int config_show_distribute (struct vty *);
extern enum filter_type distribute_apply_in (struct interface *, struct prefix *);
extern enum filter_type distribute_apply_out (struct interface *, struct prefix *);
#endif /* _ZEBRA_DISTRIBUTE_H */

View File

@@ -0,0 +1,67 @@
/*
* Route filtering function.
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_FILTER_H
#define _ZEBRA_FILTER_H
#include "if.h"
/* Filter type is made by `permit', `deny' and `dynamic'. */
enum filter_type
{
FILTER_DENY,
FILTER_PERMIT,
FILTER_DYNAMIC
};
enum access_type
{
ACCESS_TYPE_STRING,
ACCESS_TYPE_NUMBER
};
/* Access list */
struct access_list
{
char *name;
char *remark;
struct access_master *master;
enum access_type type;
struct access_list *next;
struct access_list *prev;
struct filter *head;
struct filter *tail;
};
/* Prototypes for access-list. */
extern void access_list_init (void);
extern void access_list_reset (void);
extern void access_list_add_hook (void (*func)(struct access_list *));
extern void access_list_delete_hook (void (*func)(struct access_list *));
extern struct access_list *access_list_lookup (afi_t, const char *);
extern enum filter_type access_list_apply (struct access_list *, void *);
#endif /* _ZEBRA_FILTER_H */

View File

@@ -0,0 +1,159 @@
/* Declarations for getopt.
Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@gnu.org.
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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
/*
* The operating system may or may not provide getopt_long(), and if
* so it may or may not be a version we are willing to use. Our
* strategy is to declare getopt here, and then provide code unless
* the supplied version is adequate. The difficult case is when a
* declaration for getopt is provided, as our declaration must match.
*
* XXX Arguably this version should be named differently, and the
* local names defined to refer to the system version when we choose
* to use the system version.
*/
#ifdef __cplusplus
extern "C" {
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
#if defined (__STDC__) && __STDC__
const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if defined (__STDC__) && __STDC__
#if REALLY_NEED_PLAIN_GETOPT
/*
* getopt is defined in POSIX.2. Assume that if the system defines
* getopt that it complies with POSIX.2. If not, an autoconf test
* should be written to define NONPOSIX_GETOPT_DEFINITION.
*/
#ifndef NONPOSIX_GETOPT_DEFINITION
extern int getopt (int argc, char *const *argv, const char *shortopts);
#else /* NONPOSIX_GETOPT_DEFINITION */
extern int getopt (void);
#endif /* NONPOSIX_GETOPT_DEFINITION */
#endif
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
#ifdef REALLY_NEED_PLAIN_GETOPT
extern int getopt ();
#endif /* REALLY_NEED_PLAIN_GETOPT */
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* __STDC__ */
#ifdef __cplusplus
}
#endif
#endif /* getopt.h */

View File

@@ -0,0 +1,79 @@
/* Hash routine.
Copyright (C) 1998 Kunihiro Ishiguro
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_HASH_H
#define _ZEBRA_HASH_H
/* Default hash table size. */
#define HASH_INITIAL_SIZE 256 /* initial number of backets. */
#define HASH_THRESHOLD 10 /* expand when backet. */
struct hash_backet
{
/* Linked list. */
struct hash_backet *next;
/* Hash key. */
unsigned int key;
/* Data. */
void *data;
};
struct hash
{
/* Hash backet. */
struct hash_backet **index;
/* Hash table size. Must be power of 2 */
unsigned int size;
/* If expansion failed. */
int no_expand;
/* Key make function. */
unsigned int (*hash_key) (void *);
/* Data compare function. */
int (*hash_cmp) (const void *, const void *);
/* Backet alloc. */
unsigned long count;
};
extern struct hash *hash_create (unsigned int (*) (void *),
int (*) (const void *, const void *));
extern struct hash *hash_create_size (unsigned int, unsigned int (*) (void *),
int (*) (const void *, const void *));
extern void *hash_get (struct hash *, void *, void * (*) (void *));
extern void *hash_alloc_intern (void *);
extern void *hash_lookup (struct hash *, void *);
extern void *hash_release (struct hash *, void *);
extern void hash_iterate (struct hash *,
void (*) (struct hash_backet *, void *), void *);
extern void hash_clean (struct hash *, void (*) (void *));
extern void hash_free (struct hash *);
extern unsigned int string_hash_make (const char *);
#endif /* _ZEBRA_HASH_H */

View File

@@ -0,0 +1,324 @@
/* Interface related header.
Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
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_IF_H
#define _ZEBRA_IF_H
#include "linklist.h"
/*
Interface name length.
Linux define value in /usr/include/linux/if.h.
#define IFNAMSIZ 16
FreeBSD define value in /usr/include/net/if.h.
#define IFNAMSIZ 16
*/
#define INTERFACE_NAMSIZ 20
#define INTERFACE_HWADDR_MAX 20
#ifdef HAVE_PROC_NET_DEV
struct if_stats
{
unsigned long rx_packets; /* total packets received */
unsigned long tx_packets; /* total packets transmitted */
unsigned long rx_bytes; /* total bytes received */
unsigned long tx_bytes; /* total bytes transmitted */
unsigned long rx_errors; /* bad packets received */
unsigned long tx_errors; /* packet transmit problems */
unsigned long rx_dropped; /* no space in linux buffers */
unsigned long tx_dropped; /* no space available in linux */
unsigned long rx_multicast; /* multicast packets received */
unsigned long rx_compressed;
unsigned long tx_compressed;
unsigned long collisions;
/* detailed rx_errors: */
unsigned long rx_length_errors;
unsigned long rx_over_errors; /* receiver ring buff overflow */
unsigned long rx_crc_errors; /* recved pkt with crc error */
unsigned long rx_frame_errors; /* recv'd frame alignment error */
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
unsigned long rx_missed_errors; /* receiver missed packet */
/* detailed tx_errors */
unsigned long tx_aborted_errors;
unsigned long tx_carrier_errors;
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
};
#endif /* HAVE_PROC_NET_DEV */
/* Interface structure */
struct interface
{
/* Interface name. This should probably never be changed after the
interface is created, because the configuration info for this interface
is associated with this structure. For that reason, the interface
should also never be deleted (to avoid losing configuration info).
To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
interface does not exist in the kernel.
*/
char name[INTERFACE_NAMSIZ + 1];
/* Interface index (should be IFINDEX_INTERNAL for non-kernel or
deleted interfaces). */
unsigned int ifindex;
#define IFINDEX_INTERNAL 0
/* Zebra internal interface status */
u_char status;
#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
#define ZEBRA_INTERFACE_SUB (1 << 1)
#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
/* Interface flags. */
uint64_t flags;
/* Interface metric */
int metric;
/* Interface MTU. */
unsigned int mtu; /* IPv4 MTU */
unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
/* Hardware address. */
#ifdef HAVE_STRUCT_SOCKADDR_DL
union {
/* note that sdl_storage is never accessed, it only exists to make space.
* all actual uses refer to sdl - but use sizeof(sdl_storage)! this fits
* best with C aliasing rules. */
struct sockaddr_dl sdl;
struct sockaddr_storage sdl_storage;
};
#else
unsigned short hw_type;
u_char hw_addr[INTERFACE_HWADDR_MAX];
int hw_addr_len;
#endif /* HAVE_STRUCT_SOCKADDR_DL */
/* interface bandwidth, kbits */
unsigned int bandwidth;
/* description of the interface. */
char *desc;
/* Distribute list. */
void *distribute_in;
void *distribute_out;
/* Connected address list. */
struct list *connected;
/* Daemon specific interface data pointer. */
void *info;
/* Statistics fileds. */
#ifdef HAVE_PROC_NET_DEV
struct if_stats stats;
#endif /* HAVE_PROC_NET_DEV */
#ifdef HAVE_NET_RT_IFLIST
struct if_data stats;
#endif /* HAVE_NET_RT_IFLIST */
};
/* Connected address structure. */
struct connected
{
/* Attached interface. */
struct interface *ifp;
/* Flags for configuration. */
u_char conf;
#define ZEBRA_IFC_REAL (1 << 0)
#define ZEBRA_IFC_CONFIGURED (1 << 1)
#define ZEBRA_IFC_QUEUED (1 << 2)
/*
The ZEBRA_IFC_REAL flag should be set if and only if this address
exists in the kernel and is actually usable. (A case where it exists but
is not yet usable would be IPv6 with DAD)
The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
was configured by the user from inside quagga.
The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
in the kernel. It may and should be set although the address might not be
usable yet. (compare with ZEBRA_IFC_REAL)
*/
/* Flags for connected address. */
u_char flags;
#define ZEBRA_IFA_SECONDARY (1 << 0)
#define ZEBRA_IFA_PEER (1 << 1)
/* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
a peer address has been configured. If this flag is set,
the destination field must contain the peer address.
Otherwise, if this flag is not set, the destination address
will either contain a broadcast address or be NULL.
*/
/* Address of connected network. */
struct prefix *address;
/* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
struct prefix *destination;
/* Label for Linux 2.2.X and upper. */
char *label;
};
/* Does the destination field contain a peer address? */
#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
/* Prefix to insert into the RIB */
#define CONNECTED_PREFIX(C) \
(CONNECTED_PEER(C) ? (C)->destination : (C)->address)
/* Identifying address. We guess that if there's a peer address, but the
local address is in the same prefix, then the local address may be unique. */
#define CONNECTED_ID(C) \
((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
(C)->destination : (C)->address)
/* Interface hook sort. */
#define IF_NEW_HOOK 0
#define IF_DELETE_HOOK 1
/* There are some interface flags which are only supported by some
operating system. */
#ifndef IFF_NOTRAILERS
#define IFF_NOTRAILERS 0x0
#endif /* IFF_NOTRAILERS */
#ifndef IFF_OACTIVE
#define IFF_OACTIVE 0x0
#endif /* IFF_OACTIVE */
#ifndef IFF_SIMPLEX
#define IFF_SIMPLEX 0x0
#endif /* IFF_SIMPLEX */
#ifndef IFF_LINK0
#define IFF_LINK0 0x0
#endif /* IFF_LINK0 */
#ifndef IFF_LINK1
#define IFF_LINK1 0x0
#endif /* IFF_LINK1 */
#ifndef IFF_LINK2
#define IFF_LINK2 0x0
#endif /* IFF_LINK2 */
#ifndef IFF_NOXMIT
#define IFF_NOXMIT 0x0
#endif /* IFF_NOXMIT */
#ifndef IFF_NORTEXCH
#define IFF_NORTEXCH 0x0
#endif /* IFF_NORTEXCH */
#ifndef IFF_IPV4
#define IFF_IPV4 0x0
#endif /* IFF_IPV4 */
#ifndef IFF_IPV6
#define IFF_IPV6 0x0
#endif /* IFF_IPV6 */
#ifndef IFF_VIRTUAL
#define IFF_VIRTUAL 0x0
#endif /* IFF_VIRTUAL */
/* Prototypes. */
extern int if_cmp_func (struct interface *, struct interface *);
extern struct interface *if_create (const char *name, int namelen);
extern struct interface *if_lookup_by_index (unsigned int);
extern struct interface *if_lookup_exact_address (struct in_addr);
extern struct interface *if_lookup_address (struct in_addr);
extern struct interface *if_lookup_prefix (struct prefix *prefix);
/* These 2 functions are to be used when the ifname argument is terminated
by a '\0' character: */
extern struct interface *if_lookup_by_name (const char *ifname);
extern struct interface *if_get_by_name (const char *ifname);
/* For these 2 functions, the namelen argument should be the precise length
of the ifname string (not counting any optional trailing '\0' character).
In most cases, strnlen should be used to calculate the namelen value. */
extern struct interface *if_lookup_by_name_len(const char *ifname,
size_t namelen);
extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
/* Delete the interface, but do not free the structure, and leave it in the
interface list. It is often advisable to leave the pseudo interface
structure because there may be configuration information attached. */
extern void if_delete_retain (struct interface *);
/* Delete and free the interface structure: calls if_delete_retain and then
deletes it from the interface list and frees the structure. */
extern void if_delete (struct interface *);
extern int if_is_up (struct interface *);
extern int if_is_running (struct interface *);
extern int if_is_operative (struct interface *);
extern int if_is_loopback (struct interface *);
extern int if_is_broadcast (struct interface *);
extern int if_is_pointopoint (struct interface *);
extern int if_is_multicast (struct interface *);
extern void if_add_hook (int, int (*)(struct interface *));
extern void if_init (void);
extern void if_terminate (void);
extern void if_dump_all (void);
extern const char *if_flag_dump(unsigned long);
/* Please use ifindex2ifname instead of if_indextoname where possible;
ifindex2ifname uses internal interface info, whereas if_indextoname must
make a system call. */
extern const char *ifindex2ifname (unsigned int);
/* Please use ifname2ifindex instead of if_nametoindex where possible;
ifname2ifindex uses internal interface info, whereas if_nametoindex must
make a system call. */
extern unsigned int ifname2ifindex(const char *ifname);
/* Connected address functions. */
extern struct connected *connected_new (void);
extern void connected_free (struct connected *);
extern void connected_add (struct interface *, struct connected *);
extern struct connected *connected_add_by_prefix (struct interface *,
struct prefix *,
struct prefix *);
extern struct connected *connected_delete_by_prefix (struct interface *,
struct prefix *);
extern struct connected *connected_lookup_address (struct interface *,
struct in_addr);
#ifndef HAVE_IF_NAMETOINDEX
extern unsigned int if_nametoindex (const char *);
#endif
#ifndef HAVE_IF_INDEXTONAME
extern char *if_indextoname (unsigned int, char *);
#endif
/* Exported variables. */
extern struct list *iflist;
extern struct cmd_element interface_desc_cmd;
extern struct cmd_element no_interface_desc_cmd;
extern struct cmd_element interface_cmd;
extern struct cmd_element no_interface_cmd;
extern struct cmd_element interface_pseudo_cmd;
extern struct cmd_element no_interface_pseudo_cmd;
extern struct cmd_element show_address_cmd;
#endif /* _ZEBRA_IF_H */

View File

@@ -0,0 +1,47 @@
/* route-map for interface.
* Copyright (C) 1999 Kunihiro Ishiguro
*
* 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_IF_RMAP_H
#define _ZEBRA_IF_RMAP_H
enum if_rmap_type
{
IF_RMAP_IN,
IF_RMAP_OUT,
IF_RMAP_MAX
};
struct if_rmap
{
/* Name of the interface. */
char *ifname;
char *routemap[IF_RMAP_MAX];
};
extern void if_rmap_init (int);
extern void if_rmap_reset (void);
extern void if_rmap_hook_add (void (*) (struct if_rmap *));
extern void if_rmap_hook_delete (void (*) (struct if_rmap *));
extern struct if_rmap *if_rmap_lookup (const char *);
extern int config_write_if_rmap (struct vty *);
#endif /* _ZEBRA_IF_RMAP_H */

View File

@@ -0,0 +1,44 @@
/* jhash.h: Jenkins hash support.
*
* Copyright (C) 1996 Bob Jenkins (bob_jenkins@burtleburtle.net)
*
* http://burtleburtle.net/bob/hash/
*
* These are the credits from Bob's sources:
*
* lookup2.c, by Bob Jenkins, December 1996, Public Domain.
* hash(), hash2(), hash3, and mix() are externally useful functions.
* Routines to test the hash are included if SELF_TEST is defined.
* You can use this free for any purpose. It has no warranty.
*
* Copyright (C) 2003 David S. Miller (davem@redhat.com)
*
* I've modified Bob's hash to be useful in the Linux kernel, and
* any bugs present are surely my fault. -DaveM
*/
#ifndef _QUAGGA_JHASH_H
#define _QUAGGA_JHASH_H
/* The most generic version, hashes an arbitrary sequence
* of bytes. No alignment or length assumptions are made about
* the input key.
*/
extern u_int32_t jhash(const void *key, u_int32_t length, u_int32_t initval);
/* A special optimized version that handles 1 or more of u_int32_ts.
* The length parameter here is the number of u_int32_ts in the key.
*/
extern u_int32_t jhash2(const u_int32_t *k, u_int32_t length, u_int32_t initval);
/* A special ultra-optimized versions that knows they are hashing exactly
* 3, 2 or 1 word(s).
*
* NOTE: In partilar the "c += length; __jhash_mix(a,b,c);" normally
* done at the end is not done here.
*/
extern u_int32_t jhash_3words(u_int32_t a, u_int32_t b, u_int32_t c, u_int32_t initval);
extern u_int32_t jhash_2words(u_int32_t a, u_int32_t b, u_int32_t initval);
extern u_int32_t jhash_1word(u_int32_t a, u_int32_t initval);
#endif /* _QUAGGA_JHASH_H */

View File

@@ -0,0 +1,56 @@
/* key-chain for authentication.
* Copyright (C) 2000 Kunihiro Ishiguro
*
* 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_KEYCHAIN_H
#define _ZEBRA_KEYCHAIN_H
struct keychain
{
char *name;
struct list *key;
};
struct key_range
{
time_t start;
time_t end;
u_char duration;
};
struct key
{
u_int32_t index;
char *string;
struct key_range send;
struct key_range accept;
};
extern void keychain_init (void);
extern struct keychain *keychain_lookup (const char *);
extern struct key *key_lookup_for_accept (const struct keychain *, u_int32_t);
extern struct key *key_match_for_accept (const struct keychain *, const char *);
extern struct key *key_lookup_for_send (const struct keychain *);
#endif /* _ZEBRA_KEYCHAIN_H */

View File

@@ -0,0 +1,92 @@
/*
* Defines and structures common to OSPFv2 and OSPFv3
* Copyright (C) 1998, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada
*
* 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 _LIBOSPFD_H
#define _LIBOSPFD_H
/* IP precedence. */
#ifndef IPTOS_PREC_INTERNETCONTROL
#define IPTOS_PREC_INTERNETCONTROL 0xC0
#endif /* IPTOS_PREC_INTERNETCONTROL */
/* Default protocol, port number. */
#ifndef IPPROTO_OSPFIGP
#define IPPROTO_OSPFIGP 89
#endif /* IPPROTO_OSPFIGP */
/* Architectual Constants */
#ifdef DEBUG
#define OSPF_LS_REFRESH_TIME 60
#else
#define OSPF_LS_REFRESH_TIME 1800
#endif
#define OSPF_MIN_LS_INTERVAL 5
#define OSPF_MIN_LS_ARRIVAL 1
#define OSPF_LSA_INITIAL_AGE 0 /* useful for debug */
#define OSPF_LSA_MAXAGE 3600
#define OSPF_CHECK_AGE 300
#define OSPF_LSA_MAXAGE_DIFF 900
#define OSPF_LS_INFINITY 0xffffff
#define OSPF_DEFAULT_DESTINATION 0x00000000 /* 0.0.0.0 */
#define OSPF_INITIAL_SEQUENCE_NUMBER 0x80000001U
#define OSPF_MAX_SEQUENCE_NUMBER 0x7fffffffU
/* OSPF Interface Types */
#define OSPF_IFTYPE_NONE 0
#define OSPF_IFTYPE_POINTOPOINT 1
#define OSPF_IFTYPE_BROADCAST 2
#define OSPF_IFTYPE_NBMA 3
#define OSPF_IFTYPE_POINTOMULTIPOINT 4
#define OSPF_IFTYPE_VIRTUALLINK 5
#define OSPF_IFTYPE_LOOPBACK 6
#define OSPF_IFTYPE_MAX 7
/* OSPF interface default values. */
#define OSPF_OUTPUT_COST_DEFAULT 10
#define OSPF_OUTPUT_COST_INFINITE UINT16_MAX
#define OSPF_ROUTER_DEAD_INTERVAL_DEFAULT 40
#define OSPF_ROUTER_DEAD_INTERVAL_MINIMAL 1
#define OSPF_HELLO_INTERVAL_DEFAULT 10
#define OSPF_ROUTER_PRIORITY_DEFAULT 1
#define OSPF_RETRANSMIT_INTERVAL_DEFAULT 5
#define OSPF_TRANSMIT_DELAY_DEFAULT 1
#define OSPF_DEFAULT_BANDWIDTH 10000 /* Kbps */
#define OSPF_DEFAULT_REF_BANDWIDTH 100000 /* Kbps */
#define OSPF_POLL_INTERVAL_DEFAULT 60
#define OSPF_NEIGHBOR_PRIORITY_DEFAULT 0
#define OSPF_MTU_IGNORE_DEFAULT 0
#define OSPF_FAST_HELLO_DEFAULT 0
#define OSPF_AREA_BACKBONE 0x00000000 /* 0.0.0.0 */
/* SPF Throttling timer values. */
#define OSPF_SPF_DELAY_DEFAULT 200
#define OSPF_SPF_HOLDTIME_DEFAULT 1000
#define OSPF_SPF_MAX_HOLDTIME_DEFAULT 10000
#define OSPF_LSA_MAXAGE_CHECK_INTERVAL 30
#define OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT 60
#endif /* _LIBOSPFD_H */

View File

@@ -0,0 +1,150 @@
/* Generic linked list
* Copyright (C) 1997, 2000 Kunihiro Ishiguro
*
* 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_LINKLIST_H
#define _ZEBRA_LINKLIST_H
/* listnodes must always contain data to be valid. Adding an empty node
* to a list is invalid
*/
struct listnode
{
struct listnode *next;
struct listnode *prev;
/* private member, use getdata() to retrieve, do not access directly */
void *data;
};
struct list
{
struct listnode *head;
struct listnode *tail;
/* invariant: count is the number of listnodes in the list */
unsigned int count;
/*
* Returns -1 if val1 < val2, 0 if equal?, 1 if val1 > val2.
* Used as definition of sorted for listnode_add_sort
*/
int (*cmp) (void *val1, void *val2);
/* callback to free user-owned data when listnode is deleted. supplying
* this callback is very much encouraged!
*/
void (*del) (void *val);
};
#define listnextnode(X) ((X) ? ((X)->next) : NULL)
#define listhead(X) ((X) ? ((X)->head) : NULL)
#define listtail(X) ((X) ? ((X)->tail) : NULL)
#define listcount(X) ((X)->count)
#define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL)
#define listgetdata(X) (assert((X)->data != NULL), (X)->data)
/* Prototypes. */
extern struct list *list_new(void); /* encouraged: set list.del callback on new lists */
extern void list_free (struct list *);
extern void listnode_add (struct list *, void *);
extern void listnode_add_sort (struct list *, void *);
extern void listnode_add_after (struct list *, struct listnode *, void *);
extern void listnode_move_to_tail (struct list *, struct listnode *);
extern void listnode_delete (struct list *, void *);
extern struct listnode *listnode_lookup (struct list *, void *);
extern void *listnode_head (struct list *);
extern void list_delete (struct list *);
extern void list_delete_all_node (struct list *);
/* For ospfd and ospf6d. */
extern void list_delete_node (struct list *, struct listnode *);
/* For ospf_spf.c */
extern void list_add_node_prev (struct list *, struct listnode *, void *);
extern void list_add_node_next (struct list *, struct listnode *, void *);
extern void list_add_list (struct list *, struct list *);
/* List iteration macro.
* Usage: for (ALL_LIST_ELEMENTS (...) { ... }
* It is safe to delete the listnode using this macro.
*/
#define ALL_LIST_ELEMENTS(list,node,nextnode,data) \
(node) = listhead(list), ((data) = NULL); \
(node) != NULL && \
((data) = listgetdata(node),(nextnode) = node->next, 1); \
(node) = (nextnode), ((data) = NULL)
/* read-only list iteration macro.
* Usage: as per ALL_LIST_ELEMENTS, but not safe to delete the listnode Only
* use this macro when it is *immediately obvious* the listnode is not
* deleted in the body of the loop. Does not have forward-reference overhead
* of previous macro.
*/
#define ALL_LIST_ELEMENTS_RO(list,node,data) \
(node) = listhead(list), ((data) = NULL);\
(node) != NULL && ((data) = listgetdata(node), 1); \
(node) = listnextnode(node), ((data) = NULL)
/* these *do not* cleanup list nodes and referenced data, as the functions
* do - these macros simply {de,at}tach a listnode from/to a list.
*/
/* List node attach macro. */
#define LISTNODE_ATTACH(L,N) \
do { \
(N)->prev = (L)->tail; \
(N)->next = NULL; \
if ((L)->head == NULL) \
(L)->head = (N); \
else \
(L)->tail->next = (N); \
(L)->tail = (N); \
(L)->count++; \
} while (0)
/* List node detach macro. */
#define LISTNODE_DETACH(L,N) \
do { \
if ((N)->prev) \
(N)->prev->next = (N)->next; \
else \
(L)->head = (N)->next; \
if ((N)->next) \
(N)->next->prev = (N)->prev; \
else \
(L)->tail = (N)->prev; \
(L)->count--; \
} while (0)
/* Deprecated: 20050406 */
#if !defined(QUAGGA_NO_DEPRECATED_INTERFACES)
#warning "Using deprecated libzebra interfaces"
#define LISTNODE_ADD(L,N) LISTNODE_ATTACH(L,N)
#define LISTNODE_DELETE(L,N) LISTNODE_DETACH(L,N)
#define nextnode(X) ((X) = (X)->next)
#define getdata(X) listgetdata(X)
#define LIST_LOOP(L,V,N) \
for (ALL_LIST_ELEMENTS_RO (L,N,V))
#endif /* QUAGGA_NO_DEPRECATED_INTERFACES */
#endif /* _ZEBRA_LINKLIST_H */

View File

@@ -0,0 +1,236 @@
/*
* Zebra logging funcions.
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
*
* 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_LOG_H
#define _ZEBRA_LOG_H
#include <syslog.h>
/* Here is some guidance on logging levels to use:
*
* LOG_DEBUG - For all messages that are enabled by optional debugging
* features, typically preceded by "if (IS...DEBUG...)"
* LOG_INFO - Information that may be of interest, but everything seems
* to be working properly.
* LOG_NOTICE - Only for message pertaining to daemon startup or shutdown.
* LOG_WARNING - Warning conditions: unexpected events, but the daemon believes
* it can continue to operate correctly.
* LOG_ERR - Error situations indicating malfunctions. Probably require
* attention.
*
* Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere,
* please use LOG_ERR instead.
*/
typedef enum
{
ZLOG_NONE,
ZLOG_DEFAULT,
ZLOG_ZEBRA,
ZLOG_RIP,
ZLOG_BGP,
ZLOG_OSPF,
ZLOG_RIPNG,
ZLOG_BABEL,
ZLOG_OSPF6,
ZLOG_ISIS,
ZLOG_PIM,
ZLOG_MASC
} zlog_proto_t;
/* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
to that logging destination. */
#define ZLOG_DISABLED (LOG_EMERG-1)
typedef enum
{
ZLOG_DEST_SYSLOG = 0,
ZLOG_DEST_STDOUT,
ZLOG_DEST_MONITOR,
ZLOG_DEST_FILE
} zlog_dest_t;
#define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
struct zlog
{
const char *ident; /* daemon name (first arg to openlog) */
zlog_proto_t protocol;
int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated
logging destination */
int default_lvl; /* maxlvl to use if none is specified */
FILE *fp;
char *filename;
int facility; /* as per syslog facility */
int record_priority; /* should messages logged through stdio include the
priority of the message? */
int syslog_options; /* 2nd arg to openlog */
int timestamp_precision; /* # of digits of subsecond precision */
};
/* Message structure. */
struct message
{
int key;
const char *str;
};
/* Default logging strucutre. */
extern struct zlog *zlog_default;
/* Open zlog function */
extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol,
int syslog_options, int syslog_facility);
/* Close zlog function. */
extern void closezlog (struct zlog *zl);
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
#else
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
/* Generic function for zlog. */
extern void zlog (struct zlog *zl, int priority, const char *format, ...)
PRINTF_ATTRIBUTE(3, 4);
/* Handy zlog functions. */
extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
/* For bgpd's peer oriented log. */
extern void plog_err (struct zlog *, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
extern void plog_warn (struct zlog *, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
extern void plog_info (struct zlog *, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
extern void plog_notice (struct zlog *, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
extern void plog_debug (struct zlog *, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
extern void zlog_thread_info (int log_level);
/* Set logging level for the given destination. If the log_level
argument is ZLOG_DISABLED, then the destination is disabled.
This function should not be used for file logging (use zlog_set_file
or zlog_reset_file instead). */
extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level);
/* Set logging to the given filename at the specified level. */
extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level);
/* Disable file logging. */
extern int zlog_reset_file (struct zlog *zl);
/* Rotate log. */
extern int zlog_rotate (struct zlog *);
/* For hackey message lookup and check */
#define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x)
#define LOOKUP(x, y) LOOKUP_DEF(x, y, "(no item found)")
extern const char *lookup (const struct message *, int);
extern const char *mes_lookup (const struct message *meslist,
int max, int index,
const char *no_item, const char *mesname);
extern const char *zlog_priority[];
extern const char *zlog_proto_names[];
/* Safe version of strerror -- never returns NULL. */
extern const char *safe_strerror(int errnum);
/* To be called when a fatal signal is caught. */
extern void zlog_signal(int signo, const char *action
#ifdef SA_SIGINFO
, siginfo_t *siginfo, void *program_counter
#endif
);
/* Log a backtrace. */
extern void zlog_backtrace(int priority);
/* Log a backtrace, but in an async-signal-safe way. Should not be
called unless the program is about to exit or abort, since it messes
up the state of zlog file pointers. If program_counter is non-NULL,
that is logged in addition to the current backtrace. */
extern void zlog_backtrace_sigsafe(int priority, void *program_counter);
/* Puts a current timestamp in buf and returns the number of characters
written (not including the terminating NUL). The purpose of
this function is to avoid calls to localtime appearing all over the code.
It caches the most recent localtime result and can therefore
avoid multiple calls within the same second. If buflen is too small,
*buf will be set to '\0', and 0 will be returned. */
extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */,
char *buf, size_t buflen);
/* structure useful for avoiding repeated rendering of the same timestamp */
struct timestamp_control {
size_t len; /* length of rendered timestamp */
int precision; /* configuration parameter */
int already_rendered; /* should be initialized to 0 */
char buf[40]; /* will contain the rendered timestamp */
};
/* Defines for use in command construction: */
#define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)"
#define LOG_LEVEL_DESC \
"System is unusable\n" \
"Immediate action needed\n" \
"Critical conditions\n" \
"Error conditions\n" \
"Warning conditions\n" \
"Normal but significant conditions\n" \
"Informational messages\n" \
"Debugging messages\n"
#define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)"
#define LOG_FACILITY_DESC \
"Kernel\n" \
"User process\n" \
"Mail system\n" \
"System daemons\n" \
"Authorization system\n" \
"Syslog itself\n" \
"Line printer system\n" \
"USENET news\n" \
"Unix-to-Unix copy system\n" \
"Cron/at facility\n" \
"Local use\n" \
"Local use\n" \
"Local use\n" \
"Local use\n" \
"Local use\n" \
"Local use\n" \
"Local use\n" \
"Local use\n"
#endif /* _ZEBRA_LOG_H */

View File

@@ -0,0 +1,89 @@
/* $USAGI: md5.h,v 1.2 2000/11/02 11:59:25 yoshfuji Exp $ */
/* $KAME: md5.h,v 1.4 2000/03/27 04:36:22 sumikawa Exp $ */
/* $Id: md5.h,v 1.3 2006/01/17 17:40:45 paul Exp $ */
/*
* Copyright (C) 2004 6WIND
* <Vincent.Jardin@6WIND.com>
* All rights reserved.
*
* This MD5 code is Big endian and Little Endian compatible.
*/
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _LIBZEBRA_MD5_H_
#define _LIBZEBRA_MD5_H_
#define MD5_BUFLEN 64
typedef struct {
union {
uint32_t md5_state32[4];
uint8_t md5_state8[16];
} md5_st;
#define md5_sta md5_st.md5_state32[0]
#define md5_stb md5_st.md5_state32[1]
#define md5_stc md5_st.md5_state32[2]
#define md5_std md5_st.md5_state32[3]
#define md5_st8 md5_st.md5_state8
union {
uint64_t md5_count64;
uint8_t md5_count8[8];
} md5_count;
#define md5_n md5_count.md5_count64
#define md5_n8 md5_count.md5_count8
uint md5_i;
uint8_t md5_buf[MD5_BUFLEN];
} md5_ctxt;
extern void md5_init (md5_ctxt *);
extern void md5_loop (md5_ctxt *, const void *, u_int);
extern void md5_pad (md5_ctxt *);
extern void md5_result (uint8_t *, md5_ctxt *);
/* compatibility */
#define MD5_CTX md5_ctxt
#define MD5Init(x) md5_init((x))
#define MD5Update(x, y, z) md5_loop((x), (y), (z))
#define MD5Final(x, y) \
do { \
md5_pad((y)); \
md5_result((x), (y)); \
} while (0)
/* From RFC 2104 */
void hmac_md5(unsigned char* text, int text_len, unsigned char* key,
int key_len, uint8_t *digest);
#endif /* ! _LIBZEBRA_MD5_H_*/

View File

@@ -0,0 +1,96 @@
/* Memory management routine
Copyright (C) 1998 Kunihiro Ishiguro
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_MEMORY_H
#define _ZEBRA_MEMORY_H
#define array_size(ar) (sizeof(ar) / sizeof(ar[0]))
/* For pretty printing of memory allocate information. */
struct memory_list
{
int index;
const char *format;
};
struct mlist {
struct memory_list *list;
const char *name;
};
#include "lib/memtypes.h"
extern struct mlist mlists[];
/* #define MEMORY_LOG */
#ifdef MEMORY_LOG
#define XMALLOC(mtype, size) \
mtype_zmalloc (__FILE__, __LINE__, (mtype), (size))
#define XCALLOC(mtype, size) \
mtype_zcalloc (__FILE__, __LINE__, (mtype), (size))
#define XREALLOC(mtype, ptr, size) \
mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size))
#define XFREE(mtype, ptr) \
do { \
mtype_zfree (__FILE__, __LINE__, (mtype), (ptr)); \
ptr = NULL; } \
while (0)
#define XSTRDUP(mtype, str) \
mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
#else
#define XMALLOC(mtype, size) zmalloc ((mtype), (size))
#define XCALLOC(mtype, size) zcalloc ((mtype), (size))
#define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
#define XFREE(mtype, ptr) do { \
zfree ((mtype), (ptr)); \
ptr = NULL; } \
while (0)
#define XSTRDUP(mtype, str) zstrdup ((mtype), (str))
#endif /* MEMORY_LOG */
/* Prototypes of memory function. */
extern void *zmalloc (int type, size_t size);
extern void *zcalloc (int type, size_t size);
extern void *zrealloc (int type, void *ptr, size_t size);
extern void zfree (int type, void *ptr);
extern char *zstrdup (int type, const char *str);
extern void *mtype_zmalloc (const char *file, int line, int type, size_t size);
extern void *mtype_zcalloc (const char *file, int line, int type, size_t size);
extern void *mtype_zrealloc (const char *file, int line, int type, void *ptr,
size_t size);
extern void mtype_zfree (const char *file, int line, int type,
void *ptr);
extern char *mtype_zstrdup (const char *file, int line, int type,
const char *str);
extern void memory_init (void);
extern void log_memstats_stderr (const char *);
/* return number of allocations outstanding for the type */
extern unsigned long mtype_stats_alloc (int);
/* Human friendly string for given byte count */
#define MTYPE_MEMSTR_LEN 20
extern const char *mtype_memstr (char *, size_t, unsigned long);
#endif /* _ZEBRA_MEMORY_H */

View File

@@ -0,0 +1,228 @@
/* Auto-generated from memtypes.c by gawk. */
/* Do not edit! */
#ifndef _QUAGGA_MEMTYPES_H
#define _QUAGGA_MEMTYPES_H
enum
{
MTYPE_TMP = 1,
MTYPE_STRVEC,
MTYPE_VECTOR,
MTYPE_VECTOR_INDEX,
MTYPE_LINK_LIST,
MTYPE_LINK_NODE,
MTYPE_THREAD,
MTYPE_THREAD_MASTER,
MTYPE_THREAD_STATS,
MTYPE_VTY,
MTYPE_VTY_OUT_BUF,
MTYPE_VTY_HIST,
MTYPE_IF,
MTYPE_CONNECTED,
MTYPE_CONNECTED_LABEL,
MTYPE_BUFFER,
MTYPE_BUFFER_DATA,
MTYPE_STREAM,
MTYPE_STREAM_DATA,
MTYPE_STREAM_FIFO,
MTYPE_PREFIX,
MTYPE_PREFIX_IPV4,
MTYPE_PREFIX_IPV6,
MTYPE_HASH,
MTYPE_HASH_BACKET,
MTYPE_HASH_INDEX,
MTYPE_ROUTE_TABLE,
MTYPE_ROUTE_NODE,
MTYPE_DISTRIBUTE,
MTYPE_DISTRIBUTE_IFNAME,
MTYPE_ACCESS_LIST,
MTYPE_ACCESS_LIST_STR,
MTYPE_ACCESS_FILTER,
MTYPE_PREFIX_LIST,
MTYPE_PREFIX_LIST_ENTRY,
MTYPE_PREFIX_LIST_STR,
MTYPE_ROUTE_MAP,
MTYPE_ROUTE_MAP_NAME,
MTYPE_ROUTE_MAP_INDEX,
MTYPE_ROUTE_MAP_RULE,
MTYPE_ROUTE_MAP_RULE_STR,
MTYPE_ROUTE_MAP_COMPILED,
MTYPE_CMD_TOKENS,
MTYPE_KEY,
MTYPE_KEYCHAIN,
MTYPE_IF_RMAP,
MTYPE_IF_RMAP_NAME,
MTYPE_SOCKUNION,
MTYPE_PRIVS,
MTYPE_ZLOG,
MTYPE_ZCLIENT,
MTYPE_WORK_QUEUE,
MTYPE_WORK_QUEUE_ITEM,
MTYPE_WORK_QUEUE_NAME,
MTYPE_PQUEUE,
MTYPE_PQUEUE_DATA,
MTYPE_HOST,
MTYPE_RTADV_PREFIX,
MTYPE_VRF,
MTYPE_VRF_NAME,
MTYPE_NEXTHOP,
MTYPE_RIB,
MTYPE_RIB_QUEUE,
MTYPE_STATIC_IPV4,
MTYPE_STATIC_IPV6,
MTYPE_RIB_DEST,
MTYPE_RIB_TABLE_INFO,
MTYPE_BGP,
MTYPE_BGP_LISTENER,
MTYPE_BGP_PEER,
MTYPE_BGP_PEER_HOST,
MTYPE_PEER_GROUP,
MTYPE_PEER_DESC,
MTYPE_PEER_PASSWORD,
MTYPE_ATTR,
MTYPE_ATTR_EXTRA,
MTYPE_AS_PATH,
MTYPE_AS_SEG,
MTYPE_AS_SEG_DATA,
MTYPE_AS_STR,
MTYPE_BGP_TABLE,
MTYPE_BGP_NODE,
MTYPE_BGP_ROUTE,
MTYPE_BGP_ROUTE_EXTRA,
MTYPE_BGP_CONN,
MTYPE_BGP_STATIC,
MTYPE_BGP_ADVERTISE_ATTR,
MTYPE_BGP_ADVERTISE,
MTYPE_BGP_SYNCHRONISE,
MTYPE_BGP_ADJ_IN,
MTYPE_BGP_ADJ_OUT,
MTYPE_BGP_MPATH_INFO,
MTYPE_AS_LIST,
MTYPE_AS_FILTER,
MTYPE_AS_FILTER_STR,
MTYPE_COMMUNITY,
MTYPE_COMMUNITY_VAL,
MTYPE_COMMUNITY_STR,
MTYPE_ECOMMUNITY,
MTYPE_ECOMMUNITY_VAL,
MTYPE_ECOMMUNITY_STR,
MTYPE_COMMUNITY_LIST,
MTYPE_COMMUNITY_LIST_NAME,
MTYPE_COMMUNITY_LIST_ENTRY,
MTYPE_COMMUNITY_LIST_CONFIG,
MTYPE_COMMUNITY_LIST_HANDLER,
MTYPE_CLUSTER,
MTYPE_CLUSTER_VAL,
MTYPE_BGP_PROCESS_QUEUE,
MTYPE_BGP_CLEAR_NODE_QUEUE,
MTYPE_TRANSIT,
MTYPE_TRANSIT_VAL,
MTYPE_BGP_DISTANCE,
MTYPE_BGP_NEXTHOP_CACHE,
MTYPE_BGP_CONFED_LIST,
MTYPE_PEER_UPDATE_SOURCE,
MTYPE_BGP_DAMP_INFO,
MTYPE_BGP_DAMP_ARRAY,
MTYPE_BGP_REGEXP,
MTYPE_BGP_AGGREGATE,
MTYPE_BGP_ADDR,
MTYPE_RIP,
MTYPE_RIP_INFO,
MTYPE_RIP_INTERFACE,
MTYPE_RIP_PEER,
MTYPE_RIP_OFFSET_LIST,
MTYPE_RIP_DISTANCE,
MTYPE_RIPNG,
MTYPE_RIPNG_ROUTE,
MTYPE_RIPNG_AGGREGATE,
MTYPE_RIPNG_PEER,
MTYPE_RIPNG_OFFSET_LIST,
MTYPE_RIPNG_RTE_DATA,
MTYPE_BABEL,
MTYPE_BABEL_IF,
MTYPE_OSPF_TOP,
MTYPE_OSPF_AREA,
MTYPE_OSPF_AREA_RANGE,
MTYPE_OSPF_NETWORK,
MTYPE_OSPF_NEIGHBOR_STATIC,
MTYPE_OSPF_IF,
MTYPE_OSPF_NEIGHBOR,
MTYPE_OSPF_ROUTE,
MTYPE_OSPF_TMP,
MTYPE_OSPF_LSA,
MTYPE_OSPF_LSA_DATA,
MTYPE_OSPF_LSDB,
MTYPE_OSPF_PACKET,
MTYPE_OSPF_FIFO,
MTYPE_OSPF_VERTEX,
MTYPE_OSPF_VERTEX_PARENT,
MTYPE_OSPF_NEXTHOP,
MTYPE_OSPF_PATH,
MTYPE_OSPF_VL_DATA,
MTYPE_OSPF_CRYPT_KEY,
MTYPE_OSPF_EXTERNAL_INFO,
MTYPE_OSPF_DISTANCE,
MTYPE_OSPF_IF_INFO,
MTYPE_OSPF_IF_PARAMS,
MTYPE_OSPF_MESSAGE,
MTYPE_OSPF6_TOP,
MTYPE_OSPF6_AREA,
MTYPE_OSPF6_IF,
MTYPE_OSPF6_NEIGHBOR,
MTYPE_OSPF6_ROUTE,
MTYPE_OSPF6_PREFIX,
MTYPE_OSPF6_MESSAGE,
MTYPE_OSPF6_LSA,
MTYPE_OSPF6_LSA_SUMMARY,
MTYPE_OSPF6_LSDB,
MTYPE_OSPF6_VERTEX,
MTYPE_OSPF6_SPFTREE,
MTYPE_OSPF6_NEXTHOP,
MTYPE_OSPF6_EXTERNAL_INFO,
MTYPE_OSPF6_OTHER,
MTYPE_ISIS,
MTYPE_ISIS_TMP,
MTYPE_ISIS_CIRCUIT,
MTYPE_ISIS_LSP,
MTYPE_ISIS_ADJACENCY,
MTYPE_ISIS_AREA,
MTYPE_ISIS_AREA_ADDR,
MTYPE_ISIS_TLV,
MTYPE_ISIS_DYNHN,
MTYPE_ISIS_SPFTREE,
MTYPE_ISIS_VERTEX,
MTYPE_ISIS_ROUTE_INFO,
MTYPE_ISIS_NEXTHOP,
MTYPE_ISIS_NEXTHOP6,
MTYPE_ISIS_DICT,
MTYPE_ISIS_DICT_NODE,
MTYPE_PIM_CHANNEL_OIL,
MTYPE_PIM_INTERFACE,
MTYPE_PIM_IGMP_JOIN,
MTYPE_PIM_IGMP_SOCKET,
MTYPE_PIM_IGMP_GROUP,
MTYPE_PIM_IGMP_GROUP_SOURCE,
MTYPE_PIM_NEIGHBOR,
MTYPE_PIM_IFCHANNEL,
MTYPE_PIM_UPSTREAM,
MTYPE_PIM_SSMPINGD,
MTYPE_VTYSH_CONFIG,
MTYPE_VTYSH_CONFIG_LINE,
MTYPE_MAX,
};
extern struct memory_list memory_list_lib[];
extern struct memory_list memory_list_zebra[];
extern struct memory_list memory_list_bgp[];
extern struct memory_list memory_list_rip[];
extern struct memory_list memory_list_ripng[];
extern struct memory_list memory_list_babel[];
extern struct memory_list memory_list_ospf[];
extern struct memory_list memory_list_ospf6[];
extern struct memory_list memory_list_isis[];
extern struct memory_list memory_list_pim[];
extern struct memory_list memory_list_vtysh[];
#endif /* _QUAGGA_MEMTYPES_H */

View File

@@ -0,0 +1,40 @@
/*
* Network library header.
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_NETWORK_H
#define _ZEBRA_NETWORK_H
/* Both readn and writen are deprecated and will be removed. They are not
suitable for use with non-blocking file descriptors.
*/
extern int readn (int, u_char *, int);
extern int writen (int, const u_char *, int);
/* Set the file descriptor to use non-blocking I/O. Returns 0 for success,
-1 on error. */
extern int set_nonblocking(int fd);
/* Does the I/O error indicate that the operation should be retried later? */
#define ERRNO_IO_RETRY(EN) \
(((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
#endif /* _ZEBRA_NETWORK_H */

View File

@@ -0,0 +1,135 @@
/*
* Client side of OSPF API.
* Copyright (C) 2001, 2002, 2003 Ralph Keller
*
* 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 _OSPF_APICLIENT_H
#define _OSPF_APICLIENT_H
#define MTYPE_OSPF_APICLIENT 0
/* Structure for the OSPF API client */
struct ospf_apiclient
{
/* Sockets for sync requests and async notifications */
int fd_sync;
int fd_async;
/* Pointer to callback functions */
void (*ready_notify) (u_char lsa_type, u_char opaque_type,
struct in_addr addr);
void (*new_if) (struct in_addr ifaddr, struct in_addr area_id);
void (*del_if) (struct in_addr ifaddr);
void (*ism_change) (struct in_addr ifaddr, struct in_addr area_id,
u_char status);
void (*nsm_change) (struct in_addr ifaddr, struct in_addr nbraddr,
struct in_addr router_id, u_char status);
void (*update_notify) (struct in_addr ifaddr, struct in_addr area_id,
u_char self_origin,
struct lsa_header * lsa);
void (*delete_notify) (struct in_addr ifaddr, struct in_addr area_id,
u_char self_origin,
struct lsa_header * lsa);
};
/* ---------------------------------------------------------
* API function prototypes.
* --------------------------------------------------------- */
/* Open connection to OSPF daemon. Two ports will be allocated on
client, sync channel at syncport and reverse channel at syncport+1 */
struct ospf_apiclient *ospf_apiclient_connect (char *host, int syncport);
/* Shutdown connection to OSPF daemon. */
int ospf_apiclient_close (struct ospf_apiclient *oclient);
/* Synchronous request to register opaque type. */
int ospf_apiclient_register_opaque_type (struct ospf_apiclient *oclient,
u_char ltype, u_char otype);
/* Synchronous request to register event mask. */
int ospf_apiclient_register_events (struct ospf_apiclient *oclient,
u_int32_t mask);
/* Register callback functions.*/
void ospf_apiclient_register_callback (struct ospf_apiclient *oclient,
void (*ready_notify) (u_char lsa_type,
u_char
opaque_type,
struct in_addr
addr),
void (*new_if) (struct in_addr ifaddr,
struct in_addr
area_id),
void (*del_if) (struct in_addr ifaddr),
void (*ism_change) (struct in_addr
ifaddr,
struct in_addr
area_id,
u_char status),
void (*nsm_change) (struct in_addr
ifaddr,
struct in_addr
nbraddr,
struct in_addr
router_id,
u_char status),
void (*update_notify) (struct in_addr
ifaddr,
struct in_addr
area_id,
u_char selforig,
struct
lsa_header *
lsa),
void (*delete_notify) (struct in_addr
ifaddr,
struct in_addr
area_id,
u_char selforig,
struct
lsa_header *
lsa));
/* Synchronous request to synchronize LSDB. */
int ospf_apiclient_sync_lsdb (struct ospf_apiclient *oclient);
/* Synchronous request to originate or update opaque LSA. */
int
ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient,
struct in_addr ifaddr,
struct in_addr area_id,
u_char lsa_type,
u_char opaque_type, u_int32_t opaque_id,
void *opaquedata, int opaquelen);
/* Synchronous request to delete opaque LSA. Parameter opaque_id is in
host byte order */
int ospf_apiclient_lsa_delete (struct ospf_apiclient *oclient,
struct in_addr area_id, u_char lsa_type,
u_char opaque_type, u_int32_t opaque_id);
/* Fetch async message and handle it */
int ospf_apiclient_handle_async (struct ospf_apiclient *oclient);
#endif /* _OSPF_APICLIENT_H */

View File

@@ -0,0 +1,361 @@
/*
* API message handling module for OSPF daemon and client.
* Copyright (C) 2001, 2002 Ralph Keller
*
* 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.
*/
/* This file is used both by the OSPFd and client applications to
define message formats used for communication. */
#ifndef _OSPF_API_H
#define _OSPF_API_H
#define OSPF_API_VERSION 1
/* MTYPE definition is not reflected to "memory.h". */
#define MTYPE_OSPF_API_MSG MTYPE_TMP
#define MTYPE_OSPF_API_FIFO MTYPE_TMP
/* Default API server port to accept connection request from client-side. */
/* This value could be overridden by "ospfapi" entry in "/etc/services". */
#define OSPF_API_SYNC_PORT 2607
/* -----------------------------------------------------------
* Generic messages
* -----------------------------------------------------------
*/
/* Message header structure, fields are in network byte order and
aligned to four octets. */
struct apimsghdr
{
u_char version; /* OSPF API protocol version */
u_char msgtype; /* Type of message */
u_int16_t msglen; /* Length of message w/o header */
u_int32_t msgseq; /* Sequence number */
};
/* Message representation with header and body */
struct msg
{
struct msg *next; /* to link into fifo */
/* Message header */
struct apimsghdr hdr;
/* Message body */
struct stream *s;
};
/* Prototypes for generic messages. */
extern struct msg *msg_new (u_char msgtype, void *msgbody,
u_int32_t seqnum, u_int16_t msglen);
extern struct msg *msg_dup (struct msg *msg);
extern void msg_print (struct msg *msg); /* XXX debug only */
extern void msg_free (struct msg *msg);
struct msg *msg_read (int fd);
extern int msg_write (int fd, struct msg *msg);
/* For requests, the message sequence number is between MIN_SEQ and
MAX_SEQ. For notifications, the sequence number is 0. */
#define MIN_SEQ 1
#define MAX_SEQ 2147483647
extern void msg_set_seq (struct msg *msg, u_int32_t seqnr);
extern u_int32_t msg_get_seq (struct msg *msg);
/* -----------------------------------------------------------
* Message fifo queues
* -----------------------------------------------------------
*/
/* Message queue structure. */
struct msg_fifo
{
unsigned long count;
struct msg *head;
struct msg *tail;
};
/* Prototype for message fifo queues. */
extern struct msg_fifo *msg_fifo_new (void);
extern void msg_fifo_push (struct msg_fifo *, struct msg *msg);
extern struct msg *msg_fifo_pop (struct msg_fifo *fifo);
extern struct msg *msg_fifo_head (struct msg_fifo *fifo);
extern void msg_fifo_flush (struct msg_fifo *fifo);
extern void msg_fifo_free (struct msg_fifo *fifo);
/* -----------------------------------------------------------
* Specific message type and format definitions
* -----------------------------------------------------------
*/
/* Messages to OSPF daemon. */
#define MSG_REGISTER_OPAQUETYPE 1
#define MSG_UNREGISTER_OPAQUETYPE 2
#define MSG_REGISTER_EVENT 3
#define MSG_SYNC_LSDB 4
#define MSG_ORIGINATE_REQUEST 5
#define MSG_DELETE_REQUEST 6
/* Messages from OSPF daemon. */
#define MSG_REPLY 10
#define MSG_READY_NOTIFY 11
#define MSG_LSA_UPDATE_NOTIFY 12
#define MSG_LSA_DELETE_NOTIFY 13
#define MSG_NEW_IF 14
#define MSG_DEL_IF 15
#define MSG_ISM_CHANGE 16
#define MSG_NSM_CHANGE 17
struct msg_register_opaque_type
{
u_char lsatype;
u_char opaquetype;
u_char pad[2]; /* padding */
};
struct msg_unregister_opaque_type
{
u_char lsatype;
u_char opaquetype;
u_char pad[2]; /* padding */
};
/* Power2 is needed to convert LSA types into bit positions,
* see typemask below. Type definition starts at 1, so
* Power2[0] is not used. */
#ifdef ORIGINAL_CODING
static const u_int16_t
Power2[] = { 0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80,
0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000
};
#else
static const u_int16_t
Power2[] = { 0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4),
(1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9),
(1 << 10), (1 << 11), (1 << 12), (1 << 13), (1 << 14),
(1 << 15)
};
#endif /* ORIGINAL_CODING */
struct lsa_filter_type
{
u_int16_t typemask; /* bitmask for selecting LSA types (1..16) */
u_char origin; /* selects according to origin. */
#define NON_SELF_ORIGINATED 0
#define SELF_ORIGINATED (OSPF_LSA_SELF)
#define ANY_ORIGIN 2
u_char num_areas; /* number of areas in the filter. */
/* areas, if any, go here. */
};
struct msg_register_event
{
struct lsa_filter_type filter;
};
struct msg_sync_lsdb
{
struct lsa_filter_type filter;
};
struct msg_originate_request
{
/* Used for LSA type 9 otherwise ignored */
struct in_addr ifaddr;
/* Used for LSA type 10 otherwise ignored */
struct in_addr area_id;
/* LSA header and LSA-specific part */
struct lsa_header data;
};
struct msg_delete_request
{
struct in_addr area_id; /* "0.0.0.0" for AS-external opaque LSAs */
u_char lsa_type;
u_char opaque_type;
u_char pad[2]; /* padding */
u_int32_t opaque_id;
};
struct msg_reply
{
signed char errcode;
#define OSPF_API_OK 0
#define OSPF_API_NOSUCHINTERFACE (-1)
#define OSPF_API_NOSUCHAREA (-2)
#define OSPF_API_NOSUCHLSA (-3)
#define OSPF_API_ILLEGALLSATYPE (-4)
#define OSPF_API_OPAQUETYPEINUSE (-5)
#define OSPF_API_OPAQUETYPENOTREGISTERED (-6)
#define OSPF_API_NOTREADY (-7)
#define OSPF_API_NOMEMORY (-8)
#define OSPF_API_ERROR (-9)
#define OSPF_API_UNDEF (-10)
u_char pad[3]; /* padding to four byte alignment */
};
/* Message to tell client application that it ospf daemon is
* ready to accept opaque LSAs for a given interface or area. */
struct msg_ready_notify
{
u_char lsa_type;
u_char opaque_type;
u_char pad[2]; /* padding */
struct in_addr addr; /* interface address or area address */
};
/* These messages have a dynamic length depending on the embodied LSA.
They are aligned to four octets. msg_lsa_change_notify is used for
both LSA update and LSAs delete. */
struct msg_lsa_change_notify
{
/* Used for LSA type 9 otherwise ignored */
struct in_addr ifaddr;
/* Area ID. Not valid for AS-External and Opaque11 LSAs. */
struct in_addr area_id;
u_char is_self_originated; /* 1 if self originated. */
u_char pad[3];
struct lsa_header data;
};
struct msg_new_if
{
struct in_addr ifaddr; /* interface IP address */
struct in_addr area_id; /* area this interface belongs to */
};
struct msg_del_if
{
struct in_addr ifaddr; /* interface IP address */
};
struct msg_ism_change
{
struct in_addr ifaddr; /* interface IP address */
struct in_addr area_id; /* area this interface belongs to */
u_char status; /* interface status (up/down) */
u_char pad[3]; /* not used */
};
struct msg_nsm_change
{
struct in_addr ifaddr; /* attached interface */
struct in_addr nbraddr; /* Neighbor interface address */
struct in_addr router_id; /* Router ID of neighbor */
u_char status; /* NSM status */
u_char pad[3];
};
/* We make use of a union to define a structure that covers all
possible API messages. This allows us to find out how much memory
needs to be reserved for the largest API message. */
struct apimsg
{
struct apimsghdr hdr;
union
{
struct msg_register_opaque_type register_opaque_type;
struct msg_register_event register_event;
struct msg_sync_lsdb sync_lsdb;
struct msg_originate_request originate_request;
struct msg_delete_request delete_request;
struct msg_reply reply;
struct msg_ready_notify ready_notify;
struct msg_new_if new_if;
struct msg_del_if del_if;
struct msg_ism_change ism_change;
struct msg_nsm_change nsm_change;
struct msg_lsa_change_notify lsa_change_notify;
}
u;
};
#define OSPF_API_MAX_MSG_SIZE (sizeof(struct apimsg) + OSPF_MAX_LSA_SIZE)
/* -----------------------------------------------------------
* Prototypes for specific messages
* -----------------------------------------------------------
*/
/* For debugging only. */
extern void api_opaque_lsa_print (struct lsa_header *data);
/* Messages sent by client */
extern struct msg *new_msg_register_opaque_type (u_int32_t seqnum,
u_char ltype, u_char otype);
extern struct msg *new_msg_register_event (u_int32_t seqnum,
struct lsa_filter_type *filter);
extern struct msg *new_msg_sync_lsdb (u_int32_t seqnum,
struct lsa_filter_type *filter);
extern struct msg *new_msg_originate_request (u_int32_t seqnum,
struct in_addr ifaddr,
struct in_addr area_id,
struct lsa_header *data);
extern struct msg *new_msg_delete_request (u_int32_t seqnum,
struct in_addr area_id,
u_char lsa_type,
u_char opaque_type,
u_int32_t opaque_id);
/* Messages sent by OSPF daemon */
extern struct msg *new_msg_reply (u_int32_t seqnum, u_char rc);
extern struct msg *new_msg_ready_notify (u_int32_t seqnr, u_char lsa_type,
u_char opaque_type,
struct in_addr addr);
extern struct msg *new_msg_new_if (u_int32_t seqnr,
struct in_addr ifaddr,
struct in_addr area);
extern struct msg *new_msg_del_if (u_int32_t seqnr, struct in_addr ifaddr);
extern struct msg *new_msg_ism_change (u_int32_t seqnr, struct in_addr ifaddr,
struct in_addr area, u_char status);
extern struct msg *new_msg_nsm_change (u_int32_t seqnr, struct in_addr ifaddr,
struct in_addr nbraddr,
struct in_addr router_id,
u_char status);
/* msgtype is MSG_LSA_UPDATE_NOTIFY or MSG_LSA_DELETE_NOTIFY */
extern struct msg *new_msg_lsa_change_notify (u_char msgtype,
u_int32_t seqnum,
struct in_addr ifaddr,
struct in_addr area_id,
u_char is_self_originated,
struct lsa_header *data);
/* string printing functions */
extern const char *ospf_api_errname (int errcode);
extern const char *ospf_api_typename (int msgtype);
#endif /* _OSPF_API_H */

View File

@@ -0,0 +1,80 @@
/*
* OSPF AS Boundary Router functions.
* Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada
*
* 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_OSPF_ASBR_H
#define _ZEBRA_OSPF_ASBR_H
struct route_map_set_values
{
int32_t metric;
int32_t metric_type;
};
/* Redistributed external information. */
struct external_info
{
/* Type of source protocol. */
u_char type;
/* Prefix. */
struct prefix_ipv4 p;
/* Interface index. */
unsigned int ifindex;
/* Nexthop address. */
struct in_addr nexthop;
/* Additional Route tag. */
u_int32_t tag;
struct route_map_set_values route_map_set;
#define ROUTEMAP_METRIC(E) (E)->route_map_set.metric
#define ROUTEMAP_METRIC_TYPE(E) (E)->route_map_set.metric_type
};
#define OSPF_ASBR_CHECK_DELAY 30
extern void ospf_external_route_remove (struct ospf *, struct prefix_ipv4 *);
extern struct external_info *ospf_external_info_new (u_char);
extern void ospf_reset_route_map_set_values (struct route_map_set_values *);
extern int ospf_route_map_set_compare (struct route_map_set_values *,
struct route_map_set_values *);
extern struct external_info *ospf_external_info_add (u_char,
struct prefix_ipv4,
unsigned int,
struct in_addr);
extern void ospf_external_info_delete (u_char, struct prefix_ipv4);
extern struct external_info *ospf_external_info_lookup (u_char,
struct prefix_ipv4 *);
extern struct ospf_route *ospf_external_route_lookup (struct ospf *,
struct prefix_ipv4 *);
extern void ospf_asbr_status_update (struct ospf *, u_char);
extern void ospf_redistribute_withdraw (struct ospf *, u_char);
extern void ospf_asbr_check (void);
extern void ospf_schedule_asbr_check (void);
extern void ospf_asbr_route_install_lsa (struct ospf_lsa *);
extern struct ospf_lsa *ospf_external_info_find_lsa (struct ospf *,
struct prefix_ipv4 *p);
#endif /* _ZEBRA_OSPF_ASBR_H */

View File

@@ -0,0 +1,144 @@
/*
* OSPFd dump routine.
* Copyright (C) 1999 Toshiaki Takada
*
* 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_OSPF_DUMP_H
#define _ZEBRA_OSPF_DUMP_H
/* Debug Flags. */
#define OSPF_DEBUG_HELLO 0x01
#define OSPF_DEBUG_DB_DESC 0x02
#define OSPF_DEBUG_LS_REQ 0x04
#define OSPF_DEBUG_LS_UPD 0x08
#define OSPF_DEBUG_LS_ACK 0x10
#define OSPF_DEBUG_ALL 0x1f
#define OSPF_DEBUG_SEND 0x01
#define OSPF_DEBUG_RECV 0x02
#define OSPF_DEBUG_SEND_RECV 0x03
#define OSPF_DEBUG_DETAIL 0x04
#define OSPF_DEBUG_ISM_STATUS 0x01
#define OSPF_DEBUG_ISM_EVENTS 0x02
#define OSPF_DEBUG_ISM_TIMERS 0x04
#define OSPF_DEBUG_ISM 0x07
#define OSPF_DEBUG_NSM_STATUS 0x01
#define OSPF_DEBUG_NSM_EVENTS 0x02
#define OSPF_DEBUG_NSM_TIMERS 0x04
#define OSPF_DEBUG_NSM 0x07
#define OSPF_DEBUG_LSA_GENERATE 0x01
#define OSPF_DEBUG_LSA_FLOODING 0x02
#define OSPF_DEBUG_LSA_INSTALL 0x04
#define OSPF_DEBUG_LSA_REFRESH 0x08
#define OSPF_DEBUG_LSA 0x0F
#define OSPF_DEBUG_ZEBRA_INTERFACE 0x01
#define OSPF_DEBUG_ZEBRA_REDISTRIBUTE 0x02
#define OSPF_DEBUG_ZEBRA 0x03
#define OSPF_DEBUG_EVENT 0x01
#define OSPF_DEBUG_NSSA 0x02
/* Macro for setting debug option. */
#define CONF_DEBUG_PACKET_ON(a, b) conf_debug_ospf_packet[a] |= (b)
#define CONF_DEBUG_PACKET_OFF(a, b) conf_debug_ospf_packet[a] &= ~(b)
#define TERM_DEBUG_PACKET_ON(a, b) term_debug_ospf_packet[a] |= (b)
#define TERM_DEBUG_PACKET_OFF(a, b) term_debug_ospf_packet[a] &= ~(b)
#define DEBUG_PACKET_ON(a, b) \
do { \
CONF_DEBUG_PACKET_ON(a, b); \
TERM_DEBUG_PACKET_ON(a, b); \
} while (0)
#define DEBUG_PACKET_OFF(a, b) \
do { \
CONF_DEBUG_PACKET_OFF(a, b); \
TERM_DEBUG_PACKET_OFF(a, b); \
} while (0)
#define CONF_DEBUG_ON(a, b) conf_debug_ospf_ ## a |= (OSPF_DEBUG_ ## b)
#define CONF_DEBUG_OFF(a, b) conf_debug_ospf_ ## a &= ~(OSPF_DEBUG_ ## b)
#define TERM_DEBUG_ON(a, b) term_debug_ospf_ ## a |= (OSPF_DEBUG_ ## b)
#define TERM_DEBUG_OFF(a, b) term_debug_ospf_ ## a &= ~(OSPF_DEBUG_ ## b)
#define DEBUG_ON(a, b) \
do { \
CONF_DEBUG_ON(a, b); \
TERM_DEBUG_ON(a, b); \
} while (0)
#define DEBUG_OFF(a, b) \
do { \
CONF_DEBUG_OFF(a, b); \
TERM_DEBUG_OFF(a, b); \
} while (0)
/* Macro for checking debug option. */
#define IS_DEBUG_OSPF_PACKET(a, b) \
(term_debug_ospf_packet[a] & OSPF_DEBUG_ ## b)
#define IS_DEBUG_OSPF(a, b) \
(term_debug_ospf_ ## a & OSPF_DEBUG_ ## b)
#define IS_DEBUG_OSPF_EVENT IS_DEBUG_OSPF(event,EVENT)
#define IS_DEBUG_OSPF_NSSA IS_DEBUG_OSPF(nssa,NSSA)
#define IS_CONF_DEBUG_OSPF_PACKET(a, b) \
(conf_debug_ospf_packet[a] & OSPF_DEBUG_ ## b)
#define IS_CONF_DEBUG_OSPF(a, b) \
(conf_debug_ospf_ ## a & OSPF_DEBUG_ ## b)
#ifdef ORIGINAL_CODING
#else /* ORIGINAL_CODING */
struct stream;
#endif /* ORIGINAL_CODING */
#define AREA_NAME(A) ospf_area_name_string ((A))
#define IF_NAME(I) ospf_if_name_string ((I))
/* Extern debug flag. */
extern unsigned long term_debug_ospf_packet[];
extern unsigned long term_debug_ospf_event;
extern unsigned long term_debug_ospf_ism;
extern unsigned long term_debug_ospf_nsm;
extern unsigned long term_debug_ospf_lsa;
extern unsigned long term_debug_ospf_zebra;
extern unsigned long term_debug_ospf_nssa;
/* Message Strings. */
extern char *ospf_lsa_type_str[];
extern const struct message ospf_auth_type_str[];
extern const size_t ospf_auth_type_str_max;
/* Prototypes. */
extern const char *ospf_area_name_string (struct ospf_area *);
extern const char *ospf_area_desc_string (struct ospf_area *);
extern const char *ospf_if_name_string (struct ospf_interface *);
extern void ospf_nbr_state_message (struct ospf_neighbor *, char *, size_t);
extern char *ospf_options_dump (u_char);
extern const char *ospf_timer_dump (struct thread *, char *, size_t);
extern const char *ospf_timeval_dump (struct timeval *, char *, size_t);
extern void ospf_ip_header_dump (struct ip *);
extern void ospf_packet_dump (struct stream *);
extern void ospf_lsa_header_dump (struct lsa_header *);
extern void debug_init (void);
/* Appropriate buffer size to use with ospf_timer_dump and ospf_timeval_dump: */
#define OSPF_TIME_DUMP_SIZE 16
#endif /* _ZEBRA_OSPF_DUMP_H */

View File

@@ -0,0 +1,114 @@
/*
* OSPF version 2 Interface State Machine.
* From RFC2328 [OSPF Version 2]
* Copyright (C) 1999 Toshiaki Takada
*
* 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_OSPF_ISM_H
#define _ZEBRA_OSPF_ISM_H
/* OSPF Interface State Machine Status. */
#define ISM_DependUpon 0
#define ISM_Down 1
#define ISM_Loopback 2
#define ISM_Waiting 3
#define ISM_PointToPoint 4
#define ISM_DROther 5
#define ISM_Backup 6
#define ISM_DR 7
#define OSPF_ISM_STATE_MAX 8
/* Because DR/DROther values are exhanged wrt RFC */
#define ISM_SNMP(x) (((x) == ISM_DROther) ? ISM_DR : \
((x) == ISM_DR) ? ISM_DROther : (x))
/* OSPF Interface State Machine Event. */
#define ISM_NoEvent 0
#define ISM_InterfaceUp 1
#define ISM_WaitTimer 2
#define ISM_BackupSeen 3
#define ISM_NeighborChange 4
#define ISM_LoopInd 5
#define ISM_UnloopInd 6
#define ISM_InterfaceDown 7
#define OSPF_ISM_EVENT_MAX 8
#define OSPF_ISM_WRITE_ON(O) \
do \
{ \
if (oi->on_write_q == 0) \
{ \
listnode_add ((O)->oi_write_q, oi); \
oi->on_write_q = 1; \
} \
if ((O)->t_write == NULL) \
(O)->t_write = \
thread_add_write (master, ospf_write, (O), (O)->fd); \
} while (0)
/* Macro for OSPF ISM timer turn on. */
#define OSPF_ISM_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), oi, (V)); \
} while (0)
#define OSPF_ISM_TIMER_MSEC_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer_msec (master, (F), oi, (V)); \
} while (0)
/* convenience macro to set hello timer correctly, according to
* whether fast-hello is set or not
*/
#define OSPF_HELLO_TIMER_ON(O) \
do { \
if (OSPF_IF_PARAM ((O), fast_hello)) \
OSPF_ISM_TIMER_MSEC_ON ((O)->t_hello, ospf_hello_timer, \
1000 / OSPF_IF_PARAM ((O), fast_hello)); \
else \
OSPF_ISM_TIMER_ON ((O)->t_hello, ospf_hello_timer, \
OSPF_IF_PARAM ((O), v_hello)); \
} while (0)
/* Macro for OSPF ISM timer turn off. */
#define OSPF_ISM_TIMER_OFF(X) \
do { \
if (X) \
{ \
thread_cancel (X); \
(X) = NULL; \
} \
} while (0)
/* Macro for OSPF schedule event. */
#define OSPF_ISM_EVENT_SCHEDULE(I,E) \
thread_add_event (master, ospf_ism_event, (I), (E))
/* Macro for OSPF execute event. */
#define OSPF_ISM_EVENT_EXECUTE(I,E) \
thread_execute (master, ospf_ism_event, (I), (E))
/* Prototypes. */
extern int ospf_ism_event (struct thread *);
extern void ism_change_status (struct ospf_interface *, int);
extern int ospf_hello_timer (struct thread *thread);
#endif /* _ZEBRA_OSPF_ISM_H */

View File

@@ -0,0 +1,345 @@
/*
* OSPF Link State Advertisement
* Copyright (C) 1999, 2000 Toshiaki Takada
*
* 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_OSPF_LSA_H
#define _ZEBRA_OSPF_LSA_H
#include "stream.h"
/* OSPF LSA Range definition. */
#define OSPF_MIN_LSA 1 /* begin range here */
#if defined (HAVE_OPAQUE_LSA)
#define OSPF_MAX_LSA 12
#else
#define OSPF_MAX_LSA 8
#endif
/* OSPF LSA Type definition. */
#define OSPF_UNKNOWN_LSA 0
#define OSPF_ROUTER_LSA 1
#define OSPF_NETWORK_LSA 2
#define OSPF_SUMMARY_LSA 3
#define OSPF_ASBR_SUMMARY_LSA 4
#define OSPF_AS_EXTERNAL_LSA 5
#define OSPF_GROUP_MEMBER_LSA 6 /* Not supported. */
#define OSPF_AS_NSSA_LSA 7
#define OSPF_EXTERNAL_ATTRIBUTES_LSA 8 /* Not supported. */
#define OSPF_OPAQUE_LINK_LSA 9
#define OSPF_OPAQUE_AREA_LSA 10
#define OSPF_OPAQUE_AS_LSA 11
#define OSPF_LSA_HEADER_SIZE 20U
#define OSPF_ROUTER_LSA_LINK_SIZE 12U
#define OSPF_ROUTER_LSA_TOS_SIZE 4U
#define OSPF_MAX_LSA_SIZE 1500U
/* AS-external-LSA refresh method. */
#define LSA_REFRESH_IF_CHANGED 0
#define LSA_REFRESH_FORCE 1
/* OSPF LSA header. */
struct lsa_header
{
u_int16_t ls_age;
u_char options;
u_char type;
struct in_addr id;
struct in_addr adv_router;
u_int32_t ls_seqnum;
u_int16_t checksum;
u_int16_t length;
};
/* OSPF LSA. */
struct ospf_lsa
{
/* LSA origination flag. */
u_char flags;
#define OSPF_LSA_SELF 0x01
#define OSPF_LSA_SELF_CHECKED 0x02
#define OSPF_LSA_RECEIVED 0x04
#define OSPF_LSA_APPROVED 0x08
#define OSPF_LSA_DISCARD 0x10
#define OSPF_LSA_LOCAL_XLT 0x20
#define OSPF_LSA_PREMATURE_AGE 0x40
#define OSPF_LSA_IN_MAXAGE 0x80
/* LSA data. */
struct lsa_header *data;
/* Received time stamp. */
struct timeval tv_recv;
/* Last time it was originated */
struct timeval tv_orig;
/* All of reference count, also lock to remove. */
int lock;
/* Flags for the SPF calculation. */
int stat;
#define LSA_SPF_NOT_EXPLORED -1
#define LSA_SPF_IN_SPFTREE -2
/* If stat >= 0, stat is LSA position in candidates heap. */
/* References to this LSA in neighbor retransmission lists*/
int retransmit_counter;
/* Area the LSA belongs to, may be NULL if AS-external-LSA. */
struct ospf_area *area;
/* Parent LSDB. */
struct ospf_lsdb *lsdb;
/* Related Route. */
void *route;
/* Refreshement List or Queue */
int refresh_list;
/* For Type-9 Opaque-LSAs */
struct ospf_interface *oi;
};
/* OSPF LSA Link Type. */
#define LSA_LINK_TYPE_POINTOPOINT 1
#define LSA_LINK_TYPE_TRANSIT 2
#define LSA_LINK_TYPE_STUB 3
#define LSA_LINK_TYPE_VIRTUALLINK 4
/* OSPF Router LSA Flag. */
#define ROUTER_LSA_BORDER 0x01 /* The router is an ABR */
#define ROUTER_LSA_EXTERNAL 0x02 /* The router is an ASBR */
#define ROUTER_LSA_VIRTUAL 0x04 /* The router has a VL in this area */
#define ROUTER_LSA_NT 0x10 /* The routers always translates Type-7 */
#define ROUTER_LSA_SHORTCUT 0x20 /* Shortcut-ABR specific flag */
#define IS_ROUTER_LSA_VIRTUAL(x) ((x)->flags & ROUTER_LSA_VIRTUAL)
#define IS_ROUTER_LSA_EXTERNAL(x) ((x)->flags & ROUTER_LSA_EXTERNAL)
#define IS_ROUTER_LSA_BORDER(x) ((x)->flags & ROUTER_LSA_BORDER)
#define IS_ROUTER_LSA_SHORTCUT(x) ((x)->flags & ROUTER_LSA_SHORTCUT)
#define IS_ROUTER_LSA_NT(x) ((x)->flags & ROUTER_LSA_NT)
/* OSPF Router-LSA Link information. */
struct router_lsa_link
{
struct in_addr link_id;
struct in_addr link_data;
struct
{
u_char type;
u_char tos_count;
u_int16_t metric;
} m[1];
};
/* OSPF Router-LSAs structure. */
#define OSPF_ROUTER_LSA_MIN_SIZE 4U /* w/0 link descriptors */
/* There is an edge case, when number of links in a Router-LSA may be 0 without
breaking the specification. A router, which has no other links to backbone
area besides one virtual link, will not put any VL descriptor blocks into
the Router-LSA generated for area 0 until a full adjacency over the VL is
reached (RFC2328 12.4.1.3). In this case the Router-LSA initially received
by the other end of the VL will have 0 link descriptor blocks, but soon will
be replaced with the next revision having 1 descriptor block. */
struct router_lsa
{
struct lsa_header header;
u_char flags;
u_char zero;
u_int16_t links;
struct
{
struct in_addr link_id;
struct in_addr link_data;
u_char type;
u_char tos;
u_int16_t metric;
} link[1];
};
/* OSPF Network-LSAs structure. */
#define OSPF_NETWORK_LSA_MIN_SIZE 8U /* w/1 router-ID */
struct network_lsa
{
struct lsa_header header;
struct in_addr mask;
struct in_addr routers[1];
};
/* OSPF Summary-LSAs structure. */
#define OSPF_SUMMARY_LSA_MIN_SIZE 8U /* w/1 TOS metric block */
struct summary_lsa
{
struct lsa_header header;
struct in_addr mask;
u_char tos;
u_char metric[3];
};
/* OSPF AS-external-LSAs structure. */
#define OSPF_AS_EXTERNAL_LSA_MIN_SIZE 16U /* w/1 TOS forwarding block */
struct as_external_lsa
{
struct lsa_header header;
struct in_addr mask;
struct
{
u_char tos;
u_char metric[3];
struct in_addr fwd_addr;
u_int32_t route_tag;
} e[1];
};
#ifdef HAVE_OPAQUE_LSA
#include "ospfd/ospf_opaque.h"
#endif /* HAVE_OPAQUE_LSA */
/* Macros. */
#define GET_METRIC(x) get_metric(x)
#define IS_EXTERNAL_METRIC(x) ((x) & 0x80)
#define GET_AGE(x) (ntohs ((x)->data->ls_age) + time (NULL) - (x)->tv_recv)
#define LS_AGE(x) (OSPF_LSA_MAXAGE < get_age(x) ? \
OSPF_LSA_MAXAGE : get_age(x))
#define IS_LSA_SELF(L) (CHECK_FLAG ((L)->flags, OSPF_LSA_SELF))
#define IS_LSA_MAXAGE(L) (LS_AGE ((L)) == OSPF_LSA_MAXAGE)
#define OSPF_LSA_UPDATE_DELAY 2
#define OSPF_LSA_UPDATE_TIMER_ON(T,F) \
if (!(T)) \
(T) = thread_add_timer (master, (F), 0, 2)
/* Prototypes. */
/* XXX: Eek, time functions, similar are in lib/thread.c */
extern struct timeval tv_adjust (struct timeval);
extern int tv_ceil (struct timeval);
extern int tv_floor (struct timeval);
extern struct timeval int2tv (int);
extern struct timeval tv_add (struct timeval, struct timeval);
extern struct timeval tv_sub (struct timeval, struct timeval);
extern int tv_cmp (struct timeval, struct timeval);
extern int get_age (struct ospf_lsa *);
extern u_int16_t ospf_lsa_checksum (struct lsa_header *);
extern int ospf_lsa_checksum_valid (struct lsa_header *);
extern int ospf_lsa_refresh_delay (struct ospf_lsa *);
extern const char *dump_lsa_key (struct ospf_lsa *);
extern u_int32_t lsa_seqnum_increment (struct ospf_lsa *);
extern void lsa_header_set (struct stream *, u_char, u_char, struct in_addr,
struct in_addr);
extern struct ospf_neighbor *ospf_nbr_lookup_ptop (struct ospf_interface *);
extern int ospf_check_nbr_status (struct ospf *);
/* Prototype for LSA primitive. */
extern struct ospf_lsa *ospf_lsa_new (void);
extern struct ospf_lsa *ospf_lsa_dup (struct ospf_lsa *);
extern void ospf_lsa_free (struct ospf_lsa *);
extern struct ospf_lsa *ospf_lsa_lock (struct ospf_lsa *);
extern void ospf_lsa_unlock (struct ospf_lsa **);
extern void ospf_lsa_discard (struct ospf_lsa *);
extern struct lsa_header *ospf_lsa_data_new (size_t);
extern struct lsa_header *ospf_lsa_data_dup (struct lsa_header *);
extern void ospf_lsa_data_free (struct lsa_header *);
/* Prototype for various LSAs */
extern int ospf_router_lsa_update (struct ospf *);
extern int ospf_router_lsa_update_area (struct ospf_area *);
extern void ospf_network_lsa_update (struct ospf_interface *);
extern struct ospf_lsa *ospf_summary_lsa_originate (struct prefix_ipv4 *, u_int32_t,
struct ospf_area *);
extern struct ospf_lsa *ospf_summary_asbr_lsa_originate (struct prefix_ipv4 *,
u_int32_t,
struct ospf_area *);
extern struct ospf_lsa *ospf_lsa_install (struct ospf *,
struct ospf_interface *, struct ospf_lsa *);
extern void ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p);
extern void ospf_external_lsa_flush (struct ospf *, u_char, struct prefix_ipv4 *,
unsigned int /* , struct in_addr nexthop */);
extern struct in_addr ospf_get_ip_from_ifp (struct ospf_interface *);
extern struct ospf_lsa *ospf_external_lsa_originate (struct ospf *, struct external_info *);
extern int ospf_external_lsa_originate_timer (struct thread *);
extern int ospf_default_originate_timer (struct thread *);
extern struct ospf_lsa *ospf_lsa_lookup (struct ospf_area *, u_int32_t,
struct in_addr, struct in_addr);
extern struct ospf_lsa *ospf_lsa_lookup_by_id (struct ospf_area *,
u_int32_t,
struct in_addr);
extern struct ospf_lsa *ospf_lsa_lookup_by_header (struct ospf_area *,
struct lsa_header *);
extern int ospf_lsa_more_recent (struct ospf_lsa *, struct ospf_lsa *);
extern int ospf_lsa_different (struct ospf_lsa *, struct ospf_lsa *);
extern void ospf_flush_self_originated_lsas_now (struct ospf *);
extern int ospf_lsa_is_self_originated (struct ospf *, struct ospf_lsa *);
extern struct ospf_lsa *ospf_lsa_lookup_by_prefix (struct ospf_lsdb *, u_char,
struct prefix_ipv4 *,
struct in_addr);
extern void ospf_lsa_maxage (struct ospf *, struct ospf_lsa *);
extern u_int32_t get_metric (u_char *);
extern int ospf_lsa_maxage_walker (struct thread *);
extern struct ospf_lsa *ospf_lsa_refresh (struct ospf *, struct ospf_lsa *);
extern void ospf_external_lsa_refresh_default (struct ospf *);
extern void ospf_external_lsa_refresh_type (struct ospf *, u_char, int);
extern struct ospf_lsa *ospf_external_lsa_refresh (struct ospf *,
struct ospf_lsa *,
struct external_info *,
int);
extern struct in_addr ospf_lsa_unique_id (struct ospf *, struct ospf_lsdb *, u_char,
struct prefix_ipv4 *);
extern void ospf_schedule_lsa_flood_area (struct ospf_area *, struct ospf_lsa *);
extern void ospf_schedule_lsa_flush_area (struct ospf_area *, struct ospf_lsa *);
extern void ospf_refresher_register_lsa (struct ospf *, struct ospf_lsa *);
extern void ospf_refresher_unregister_lsa (struct ospf *, struct ospf_lsa *);
extern int ospf_lsa_refresh_walker (struct thread *);
extern void ospf_lsa_maxage_delete (struct ospf *, struct ospf_lsa *);
extern void ospf_discard_from_db (struct ospf *, struct ospf_lsdb *, struct ospf_lsa*);
extern int is_prefix_default (struct prefix_ipv4 *);
extern int metric_type (struct ospf *, u_char);
extern int metric_value (struct ospf *, u_char);
extern struct in_addr ospf_get_nssa_ip (struct ospf_area *);
extern int ospf_translated_nssa_compare (struct ospf_lsa *, struct ospf_lsa *);
extern struct ospf_lsa *ospf_translated_nssa_refresh (struct ospf *, struct ospf_lsa *,
struct ospf_lsa *);
extern struct ospf_lsa *ospf_translated_nssa_originate (struct ospf *, struct ospf_lsa *);
#endif /* _ZEBRA_OSPF_LSA_H */

View File

@@ -0,0 +1,87 @@
/*
* OSPF LSDB support.
* Copyright (C) 1999, 2000 Alex Zinin, Kunihiro Ishiguro, Toshiaki Takada
*
* 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_OSPF_LSDB_H
#define _ZEBRA_OSPF_LSDB_H
/* OSPF LSDB structure. */
struct ospf_lsdb
{
struct
{
unsigned long count;
unsigned long count_self;
unsigned int checksum;
struct route_table *db;
} type[OSPF_MAX_LSA];
unsigned long total;
#define MONITOR_LSDB_CHANGE 1 /* XXX */
#ifdef MONITOR_LSDB_CHANGE
/* Hooks for callback functions to catch every add/del event. */
int (* new_lsa_hook)(struct ospf_lsa *);
int (* del_lsa_hook)(struct ospf_lsa *);
#endif /* MONITOR_LSDB_CHANGE */
};
/* Macros. */
#define LSDB_LOOP(T,N,L) \
if ((T) != NULL) \
for ((N) = route_top ((T)); ((N)); ((N)) = route_next ((N))) \
if (((L) = (N)->info))
#define ROUTER_LSDB(A) ((A)->lsdb->type[OSPF_ROUTER_LSA].db)
#define NETWORK_LSDB(A) ((A)->lsdb->type[OSPF_NETWORK_LSA].db)
#define SUMMARY_LSDB(A) ((A)->lsdb->type[OSPF_SUMMARY_LSA].db)
#define ASBR_SUMMARY_LSDB(A) ((A)->lsdb->type[OSPF_ASBR_SUMMARY_LSA].db)
#define EXTERNAL_LSDB(O) ((O)->lsdb->type[OSPF_AS_EXTERNAL_LSA].db)
#define NSSA_LSDB(A) ((A)->lsdb->type[OSPF_AS_NSSA_LSA].db)
#define OPAQUE_LINK_LSDB(A) ((A)->lsdb->type[OSPF_OPAQUE_LINK_LSA].db)
#define OPAQUE_AREA_LSDB(A) ((A)->lsdb->type[OSPF_OPAQUE_AREA_LSA].db)
#define OPAQUE_AS_LSDB(O) ((O)->lsdb->type[OSPF_OPAQUE_AS_LSA].db)
#define AREA_LSDB(A,T) ((A)->lsdb->type[(T)].db)
#define AS_LSDB(O,T) ((O)->lsdb->type[(T)].db)
/* OSPF LSDB related functions. */
extern struct ospf_lsdb *ospf_lsdb_new (void);
extern void ospf_lsdb_init (struct ospf_lsdb *);
extern void ospf_lsdb_free (struct ospf_lsdb *);
extern void ospf_lsdb_cleanup (struct ospf_lsdb *);
extern void ls_prefix_set (struct prefix_ls *lp, struct ospf_lsa *lsa);
extern void ospf_lsdb_add (struct ospf_lsdb *, struct ospf_lsa *);
extern void ospf_lsdb_delete (struct ospf_lsdb *, struct ospf_lsa *);
extern void ospf_lsdb_delete_all (struct ospf_lsdb *);
/* Set all stats to -1 (LSA_SPF_NOT_EXPLORED). */
extern void ospf_lsdb_clean_stat (struct ospf_lsdb *lsdb);
extern struct ospf_lsa *ospf_lsdb_lookup (struct ospf_lsdb *, struct ospf_lsa *);
extern struct ospf_lsa *ospf_lsdb_lookup_by_id (struct ospf_lsdb *, u_char,
struct in_addr, struct in_addr);
extern struct ospf_lsa *ospf_lsdb_lookup_by_id_next (struct ospf_lsdb *, u_char,
struct in_addr, struct in_addr,
int);
extern unsigned long ospf_lsdb_count_all (struct ospf_lsdb *);
extern unsigned long ospf_lsdb_count (struct ospf_lsdb *, int);
extern unsigned long ospf_lsdb_count_self (struct ospf_lsdb *, int);
extern unsigned int ospf_lsdb_checksum (struct ospf_lsdb *, int);
extern unsigned long ospf_lsdb_isempty (struct ospf_lsdb *);
#endif /* _ZEBRA_OSPF_LSDB_H */

View File

@@ -0,0 +1,90 @@
/*
* OSPF version 2 Neighbor State Machine
* From RFC2328 [OSPF Version 2]
* Copyright (C) 1999 Toshiaki Takada
*
* 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_OSPF_NSM_H
#define _ZEBRA_OSPF_NSM_H
/* OSPF Neighbor State Machine State. */
#define NSM_DependUpon 0
#define NSM_Deleted 1
#define NSM_Down 2
#define NSM_Attempt 3
#define NSM_Init 4
#define NSM_TwoWay 5
#define NSM_ExStart 6
#define NSM_Exchange 7
#define NSM_Loading 8
#define NSM_Full 9
#define OSPF_NSM_STATE_MAX 10
/* OSPF Neighbor State Machine Event. */
#define NSM_NoEvent 0
#define NSM_PacketReceived 1 /* HelloReceived in the protocol */
#define NSM_Start 2
#define NSM_TwoWayReceived 3
#define NSM_NegotiationDone 4
#define NSM_ExchangeDone 5
#define NSM_BadLSReq 6
#define NSM_LoadingDone 7
#define NSM_AdjOK 8
#define NSM_SeqNumberMismatch 9
#define NSM_OneWayReceived 10
#define NSM_KillNbr 11
#define NSM_InactivityTimer 12
#define NSM_LLDown 13
#define OSPF_NSM_EVENT_MAX 14
/* Macro for OSPF NSM timer turn on. */
#define OSPF_NSM_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), nbr, (V)); \
} while (0)
/* Macro for OSPF NSM timer turn off. */
#define OSPF_NSM_TIMER_OFF(X) \
do { \
if (X) \
{ \
thread_cancel (X); \
(X) = NULL; \
} \
} while (0)
/* Macro for OSPF NSM schedule event. */
#define OSPF_NSM_EVENT_SCHEDULE(N,E) \
thread_add_event (master, ospf_nsm_event, (N), (E))
/* Macro for OSPF NSM execute event. */
#define OSPF_NSM_EVENT_EXECUTE(N,E) \
thread_execute (master, ospf_nsm_event, (N), (E))
/* Prototypes. */
extern int ospf_nsm_event (struct thread *);
extern void ospf_check_nbr_loading (struct ospf_neighbor *);
extern int ospf_db_summary_isempty (struct ospf_neighbor *);
extern int ospf_db_summary_count (struct ospf_neighbor *);
extern void ospf_db_summary_clear (struct ospf_neighbor *);
#endif /* _ZEBRA_OSPF_NSM_H */

View File

@@ -0,0 +1,166 @@
/*
* This is an implementation of rfc2370.
* Copyright (C) 2001 KDD R&D Laboratories, Inc.
* http://www.kddlabs.co.jp/
*
* 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_OSPF_OPAQUE_H
#define _ZEBRA_OSPF_OPAQUE_H
#include "vty.h"
#define IS_OPAQUE_LSA(type) \
((type) == OSPF_OPAQUE_LINK_LSA || \
(type) == OSPF_OPAQUE_AREA_LSA || \
(type) == OSPF_OPAQUE_AS_LSA)
/*
* Usage of Opaque-LSA administrative flags in "struct ospf".
*
* 7 6 5 4 3 2 1 0
* +---+---+---+---+---+---+---+---+
* |///|///|///|///|B11|B10|B09| O |
* +---+---+---+---+---+---+---+---+
* |<--------->| A
* | +--- Operation status (operational = 1)
* +----------- Blocking status for each LSA type
*/
#define IS_OPAQUE_LSA_ORIGINATION_BLOCKED(V) \
CHECK_FLAG((V), (OPAQUE_BLOCK_TYPE_09_LSA_BIT | \
OPAQUE_BLOCK_TYPE_10_LSA_BIT | \
OPAQUE_BLOCK_TYPE_11_LSA_BIT))
/*
* Opaque LSA's link state ID is redefined as follows.
*
* 24 16 8 0
* +--------+--------+--------+--------+
* |tttttttt|........|........|........|
* +--------+--------+--------+--------+
* |<-Type->|<------- Opaque ID ------>|
*/
#define LSID_OPAQUE_TYPE_MASK 0xff000000 /* 8 bits */
#define LSID_OPAQUE_ID_MASK 0x00ffffff /* 24 bits */
#define GET_OPAQUE_TYPE(lsid) \
(((u_int32_t)(lsid) & LSID_OPAQUE_TYPE_MASK) >> 24)
#define GET_OPAQUE_ID(lsid) \
((u_int32_t)(lsid) & LSID_OPAQUE_ID_MASK)
#define SET_OPAQUE_LSID(type, id) \
((((type) << 24) & LSID_OPAQUE_TYPE_MASK) \
| ((id) & LSID_OPAQUE_ID_MASK))
/*
* Opaque LSA types will be assigned by IANA.
* <http://www.iana.org/assignments/ospf-opaque-types>
*/
#define OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA 1
#define OPAQUE_TYPE_SYCAMORE_OPTICAL_TOPOLOGY_DESC 2
#define OPAQUE_TYPE_GRACE_LSA 3
/* Followings types are proposed in internet-draft documents. */
#define OPAQUE_TYPE_8021_QOSPF 129
#define OPAQUE_TYPE_SECONDARY_NEIGHBOR_DISCOVERY 224
#define OPAQUE_TYPE_FLOODGATE 225
/* Ugly hack to make use of an unallocated value for wildcard matching! */
#define OPAQUE_TYPE_WILDCARD 0
#define OPAQUE_TYPE_RANGE_UNASSIGNED(type) \
( 4 <= (type) && (type) <= 127)
#define OPAQUE_TYPE_RANGE_RESERVED(type) \
(127 < (type) && (type) <= 255)
#define VALID_OPAQUE_INFO_LEN(lsahdr) \
((ntohs((lsahdr)->length) >= sizeof (struct lsa_header)) && \
((ntohs((lsahdr)->length) % sizeof (u_int32_t)) == 0))
/* Prototypes. */
extern void ospf_opaque_init (void);
extern void ospf_opaque_term (void);
extern int ospf_opaque_type9_lsa_init (struct ospf_interface *oi);
extern void ospf_opaque_type9_lsa_term (struct ospf_interface *oi);
extern int ospf_opaque_type10_lsa_init (struct ospf_area *area);
extern void ospf_opaque_type10_lsa_term (struct ospf_area *area);
extern int ospf_opaque_type11_lsa_init (struct ospf *ospf);
extern void ospf_opaque_type11_lsa_term (struct ospf *ospf);
extern int
ospf_register_opaque_functab (
u_char lsa_type,
u_char opaque_type,
int (* new_if_hook)(struct interface *ifp),
int (* del_if_hook)(struct interface *ifp),
void (* ism_change_hook)(struct ospf_interface *oi, int old_status),
void (* nsm_change_hook)(struct ospf_neighbor *nbr, int old_status),
void (* config_write_router)(struct vty *vty),
void (* config_write_if )(struct vty *vty, struct interface *ifp),
void (* config_write_debug )(struct vty *vty),
void (* show_opaque_info )(struct vty *vty, struct ospf_lsa *lsa),
int (* lsa_originator)(void *arg),
struct ospf_lsa *(* lsa_refresher )(struct ospf_lsa *lsa),
int (* new_lsa_hook)(struct ospf_lsa *lsa),
int (* del_lsa_hook)(struct ospf_lsa *lsa)
);
extern void ospf_delete_opaque_functab (u_char lsa_type, u_char opaque_type);
extern int ospf_opaque_new_if (struct interface *ifp);
extern int ospf_opaque_del_if (struct interface *ifp);
extern void ospf_opaque_ism_change (struct ospf_interface *oi,
int old_status);
extern void ospf_opaque_nsm_change (struct ospf_neighbor *nbr,
int old_status);
extern void ospf_opaque_config_write_router (struct vty *vty, struct ospf *);
extern void ospf_opaque_config_write_if (struct vty *vty,
struct interface *ifp);
extern void ospf_opaque_config_write_debug (struct vty *vty);
extern void show_opaque_info_detail (struct vty *vty, struct ospf_lsa *lsa);
extern void ospf_opaque_lsa_dump (struct stream *s, u_int16_t length);
extern void ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi,
int *init_delay);
extern struct ospf_lsa *ospf_opaque_lsa_install (struct ospf_lsa *,
int rt_recalc);
extern struct ospf_lsa *ospf_opaque_lsa_refresh (struct ospf_lsa *lsa);
extern void ospf_opaque_lsa_reoriginate_schedule (void *lsa_type_dependent,
u_char lsa_type,
u_char opaque_type);
extern void ospf_opaque_lsa_refresh_schedule (struct ospf_lsa *lsa);
extern void ospf_opaque_lsa_flush_schedule (struct ospf_lsa *lsa);
extern void ospf_opaque_adjust_lsreq (struct ospf_neighbor *nbr,
struct list *lsas);
extern void ospf_opaque_self_originated_lsa_received (struct ospf_neighbor
*nbr,
struct ospf_lsa *lsa);
extern void ospf_opaque_ls_ack_received (struct ospf_neighbor *nbr,
struct ospf_lsa *lsa);
extern void htonf (float *src, float *dst);
extern void ntohf (float *src, float *dst);
extern struct ospf *oi_to_top (struct ospf_interface *oi);
#endif /* _ZEBRA_OSPF_OPAQUE_H */

View File

@@ -0,0 +1,570 @@
/*
* OSPFd main header.
* Copyright (C) 1998, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada
*
* 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_OSPFD_H
#define _ZEBRA_OSPFD_H
#include <zebra.h>
#include "libospf.h"
#include "filter.h"
#include "log.h"
#define OSPF_VERSION 2
/* VTY port number. */
#define OSPF_VTY_PORT 2604
/* IP TTL for OSPF protocol. */
#define OSPF_IP_TTL 1
#define OSPF_VL_IP_TTL 100
/* Default configuration file name for ospfd. */
#define OSPF_DEFAULT_CONFIG "ospfd.conf"
#define OSPF_NSSA_TRANS_STABLE_DEFAULT 40
#define OSPF_ALLSPFROUTERS 0xe0000005 /* 224.0.0.5 */
#define OSPF_ALLDROUTERS 0xe0000006 /* 224.0.0.6 */
/* OSPF Authentication Type. */
#define OSPF_AUTH_NULL 0
#define OSPF_AUTH_SIMPLE 1
#define OSPF_AUTH_CRYPTOGRAPHIC 2
/* For Interface authentication setting default */
#define OSPF_AUTH_NOTSET -1
/* For the consumption and sanity of the command handler */
/* DO NIOT REMOVE!!! Need to detect whether a value has
been given or not in VLink command handlers */
#define OSPF_AUTH_CMD_NOTSEEN -2
/* OSPF options. */
#define OSPF_OPTION_T 0x01 /* TOS. */
#define OSPF_OPTION_E 0x02
#define OSPF_OPTION_MC 0x04
#define OSPF_OPTION_NP 0x08
#define OSPF_OPTION_EA 0x10
#define OSPF_OPTION_DC 0x20
#define OSPF_OPTION_O 0x40
/* OSPF Database Description flags. */
#define OSPF_DD_FLAG_MS 0x01
#define OSPF_DD_FLAG_M 0x02
#define OSPF_DD_FLAG_I 0x04
#define OSPF_DD_FLAG_ALL 0x07
#define OSPF_LS_REFRESH_SHIFT (60 * 15)
#define OSPF_LS_REFRESH_JITTER 60
/* OSPF master for system wide configuration and variables. */
struct ospf_master
{
/* OSPF instance. */
struct list *ospf;
/* OSPF thread master. */
struct thread_master *master;
/* Zebra interface list. */
struct list *iflist;
/* Redistributed external information. */
struct route_table *external_info[ZEBRA_ROUTE_MAX + 1];
#define EXTERNAL_INFO(T) om->external_info[T]
/* OSPF start time. */
time_t start_time;
/* Various OSPF global configuration. */
u_char options;
#define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */
};
/* OSPF instance structure. */
struct ospf
{
/* OSPF Router ID. */
struct in_addr router_id; /* Configured automatically. */
struct in_addr router_id_static; /* Configured manually. */
/* ABR/ASBR internal flags. */
u_char flags;
#define OSPF_FLAG_ABR 0x0001
#define OSPF_FLAG_ASBR 0x0002
/* ABR type. */
u_char abr_type;
#define OSPF_ABR_UNKNOWN 0
#define OSPF_ABR_STAND 1
#define OSPF_ABR_IBM 2
#define OSPF_ABR_CISCO 3
#define OSPF_ABR_SHORTCUT 4
#define OSPF_ABR_DEFAULT OSPF_ABR_CISCO
/* NSSA ABR */
u_char anyNSSA; /* Bump for every NSSA attached. */
/* Configured variables. */
u_char config;
#define OSPF_RFC1583_COMPATIBLE (1 << 0)
#define OSPF_OPAQUE_CAPABLE (1 << 2)
#define OSPF_LOG_ADJACENCY_CHANGES (1 << 3)
#define OSPF_LOG_ADJACENCY_DETAIL (1 << 4)
#ifdef HAVE_OPAQUE_LSA
/* Opaque-LSA administrative flags. */
u_char opaque;
#define OPAQUE_OPERATION_READY_BIT (1 << 0)
#define OPAQUE_BLOCK_TYPE_09_LSA_BIT (1 << 1)
#define OPAQUE_BLOCK_TYPE_10_LSA_BIT (1 << 2)
#define OPAQUE_BLOCK_TYPE_11_LSA_BIT (1 << 3)
#endif /* HAVE_OPAQUE_LSA */
/* RFC3137 stub router. Configured time to stay stub / max-metric */
unsigned int stub_router_startup_time; /* seconds */
unsigned int stub_router_shutdown_time; /* seconds */
#define OSPF_STUB_ROUTER_UNCONFIGURED 0
u_char stub_router_admin_set;
#define OSPF_STUB_ROUTER_ADMINISTRATIVE_SET 1
#define OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET 0
#define OSPF_STUB_MAX_METRIC_SUMMARY_COST 0x00ff0000
/* SPF parameters */
unsigned int spf_delay; /* SPF delay time. */
unsigned int spf_holdtime; /* SPF hold time. */
unsigned int spf_max_holdtime; /* SPF maximum-holdtime */
unsigned int spf_hold_multiplier; /* Adaptive multiplier for hold time */
int default_originate; /* Default information originate. */
#define DEFAULT_ORIGINATE_NONE 0
#define DEFAULT_ORIGINATE_ZEBRA 1
#define DEFAULT_ORIGINATE_ALWAYS 2
u_int32_t ref_bandwidth; /* Reference Bandwidth (Kbps). */
struct route_table *networks; /* OSPF config networks. */
struct list *vlinks; /* Configured Virtual-Links. */
struct list *areas; /* OSPF areas. */
struct route_table *nbr_nbma;
struct ospf_area *backbone; /* Pointer to the Backbone Area. */
struct list *oiflist; /* ospf interfaces */
u_char passive_interface_default; /* passive-interface default */
/* LSDB of AS-external-LSAs. */
struct ospf_lsdb *lsdb;
/* Flags. */
int external_origin; /* AS-external-LSA origin flag. */
int ase_calc; /* ASE calculation flag. */
#ifdef HAVE_OPAQUE_LSA
struct list *opaque_lsa_self; /* Type-11 Opaque-LSAs */
#endif /* HAVE_OPAQUE_LSA */
/* Routing tables. */
struct route_table *old_table; /* Old routing table. */
struct route_table *new_table; /* Current routing table. */
struct route_table *old_rtrs; /* Old ABR/ASBR RT. */
struct route_table *new_rtrs; /* New ABR/ASBR RT. */
struct route_table *new_external_route; /* New External Route. */
struct route_table *old_external_route; /* Old External Route. */
struct route_table *external_lsas; /* Database of external LSAs,
prefix is LSA's adv. network*/
/* Time stamps */
struct timeval ts_spf; /* SPF calculation time stamp. */
struct timeval ts_spf_duration; /* Execution time of last SPF */
struct route_table *maxage_lsa; /* List of MaxAge LSA for deletion. */
int redistribute; /* Num of redistributed protocols. */
/* Threads. */
struct thread *t_abr_task; /* ABR task timer. */
struct thread *t_asbr_check; /* ASBR check timer. */
struct thread *t_distribute_update; /* Distirbute list update timer. */
struct thread *t_spf_calc; /* SPF calculation timer. */
struct thread *t_ase_calc; /* ASE calculation timer. */
struct thread *t_external_lsa; /* AS-external-LSA origin timer. */
#ifdef HAVE_OPAQUE_LSA
struct thread *t_opaque_lsa_self; /* Type-11 Opaque-LSAs origin event. */
#endif /* HAVE_OPAQUE_LSA */
unsigned int maxage_delay; /* Delay on Maxage remover timer, sec */
struct thread *t_maxage; /* MaxAge LSA remover timer. */
struct thread *t_maxage_walker; /* MaxAge LSA checking timer. */
struct thread *t_deferred_shutdown; /* deferred/stub-router shutdown timer*/
struct thread *t_write;
struct thread *t_read;
int fd;
unsigned int maxsndbuflen;
struct stream *ibuf;
struct list *oi_write_q;
/* Distribute lists out of other route sources. */
struct
{
char *name;
struct access_list *list;
} dlist[ZEBRA_ROUTE_MAX];
#define DISTRIBUTE_NAME(O,T) (O)->dlist[T].name
#define DISTRIBUTE_LIST(O,T) (O)->dlist[T].list
/* Redistribute metric info. */
struct
{
int type; /* External metric type (E1 or E2). */
int value; /* Value for static metric (24-bit).
-1 means metric value is not set. */
} dmetric [ZEBRA_ROUTE_MAX + 1];
/* For redistribute route map. */
struct
{
char *name;
struct route_map *map;
} route_map [ZEBRA_ROUTE_MAX + 1]; /* +1 is for default-information */
#define ROUTEMAP_NAME(O,T) (O)->route_map[T].name
#define ROUTEMAP(O,T) (O)->route_map[T].map
int default_metric; /* Default metric for redistribute. */
#define OSPF_LSA_REFRESHER_GRANULARITY 10
#define OSPF_LSA_REFRESHER_SLOTS ((OSPF_LS_REFRESH_TIME + \
OSPF_LS_REFRESH_SHIFT)/10 + 1)
struct
{
u_int16_t index;
struct list *qs[OSPF_LSA_REFRESHER_SLOTS];
} lsa_refresh_queue;
struct thread *t_lsa_refresher;
time_t lsa_refresher_started;
#define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10
u_int16_t lsa_refresh_interval;
/* Distance parameter. */
u_char distance_all;
u_char distance_intra;
u_char distance_inter;
u_char distance_external;
/* Statistics for LSA origination. */
u_int32_t lsa_originate_count;
/* Statistics for LSA used for new instantiation. */
u_int32_t rx_lsa_count;
struct route_table *distance_table;
};
/* OSPF area structure. */
struct ospf_area
{
/* OSPF instance. */
struct ospf *ospf;
/* Zebra interface list belonging to the area. */
struct list *oiflist;
/* Area ID. */
struct in_addr area_id;
/* Area ID format. */
char format;
#define OSPF_AREA_ID_FORMAT_ADDRESS 1
#define OSPF_AREA_ID_FORMAT_DECIMAL 2
/* Address range. */
struct list *address_range;
/* Configured variables. */
int external_routing; /* ExternalRoutingCapability. */
#define OSPF_AREA_DEFAULT 0
#define OSPF_AREA_STUB 1
#define OSPF_AREA_NSSA 2
#define OSPF_AREA_TYPE_MAX 3
int no_summary; /* Don't inject summaries into stub.*/
int shortcut_configured; /* Area configured as shortcut. */
#define OSPF_SHORTCUT_DEFAULT 0
#define OSPF_SHORTCUT_ENABLE 1
#define OSPF_SHORTCUT_DISABLE 2
int shortcut_capability; /* Other ABRs agree on S-bit */
u_int32_t default_cost; /* StubDefaultCost. */
int auth_type; /* Authentication type. */
u_char NSSATranslatorRole; /* NSSA configured role */
#define OSPF_NSSA_ROLE_NEVER 0
#define OSPF_NSSA_ROLE_CANDIDATE 1
#define OSPF_NSSA_ROLE_ALWAYS 2
u_char NSSATranslatorState; /* NSSA operational role */
#define OSPF_NSSA_TRANSLATE_DISABLED 0
#define OSPF_NSSA_TRANSLATE_ENABLED 1
int NSSATranslatorStabilityInterval;
u_char transit; /* TransitCapability. */
#define OSPF_TRANSIT_FALSE 0
#define OSPF_TRANSIT_TRUE 1
struct route_table *ranges; /* Configured Area Ranges. */
/* RFC3137 stub router state flags for area */
u_char stub_router_state;
#define OSPF_AREA_ADMIN_STUB_ROUTED (1 << 0) /* admin stub-router set */
#define OSPF_AREA_IS_STUB_ROUTED (1 << 1) /* stub-router active */
#define OSPF_AREA_WAS_START_STUB_ROUTED (1 << 2) /* startup SR was done */
/* Area related LSDBs[Type1-4]. */
struct ospf_lsdb *lsdb;
/* Self-originated LSAs. */
struct ospf_lsa *router_lsa_self;
#ifdef HAVE_OPAQUE_LSA
struct list *opaque_lsa_self; /* Type-10 Opaque-LSAs */
#endif /* HAVE_OPAQUE_LSA */
/* Area announce list. */
struct
{
char *name;
struct access_list *list;
} _export;
#define EXPORT_NAME(A) (A)->_export.name
#define EXPORT_LIST(A) (A)->_export.list
/* Area acceptance list. */
struct
{
char *name;
struct access_list *list;
} import;
#define IMPORT_NAME(A) (A)->import.name
#define IMPORT_LIST(A) (A)->import.list
/* Type 3 LSA Area prefix-list. */
struct
{
char *name;
struct prefix_list *list;
} plist_in;
#define PREFIX_LIST_IN(A) (A)->plist_in.list
#define PREFIX_NAME_IN(A) (A)->plist_in.name
struct
{
char *name;
struct prefix_list *list;
} plist_out;
#define PREFIX_LIST_OUT(A) (A)->plist_out.list
#define PREFIX_NAME_OUT(A) (A)->plist_out.name
/* Shortest Path Tree. */
struct vertex *spf;
/* Threads. */
struct thread *t_stub_router; /* Stub-router timer */
#ifdef HAVE_OPAQUE_LSA
struct thread *t_opaque_lsa_self; /* Type-10 Opaque-LSAs origin. */
#endif /* HAVE_OPAQUE_LSA */
/* Statistics field. */
u_int32_t spf_calculation; /* SPF Calculation Count. */
/* Time stamps. */
struct timeval ts_spf; /* SPF calculation time stamp. */
/* Router count. */
u_int32_t abr_count; /* ABR router in this area. */
u_int32_t asbr_count; /* ASBR router in this area. */
/* Counters. */
u_int32_t act_ints; /* Active interfaces. */
u_int32_t full_nbrs; /* Fully adjacent neighbors. */
u_int32_t full_vls; /* Fully adjacent virtual neighbors. */
};
/* OSPF config network structure. */
struct ospf_network
{
/* Area ID. */
struct in_addr area_id;
int format;
};
/* OSPF NBMA neighbor structure. */
struct ospf_nbr_nbma
{
/* Neighbor IP address. */
struct in_addr addr;
/* OSPF interface. */
struct ospf_interface *oi;
/* OSPF neighbor structure. */
struct ospf_neighbor *nbr;
/* Neighbor priority. */
u_char priority;
/* Poll timer value. */
u_int32_t v_poll;
/* Poll timer thread. */
struct thread *t_poll;
/* State change. */
u_int32_t state_change;
};
/* Macro. */
#define OSPF_AREA_SAME(X,Y) \
(memcmp ((X->area_id), (Y->area_id), IPV4_MAX_BYTELEN) == 0)
#define IS_OSPF_ABR(O) ((O)->flags & OSPF_FLAG_ABR)
#define IS_OSPF_ASBR(O) ((O)->flags & OSPF_FLAG_ASBR)
#define OSPF_IS_AREA_ID_BACKBONE(I) ((I).s_addr == OSPF_AREA_BACKBONE)
#define OSPF_IS_AREA_BACKBONE(A) OSPF_IS_AREA_ID_BACKBONE ((A)->area_id)
#ifdef roundup
# define ROUNDUP(val, gran) roundup(val, gran)
#else /* roundup */
# define ROUNDUP(val, gran) (((val) - 1 | (gran) - 1) + 1)
#endif /* roundup */
#define LSA_OPTIONS_GET(area) \
(((area)->external_routing == OSPF_AREA_DEFAULT) ? OSPF_OPTION_E : 0)
#define LSA_OPTIONS_NSSA_GET(area) \
(((area)->external_routing == OSPF_AREA_NSSA) ? OSPF_OPTION_NP : 0)
#define OSPF_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), ospf, (V)); \
} while (0)
#define OSPF_AREA_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), area, (V)); \
} while (0)
#define OSPF_POLL_TIMER_ON(T,F,V) \
do { \
if (!(T)) \
(T) = thread_add_timer (master, (F), nbr_nbma, (V)); \
} while (0)
#define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X))
#define OSPF_TIMER_OFF(X) \
do { \
if (X) \
{ \
thread_cancel (X); \
(X) = NULL; \
} \
} while (0)
/* Extern variables. */
extern struct ospf_master *om;
extern const struct message ospf_ism_state_msg[];
extern const struct message ospf_nsm_state_msg[];
extern const struct message ospf_lsa_type_msg[];
extern const struct message ospf_link_state_id_type_msg[];
extern const struct message ospf_network_type_msg[];
extern const int ospf_ism_state_msg_max;
extern const int ospf_nsm_state_msg_max;
extern const int ospf_lsa_type_msg_max;
extern const int ospf_link_state_id_type_msg_max;
extern const int ospf_redistributed_proto_max;
extern const int ospf_network_type_msg_max;
extern struct zclient *zclient;
extern struct thread_master *master;
extern int ospf_zlog;
/* Prototypes. */
extern const char *ospf_redist_string(u_int route_type);
extern struct ospf *ospf_lookup (void);
extern struct ospf *ospf_get (void);
extern void ospf_finish (struct ospf *);
extern void ospf_router_id_update (struct ospf *ospf);
extern int ospf_network_set (struct ospf *, struct prefix_ipv4 *,
struct in_addr);
extern int ospf_network_unset (struct ospf *, struct prefix_ipv4 *,
struct in_addr);
extern int ospf_area_stub_set (struct ospf *, struct in_addr);
extern int ospf_area_stub_unset (struct ospf *, struct in_addr);
extern int ospf_area_no_summary_set (struct ospf *, struct in_addr);
extern int ospf_area_no_summary_unset (struct ospf *, struct in_addr);
extern int ospf_area_nssa_set (struct ospf *, struct in_addr);
extern int ospf_area_nssa_unset (struct ospf *, struct in_addr);
extern int ospf_area_nssa_translator_role_set (struct ospf *, struct in_addr,
int);
extern int ospf_area_export_list_set (struct ospf *, struct ospf_area *,
const char *);
extern int ospf_area_export_list_unset (struct ospf *, struct ospf_area *);
extern int ospf_area_import_list_set (struct ospf *, struct ospf_area *,
const char *);
extern int ospf_area_import_list_unset (struct ospf *, struct ospf_area *);
extern int ospf_area_shortcut_set (struct ospf *, struct ospf_area *, int);
extern int ospf_area_shortcut_unset (struct ospf *, struct ospf_area *);
extern int ospf_timers_refresh_set (struct ospf *, int);
extern int ospf_timers_refresh_unset (struct ospf *);
extern int ospf_nbr_nbma_set (struct ospf *, struct in_addr);
extern int ospf_nbr_nbma_unset (struct ospf *, struct in_addr);
extern int ospf_nbr_nbma_priority_set (struct ospf *, struct in_addr, u_char);
extern int ospf_nbr_nbma_priority_unset (struct ospf *, struct in_addr);
extern int ospf_nbr_nbma_poll_interval_set (struct ospf *, struct in_addr,
unsigned int);
extern int ospf_nbr_nbma_poll_interval_unset (struct ospf *, struct in_addr);
extern void ospf_prefix_list_update (struct prefix_list *);
extern void ospf_init (void);
extern void ospf_if_update (struct ospf *, struct interface *);
extern void ospf_ls_upd_queue_empty (struct ospf_interface *);
extern void ospf_terminate (void);
extern void ospf_nbr_nbma_if_update (struct ospf *, struct ospf_interface *);
extern struct ospf_nbr_nbma *ospf_nbr_nbma_lookup (struct ospf *,
struct in_addr);
extern struct ospf_nbr_nbma *ospf_nbr_nbma_lookup_next (struct ospf *,
struct in_addr *,
int);
extern int ospf_oi_count (struct interface *);
extern struct ospf_area *ospf_area_get (struct ospf *, struct in_addr, int);
extern void ospf_area_check_free (struct ospf *, struct in_addr);
extern struct ospf_area *ospf_area_lookup_by_area_id (struct ospf *,
struct in_addr);
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 void ospf_route_map_init (void);
extern void ospf_snmp_init (void);
extern void ospf_master_init (void);
#endif /* _ZEBRA_OSPFD_H */

View File

@@ -0,0 +1,83 @@
/*
* Prefix list functions.
* Copyright (C) 1999 Kunihiro Ishiguro
*
* 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 _QUAGGA_PLIST_H
#define _QUAGGA_PLIST_H
#define AFI_ORF_PREFIX 65535
enum prefix_list_type
{
PREFIX_DENY,
PREFIX_PERMIT,
};
enum prefix_name_type
{
PREFIX_TYPE_STRING,
PREFIX_TYPE_NUMBER
};
struct prefix_list
{
char *name;
char *desc;
struct prefix_master *master;
enum prefix_name_type type;
int count;
int rangecount;
struct prefix_list_entry *head;
struct prefix_list_entry *tail;
struct prefix_list *next;
struct prefix_list *prev;
};
struct orf_prefix
{
u_int32_t seq;
u_char ge;
u_char le;
struct prefix p;
};
/* Prototypes. */
extern void prefix_list_init (void);
extern void prefix_list_reset (void);
extern void prefix_list_add_hook (void (*func) (struct prefix_list *));
extern void prefix_list_delete_hook (void (*func) (struct prefix_list *));
extern struct prefix_list *prefix_list_lookup (afi_t, const char *);
extern enum prefix_list_type prefix_list_apply (struct prefix_list *, void *);
extern struct stream * prefix_bgp_orf_entry (struct stream *,
struct prefix_list *,
u_char, u_char, u_char);
extern int prefix_bgp_orf_set (char *, afi_t, struct orf_prefix *, int, int);
extern void prefix_bgp_orf_remove_all (char *);
extern int prefix_bgp_show_prefix_list (struct vty *, afi_t, char *);
#endif /* _QUAGGA_PLIST_H */

View File

@@ -0,0 +1,46 @@
/* Priority queue functions.
Copyright (C) 2003 Yasuhiro Ohara
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_PQUEUE_H
#define _ZEBRA_PQUEUE_H
struct pqueue
{
void **array;
int array_size;
int size;
int (*cmp) (void *, void *);
void (*update) (void * node, int actual_position);
};
#define PQUEUE_INIT_ARRAYSIZE 32
extern struct pqueue *pqueue_create (void);
extern void pqueue_delete (struct pqueue *queue);
extern void pqueue_enqueue (void *data, struct pqueue *queue);
extern void *pqueue_dequeue (struct pqueue *queue);
extern void pqueue_remove_at (int index, struct pqueue *queue);
extern void trickle_down (int index, struct pqueue *queue);
extern void trickle_up (int index, struct pqueue *queue);
#endif /* _ZEBRA_PQUEUE_H */

View File

@@ -0,0 +1,237 @@
/*
* Prefix structure.
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_PREFIX_H
#define _ZEBRA_PREFIX_H
#include "sockunion.h"
/*
* A struct prefix contains an address family, a prefix length, and an
* address. This can represent either a 'network prefix' as defined
* by CIDR, where the 'host bits' of the prefix are 0
* (e.g. AF_INET:10.0.0.0/8), or an address and netmask
* (e.g. AF_INET:10.0.0.9/8), such as might be configured on an
* interface.
*/
/* IPv4 and IPv6 unified prefix structure. */
struct prefix
{
u_char family;
u_char prefixlen;
union
{
u_char prefix;
struct in_addr prefix4;
#ifdef HAVE_IPV6
struct in6_addr prefix6;
#endif /* HAVE_IPV6 */
struct
{
struct in_addr id;
struct in_addr adv_router;
} lp;
u_char val[8];
uintptr_t ptr;
} u __attribute__ ((aligned (8)));
};
/* IPv4 prefix structure. */
struct prefix_ipv4
{
u_char family;
u_char prefixlen;
struct in_addr prefix __attribute__ ((aligned (8)));
};
/* IPv6 prefix structure. */
#ifdef HAVE_IPV6
struct prefix_ipv6
{
u_char family;
u_char prefixlen;
struct in6_addr prefix __attribute__ ((aligned (8)));
};
#endif /* HAVE_IPV6 */
struct prefix_ls
{
u_char family;
u_char prefixlen;
struct in_addr id __attribute__ ((aligned (8)));
struct in_addr adv_router;
};
/* Prefix for routing distinguisher. */
struct prefix_rd
{
u_char family;
u_char prefixlen;
u_char val[8] __attribute__ ((aligned (8)));
};
/* Prefix for a generic pointer */
struct prefix_ptr
{
u_char family;
u_char prefixlen;
uintptr_t prefix __attribute__ ((aligned (8)));
};
/* helper to get type safety/avoid casts on calls
* (w/o this, functions accepting all prefix types need casts on the caller
* side, which strips type safety since the cast will accept any pointer
* type.)
*/
union prefix46ptr
{
struct prefix *p;
struct prefix_ipv4 *p4;
struct prefix_ipv6 *p6;
} __attribute__ ((transparent_union));
union prefix46constptr
{
const struct prefix *p;
const struct prefix_ipv4 *p4;
const struct prefix_ipv6 *p6;
} __attribute__ ((transparent_union));
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
#endif /* INET_ADDRSTRLEN */
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN 46
#endif /* INET6_ADDRSTRLEN */
#ifndef INET6_BUFSIZ
#define INET6_BUFSIZ 51
#endif /* INET6_BUFSIZ */
/* Max bit/byte length of IPv4 address. */
#define IPV4_MAX_BYTELEN 4
#define IPV4_MAX_BITLEN 32
#define IPV4_MAX_PREFIXLEN 32
#define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)
#define IPV4_ADDR_SAME(D,S) (memcmp ((D), (S), IPV4_MAX_BYTELEN) == 0)
#define IPV4_ADDR_COPY(D,S) memcpy ((D), (S), IPV4_MAX_BYTELEN)
#define IPV4_NET0(a) ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
#define IPV4_NET127(a) ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
#define IPV4_LINKLOCAL(a) ((((u_int32_t) (a)) & 0xffff0000) == 0xa9fe0000)
#define IPV4_CLASS_DE(a) ((((u_int32_t) (a)) & 0xe0000000) == 0xe0000000)
/* Max bit/byte length of IPv6 address. */
#define IPV6_MAX_BYTELEN 16
#define IPV6_MAX_BITLEN 128
#define IPV6_MAX_PREFIXLEN 128
#define IPV6_ADDR_CMP(D,S) memcmp ((D), (S), IPV6_MAX_BYTELEN)
#define IPV6_ADDR_SAME(D,S) (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0)
#define IPV6_ADDR_COPY(D,S) memcpy ((D), (S), IPV6_MAX_BYTELEN)
/* Count prefix size from mask length */
#define PSIZE(a) (((a) + 7) / (8))
/* Prefix's family member. */
#define PREFIX_FAMILY(p) ((p)->family)
/* Prototypes. */
extern int afi2family (afi_t);
extern afi_t family2afi (int);
/* Check bit of the prefix. */
extern unsigned int prefix_bit (const u_char *prefix, const u_char prefixlen);
extern unsigned int prefix6_bit (const struct in6_addr *prefix, const u_char prefixlen);
extern struct prefix *prefix_new (void);
extern void prefix_free (struct prefix *);
extern const char *prefix_family_str (const struct prefix *);
extern int prefix_blen (const struct prefix *);
extern int str2prefix (const char *, struct prefix *);
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 *);
extern int str2prefix_ipv4 (const char *, struct prefix_ipv4 *);
extern void apply_mask_ipv4 (struct prefix_ipv4 *);
#define PREFIX_COPY_IPV4(DST, SRC) \
*((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC));
extern int prefix_ipv4_any (const struct prefix_ipv4 *);
extern void apply_classful_mask_ipv4 (struct prefix_ipv4 *);
extern u_char ip_masklen (struct in_addr);
extern void masklen2ip (const int, struct in_addr *);
/* returns the network portion of the host address */
extern in_addr_t ipv4_network_addr (in_addr_t hostaddr, int masklen);
/* given the address of a host on a network and the network mask length,
* calculate the broadcast address for that network;
* special treatment for /31: returns the address of the other host
* on the network by flipping the host bit */
extern in_addr_t ipv4_broadcast_addr (in_addr_t hostaddr, int masklen);
extern int netmask_str2prefix_str (const char *, const char *, char *);
#ifdef HAVE_IPV6
extern struct prefix_ipv6 *prefix_ipv6_new (void);
extern void prefix_ipv6_free (struct prefix_ipv6 *);
extern int str2prefix_ipv6 (const char *, struct prefix_ipv6 *);
extern void apply_mask_ipv6 (struct prefix_ipv6 *);
#define PREFIX_COPY_IPV6(DST, SRC) \
*((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC));
extern int ip6_masklen (struct in6_addr);
extern void masklen2ip6 (const int, struct in6_addr *);
extern void str2in6_addr (const char *, struct in6_addr *);
extern const char *inet6_ntoa (struct in6_addr);
#endif /* HAVE_IPV6 */
extern int all_digit (const char *);
static inline int ipv4_martian (struct in_addr *addr)
{
in_addr_t ip = addr->s_addr;
if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_DE(ip)) {
return 1;
}
return 0;
}
#endif /* _ZEBRA_PREFIX_H */

View File

@@ -0,0 +1,90 @@
/*
* Zebra privileges header.
*
* Copyright (C) 2003 Paul Jakma.
*
* 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_PRIVS_H
#define _ZEBRA_PRIVS_H
/* list of zebra capabilities */
typedef enum
{
ZCAP_SETID,
ZCAP_BIND,
ZCAP_NET_ADMIN,
ZCAP_SYS_ADMIN,
ZCAP_NET_RAW,
ZCAP_CHROOT,
ZCAP_NICE,
ZCAP_PTRACE,
ZCAP_DAC_OVERRIDE,
ZCAP_READ_SEARCH,
ZCAP_FOWNER,
ZCAP_MAX
} zebra_capabilities_t;
typedef enum
{
ZPRIVS_LOWERED,
ZPRIVS_RAISED,
ZPRIVS_UNKNOWN,
} zebra_privs_current_t;
typedef enum
{
ZPRIVS_RAISE,
ZPRIVS_LOWER,
} zebra_privs_ops_t;
struct zebra_privs_t
{
zebra_capabilities_t *caps_p; /* caps required for operation */
zebra_capabilities_t *caps_i; /* caps to allow inheritance of */
int cap_num_p; /* number of caps in arrays */
int cap_num_i;
const char *user; /* user and group to run as */
const char *group;
const char *vty_group; /* group to chown vty socket to */
/* methods */
int
(*change) (zebra_privs_ops_t); /* change privileges, 0 on success */
zebra_privs_current_t
(*current_state) (void); /* current privilege state */
};
struct zprivs_ids_t
{
/* -1 is undefined */
uid_t uid_priv; /* privileged uid */
uid_t uid_normal; /* normal uid */
gid_t gid_priv; /* privileged uid */
gid_t gid_normal; /* normal uid */
gid_t gid_vty; /* vty gid */
};
/* initialise zebra privileges */
extern void zprivs_init (struct zebra_privs_t *zprivs);
/* drop all and terminate privileges */
extern void zprivs_terminate (struct zebra_privs_t *);
/* query for runtime uid's and gid's, eg vty needs this */
extern void zprivs_get_ids(struct zprivs_ids_t *);
#endif /* _ZEBRA_PRIVS_H */

View File

@@ -0,0 +1,276 @@
/* Auto-generated from route_types.txt by . */
/* Do not edit! */
#ifndef _QUAGGA_ROUTE_TYPES_H
#define _QUAGGA_ROUTE_TYPES_H
/* 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_PIM 10
#define ZEBRA_ROUTE_HSLS 11
#define ZEBRA_ROUTE_OLSR 12
#define ZEBRA_ROUTE_BABEL 13
#define ZEBRA_ROUTE_MAX 14
#define SHOW_ROUTE_V4_HEADER \
"Codes: K - kernel route, C - connected, S - static, R - RIP,%s" \
" O - OSPF, I - IS-IS, B - BGP, P - PIM, A - Babel,%s" \
" > - selected route, * - FIB route%s%s", \
VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE
#define SHOW_ROUTE_V6_HEADER \
"Codes: K - kernel route, C - connected, S - static, R - RIPng,%s" \
" O - OSPFv6, I - IS-IS, B - BGP, A - Babel,%s" \
" > - selected route, * - FIB route%s%s", \
VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE
/* babeld */
#define QUAGGA_REDIST_STR_BABELD \
"(kernel|connected|static|rip|ripng|ospf|ospf6|isis|bgp|pim)"
#define QUAGGA_REDIST_HELP_STR_BABELD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n"
#define QUAGGA_IP_REDIST_STR_BABELD \
"(kernel|connected|static|rip|ospf|isis|bgp|pim)"
#define QUAGGA_IP_REDIST_HELP_STR_BABELD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n"
#define QUAGGA_IP6_REDIST_STR_BABELD \
"(kernel|connected|static|ripng|ospf6|isis|bgp)"
#define QUAGGA_IP6_REDIST_HELP_STR_BABELD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n"
/* bgpd */
#define QUAGGA_REDIST_STR_BGPD \
"(kernel|connected|static|rip|ripng|ospf|ospf6|isis|pim|babel)"
#define QUAGGA_REDIST_HELP_STR_BGPD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
#define QUAGGA_IP_REDIST_STR_BGPD \
"(kernel|connected|static|rip|ospf|isis|pim|babel)"
#define QUAGGA_IP_REDIST_HELP_STR_BGPD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
#define QUAGGA_IP6_REDIST_STR_BGPD \
"(kernel|connected|static|ripng|ospf6|isis|babel)"
#define QUAGGA_IP6_REDIST_HELP_STR_BGPD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Babel routing protocol (Babel)\n"
/* isisd */
#define QUAGGA_REDIST_STR_ISISD \
"(kernel|connected|static|rip|ripng|ospf|ospf6|bgp|pim|babel)"
#define QUAGGA_REDIST_HELP_STR_ISISD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
#define QUAGGA_IP_REDIST_STR_ISISD \
"(kernel|connected|static|rip|ospf|bgp|pim|babel)"
#define QUAGGA_IP_REDIST_HELP_STR_ISISD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
#define QUAGGA_IP6_REDIST_STR_ISISD \
"(kernel|connected|static|ripng|ospf6|bgp|babel)"
#define QUAGGA_IP6_REDIST_HELP_STR_ISISD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Border Gateway Protocol (BGP)\n" \
"Babel routing protocol (Babel)\n"
/* ospf6d */
#define QUAGGA_REDIST_STR_OSPF6D \
"(kernel|connected|static|ripng|isis|bgp|babel)"
#define QUAGGA_REDIST_HELP_STR_OSPF6D \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Babel routing protocol (Babel)\n"
/* ospfd */
#define QUAGGA_REDIST_STR_OSPFD \
"(kernel|connected|static|rip|isis|bgp|pim|babel)"
#define QUAGGA_REDIST_HELP_STR_OSPFD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
/* pimd */
#define QUAGGA_REDIST_STR_PIMD \
"(kernel|connected|static|rip|ospf|isis|bgp|babel)"
#define QUAGGA_REDIST_HELP_STR_PIMD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Babel routing protocol (Babel)\n"
/* ripd */
#define QUAGGA_REDIST_STR_RIPD \
"(kernel|connected|static|ospf|isis|bgp|pim|babel)"
#define QUAGGA_REDIST_HELP_STR_RIPD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
/* ripngd */
#define QUAGGA_REDIST_STR_RIPNGD \
"(kernel|connected|static|ospf6|isis|bgp|babel)"
#define QUAGGA_REDIST_HELP_STR_RIPNGD \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Babel routing protocol (Babel)\n"
/* zebra */
#define QUAGGA_REDIST_STR_ZEBRA \
"(kernel|connected|static|rip|ripng|ospf|ospf6|isis|bgp|pim|babel)"
#define QUAGGA_REDIST_HELP_STR_ZEBRA \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
#define QUAGGA_IP_REDIST_STR_ZEBRA \
"(kernel|connected|static|rip|ospf|isis|bgp|pim|babel)"
#define QUAGGA_IP_REDIST_HELP_STR_ZEBRA \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol (RIP)\n" \
"Open Shortest Path First (OSPFv2)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Protocol Independent Multicast (PIM)\n" \
"Babel routing protocol (Babel)\n"
#define QUAGGA_IP6_REDIST_STR_ZEBRA \
"(kernel|connected|static|ripng|ospf6|isis|bgp|babel)"
#define QUAGGA_IP6_REDIST_HELP_STR_ZEBRA \
"Kernel routes (not installed via the zebra RIB)\n" \
"Connected routes (directly attached subnet or host)\n" \
"Statically configured routes\n" \
"Routing Information Protocol next-generation (IPv6) (RIPng)\n" \
"Open Shortest Path First (IPv6) (OSPFv3)\n" \
"Intermediate System to Intermediate System (IS-IS)\n" \
"Border Gateway Protocol (BGP)\n" \
"Babel routing protocol (Babel)\n"
#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[] = {
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_PIM, "pim", 'P' ),
DESC_ENTRY (ZEBRA_ROUTE_HSLS, "hsls", 'H' ),
DESC_ENTRY (ZEBRA_ROUTE_OLSR, "olsr", 'o' ),
DESC_ENTRY (ZEBRA_ROUTE_BABEL, "babel", 'A' ),
};
#undef DESC_ENTRY
#endif /* QUAGGA_DEFINE_DESC_TABLE */
#endif /* _QUAGGA_ROUTE_TYPES_H */

View File

@@ -0,0 +1,198 @@
/* Route map function.
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_ROUTEMAP_H
#define _ZEBRA_ROUTEMAP_H
/* Route map's type. */
enum route_map_type
{
RMAP_PERMIT,
RMAP_DENY,
RMAP_ANY
};
typedef enum
{
RMAP_MATCH,
RMAP_DENYMATCH,
RMAP_NOMATCH,
RMAP_ERROR,
RMAP_OKAY
} route_map_result_t;
typedef enum
{
RMAP_RIP,
RMAP_RIPNG,
RMAP_BABEL,
RMAP_OSPF,
RMAP_OSPF6,
RMAP_BGP,
RMAP_ZEBRA
} route_map_object_t;
typedef enum
{
RMAP_EXIT,
RMAP_GOTO,
RMAP_NEXT
} route_map_end_t;
typedef enum
{
RMAP_EVENT_SET_ADDED,
RMAP_EVENT_SET_DELETED,
RMAP_EVENT_SET_REPLACED,
RMAP_EVENT_MATCH_ADDED,
RMAP_EVENT_MATCH_DELETED,
RMAP_EVENT_MATCH_REPLACED,
RMAP_EVENT_INDEX_ADDED,
RMAP_EVENT_INDEX_DELETED
} route_map_event_t;
/* Depth limit in RMAP recursion using RMAP_CALL. */
#define RMAP_RECURSION_LIMIT 10
/* Route map rule structure for matching and setting. */
struct route_map_rule_cmd
{
/* Route map rule name (e.g. as-path, metric) */
const char *str;
/* Function for value set or match. */
route_map_result_t (*func_apply)(void *, struct prefix *,
route_map_object_t, void *);
/* Compile argument and return result as void *. */
void *(*func_compile)(const char *);
/* Free allocated value by func_compile (). */
void (*func_free)(void *);
};
/* Route map apply error. */
enum
{
/* Route map rule is missing. */
RMAP_RULE_MISSING = 1,
/* Route map rule can't compile */
RMAP_COMPILE_ERROR
};
/* Route map rule list. */
struct route_map_rule_list
{
struct route_map_rule *head;
struct route_map_rule *tail;
};
/* Route map index structure. */
struct route_map_index
{
struct route_map *map;
char *description;
/* Preference of this route map rule. */
int pref;
/* Route map type permit or deny. */
enum route_map_type type;
/* Do we follow old rules, or hop forward? */
route_map_end_t exitpolicy;
/* If we're using "GOTO", to where do we go? */
int nextpref;
/* If we're using "CALL", to which route-map do ew go? */
char *nextrm;
/* Matching rule list. */
struct route_map_rule_list match_list;
struct route_map_rule_list set_list;
/* Make linked list. */
struct route_map_index *next;
struct route_map_index *prev;
};
/* Route map list structure. */
struct route_map
{
/* Name of route map. */
char *name;
/* Route map's rule. */
struct route_map_index *head;
struct route_map_index *tail;
/* Make linked list. */
struct route_map *next;
struct route_map *prev;
};
/* Prototypes. */
extern void route_map_init (void);
extern void route_map_init_vty (void);
extern void route_map_finish (void);
/* Add match statement to route map. */
extern int route_map_add_match (struct route_map_index *index,
const char *match_name,
const char *match_arg);
/* Delete specified route match rule. */
extern int route_map_delete_match (struct route_map_index *index,
const char *match_name,
const char *match_arg);
/* Add route-map set statement to the route map. */
extern int route_map_add_set (struct route_map_index *index,
const char *set_name,
const char *set_arg);
/* Delete route map set rule. */
extern int route_map_delete_set (struct route_map_index *index,
const char *set_name,
const char *set_arg);
/* Install rule command to the match list. */
extern void route_map_install_match (struct route_map_rule_cmd *cmd);
/* Install rule command to the set list. */
extern void route_map_install_set (struct route_map_rule_cmd *cmd);
/* Lookup route map by name. */
extern struct route_map * route_map_lookup_by_name (const char *name);
/* Apply route map to the object. */
extern route_map_result_t route_map_apply (struct route_map *map,
struct prefix *,
route_map_object_t object_type,
void *object);
extern void route_map_add_hook (void (*func) (const char *));
extern void route_map_delete_hook (void (*func) (const char *));
extern void route_map_event_hook (void (*func) (route_map_event_t, const char *));
#endif /* _ZEBRA_ROUTEMAP_H */

View File

@@ -0,0 +1,52 @@
/*
* Quagga Signal handling header.
*
* Copyright (C) 2004 Paul Jakma.
*
* This file is part of Quagga.
*
* Quagga 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.
*
* Quagga 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 Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef _QUAGGA_SIGNAL_H
#define _QUAGGA_SIGNAL_H
#include <thread.h>
#define QUAGGA_SIGNAL_TIMER_INTERVAL 2L
struct quagga_signal_t
{
int signal; /* signal number */
void (*handler) (void); /* handler to call */
volatile sig_atomic_t caught; /* private member */
};
/* initialise sigevent system
* takes:
* - pointer to valid struct thread_master
* - number of elements in passed in signals array
* - array of quagga_signal_t's describing signals to handle
* and handlers to use for each signal
*/
extern void signal_init (struct thread_master *m, int sigc,
struct quagga_signal_t *signals);
/* check whether there are signals to handle, process any found */
extern int quagga_sigevent_process (void);
#endif /* _QUAGGA_SIGNAL_H */

View File

@@ -0,0 +1,114 @@
/* SNMP support
* Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
*
* 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_SNMP_H
#define _ZEBRA_SNMP_H
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/agent/snmp_vars.h>
/* Structures here are mostly compatible with UCD SNMP 4.1.1 */
#define MATCH_FAILED (-1)
#define MATCH_SUCCEEDED 0
/* SYNTAX TruthValue from SNMPv2-TC. */
#define SNMP_TRUE 1
#define SNMP_FALSE 2
/* SYNTAX RowStatus from SNMPv2-TC. */
#define SNMP_VALID 1
#define SNMP_INVALID 2
#define IN_ADDR_SIZE sizeof(struct in_addr)
#undef REGISTER_MIB
#define REGISTER_MIB(descr, var, vartype, theoid) \
smux_register_mib(descr, (struct variable *)var, sizeof(struct vartype), \
sizeof(var)/sizeof(struct vartype), \
theoid, sizeof(theoid)/sizeof(oid))
struct trap_object
{
int namelen; /* Negative if the object is not indexed */
oid name[MAX_OID_LEN];
};
/* Declare SMUX return value. */
#define SNMP_LOCAL_VARIABLES \
static long snmp_int_val; \
static struct in_addr snmp_in_addr_val;
#define SNMP_INTEGER(V) \
( \
*var_len = sizeof (snmp_int_val), \
snmp_int_val = V, \
(u_char *) &snmp_int_val \
)
#define SNMP_IPADDRESS(V) \
( \
*var_len = sizeof (struct in_addr), \
snmp_in_addr_val = V, \
(u_char *) &snmp_in_addr_val \
)
extern void smux_init (struct thread_master *tm);
extern void smux_register_mib(const char *, struct variable *,
size_t, int, oid [], size_t);
extern int smux_header_generic (struct variable *, oid [], size_t *,
int, size_t *, WriteMethod **);
extern int smux_header_table (struct variable *, oid *, size_t *,
int, size_t *, WriteMethod **);
/* For traps, three OID are provided:
1. The enterprise OID to use (the last argument will be appended to
it to form the SNMP trap OID)
2. The base OID for objects to be sent in traps.
3. The index OID for objects to be sent in traps. This index is used
to designate a particular instance of a column.
The provided trap object contains the bindings to be sent with the
trap. The base OID will be prefixed to the provided OID and, if the
length is positive, the requested OID is assumed to be a columnar
object and the index OID will be appended.
The two first arguments are the MIB registry used to locate the trap
objects.
The use of the arguments may differ depending on the implementation
used.
*/
extern int smux_trap (struct variable *, size_t,
const oid *, size_t,
const oid *, size_t,
const oid *, size_t,
const struct trap_object *, size_t,
u_char);
extern int oid_compare (oid *, int, oid *, int);
extern void oid2in_addr (oid [], int, struct in_addr *);
extern void *oid_copy (void *, const void *, size_t);
extern void oid_copy_addr (oid [], struct in_addr *, int);
#endif /* _ZEBRA_SNMP_H */

View File

@@ -0,0 +1,105 @@
/* Router advertisement
* Copyright (C) 1999 Kunihiro Ishiguro
*
* 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_SOCKOPT_H
#define _ZEBRA_SOCKOPT_H
#include "sockunion.h"
extern int setsockopt_so_recvbuf (int sock, int size);
extern int setsockopt_so_sendbuf (const int sock, int size);
extern int getsockopt_so_sendbuf (const int sock);
#ifdef HAVE_IPV6
extern int setsockopt_ipv6_pktinfo (int, int);
extern int setsockopt_ipv6_checksum (int, int);
extern int setsockopt_ipv6_multicast_hops (int, int);
extern int setsockopt_ipv6_unicast_hops (int, int);
extern int setsockopt_ipv6_hoplimit (int, int);
extern int setsockopt_ipv6_multicast_loop (int, int);
extern int setsockopt_ipv6_tclass (int, int);
#endif /* HAVE_IPV6 */
/*
* It is OK to reference in6_pktinfo here without a protecting #if
* because this macro will only be used #if HAVE_IPV6, and in6_pktinfo
* is not optional for HAVE_IPV6.
*/
#define SOPT_SIZE_CMSG_PKTINFO_IPV6() (sizeof (struct in6_pktinfo));
/*
* Size defines for control messages used to get ifindex. We define
* values for each method, and define a macro that can be used by code
* that is unaware of which method is in use.
* These values are without any alignment needed (see CMSG_SPACE in RFC3542).
*/
#if defined (IP_PKTINFO)
/* Linux in_pktinfo. */
#define SOPT_SIZE_CMSG_PKTINFO_IPV4() (CMSG_SPACE(sizeof (struct in_pktinfo)))
/* XXX This should perhaps be defined even if IP_PKTINFO is not. */
#define SOPT_SIZE_CMSG_PKTINFO(af) \
((af == AF_INET) ? SOPT_SIZE_CMSG_PKTINFO_IPV4() \
: SOPT_SIZE_CMSG_PKTINFO_IPV6()
#endif /* IP_PKTINFO */
#if defined (IP_RECVIF)
/* BSD/Solaris */
#if defined (SUNOS_5)
#define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof (uint_t))
#else
#define SOPT_SIZE_CMSG_RECVIF_IPV4() (sizeof (struct sockaddr_dl))
#endif /* SUNOS_5 */
#endif /* IP_RECVIF */
/* SOPT_SIZE_CMSG_IFINDEX_IPV4 - portable type */
#if defined (SOPT_SIZE_CMSG_PKTINFO)
#define SOPT_SIZE_CMSG_IFINDEX_IPV4() SOPT_SIZE_CMSG_PKTINFO_IPV4()
#elif defined (SOPT_SIZE_CMSG_RECVIF_IPV4)
#define SOPT_SIZE_CMSG_IFINDEX_IPV4() SOPT_SIZE_CMSG_RECVIF_IPV4()
#else /* Nothing available */
#define SOPT_SIZE_CMSG_IFINDEX_IPV4() (sizeof (char *))
#endif /* SOPT_SIZE_CMSG_IFINDEX_IPV4 */
#define SOPT_SIZE_CMSG_IFINDEX(af) \
(((af) == AF_INET) : SOPT_SIZE_CMSG_IFINDEX_IPV4() \
? SOPT_SIZE_CMSG_PKTINFO_IPV6())
extern int setsockopt_ipv4_multicast_if(int sock,
unsigned int ifindex);
extern int setsockopt_ipv4_multicast(int sock, int optname,
unsigned int mcast_addr,
unsigned int ifindex);
extern int setsockopt_ipv4_tos(int sock, int tos);
/* Ask for, and get, ifindex, by whatever method is supported. */
extern int setsockopt_ifindex (int, int, int);
extern int getsockopt_ifindex (int, struct msghdr *);
/* swab the fields in iph between the host order and system order expected
* for IP_HDRINCL.
*/
extern void sockopt_iphdrincl_swab_htosys (struct ip *iph);
extern void sockopt_iphdrincl_swab_systoh (struct ip *iph);
extern int sockopt_tcp_signature(int sock, union sockunion *su,
const char *password);
#endif /*_ZEBRA_SOCKOPT_H */

View File

@@ -0,0 +1,125 @@
/*
* Socket union header.
* Copyright (c) 1997 Kunihiro Ishiguro
*
* 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_SOCKUNION_H
#define _ZEBRA_SOCKUNION_H
#if 0
union sockunion {
struct sockinet {
u_char si_len;
u_char si_family;
u_short si_port;
} su_si;
struct sockaddr_in su_sin;
struct sockaddr_in6 su_sin6;
};
#define su_len su_si.si_len
#define su_family su_si.si_family
#define su_port su_si.si_port
#endif /* 0 */
union sockunion
{
struct sockaddr sa;
struct sockaddr_in sin;
#ifdef HAVE_IPV6
struct sockaddr_in6 sin6;
#endif /* HAVE_IPV6 */
};
enum connect_result
{
connect_error,
connect_success,
connect_in_progress
};
/* Default address family. */
#ifdef HAVE_IPV6
#define AF_INET_UNION AF_INET6
#else
#define AF_INET_UNION AF_INET
#endif
/* Sockunion address string length. Same as INET6_ADDRSTRLEN. */
#define SU_ADDRSTRLEN 46
/* Macro to set link local index to the IPv6 address. For KAME IPv6
stack. */
#ifdef KAME
#define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3])
#define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
do { \
(a).s6_addr[2] = ((i) >> 8) & 0xff; \
(a).s6_addr[3] = (i) & 0xff; \
} while (0)
#else
#define IN6_LINKLOCAL_IFINDEX(a)
#define SET_IN6_LINKLOCAL_IFINDEX(a, i)
#endif /* KAME */
#define sockunion_family(X) (X)->sa.sa_family
#define sockunion2ip(X) (X)->sin.sin_addr.s_addr
/* Prototypes. */
extern int str2sockunion (const char *, union sockunion *);
extern const char *sockunion2str (union sockunion *, char *, size_t);
extern int sockunion_cmp (union sockunion *, union sockunion *);
extern int sockunion_same (union sockunion *, union sockunion *);
extern union sockunion *sockunion_str2su (const char *str);
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_minttl (int family, int sock, int minttl);
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,
unsigned short port,
unsigned int);
extern union sockunion *sockunion_getsockname (int);
extern union sockunion *sockunion_getpeername (int);
extern union sockunion *sockunion_dup (union sockunion *);
extern void sockunion_free (union sockunion *);
#ifndef HAVE_INET_NTOP
extern const char * inet_ntop (int family, const void *addrptr,
char *strptr, size_t len);
#endif /* HAVE_INET_NTOP */
#ifndef HAVE_INET_PTON
extern int inet_pton (int family, const char *strptr, void *addrptr);
#endif /* HAVE_INET_PTON */
#ifndef HAVE_INET_ATON
extern int inet_aton (const char *cp, struct in_addr *inaddr);
#endif
#endif /* _ZEBRA_SOCKUNION_H */

View File

@@ -0,0 +1,33 @@
/*
* $Id: str.h,v 1.4 2005/09/19 09:53:21 hasso Exp $
*/
#ifndef _ZEBRA_STR_H
#define _ZEBRA_STR_H
#ifndef HAVE_SNPRINTF
extern int snprintf(char *, size_t, const char *, ...);
#endif
#ifndef HAVE_VSNPRINTF
#define vsnprintf(buf, size, format, args) vsprintf(buf, format, args)
#endif
#ifndef HAVE_STRLCPY
extern size_t strlcpy(char *, const char *, size_t);
#endif
#ifndef HAVE_STRLCAT
extern size_t strlcat(char *, const char *, size_t);
#endif
#ifndef HAVE_STRNLEN
extern size_t strnlen(const char *s, size_t maxlen);
#endif
#ifndef HAVE_STRNDUP
extern char * strndup (const char *, size_t);
#endif
#endif /* _ZEBRA_STR_H */

View File

@@ -0,0 +1,229 @@
/*
* Packet interface
* Copyright (C) 1999 Kunihiro Ishiguro
*
* 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_STREAM_H
#define _ZEBRA_STREAM_H
#include "prefix.h"
/*
* A stream is an arbitrary buffer, whose contents generally are assumed to
* be in network order.
*
* A stream has the following attributes associated with it:
*
* - size: the allocated, invariant size of the buffer.
*
* - getp: the get position marker, denoting the offset in the stream where
* the next read (or 'get') will be from. This getp marker is
* automatically adjusted when data is read from the stream, the
* user may also manipulate this offset as they wish, within limits
* (see below)
*
* - endp: the end position marker, denoting the offset in the stream where
* valid data ends, and if the user attempted to write (or
* 'put') data where that data would be written (or 'put') to.
*
* These attributes are all size_t values.
*
* Constraints:
*
* 1. getp can never exceed endp
*
* - hence if getp is equal to endp, there is no more valid data that can be
* gotten from the stream (though, the user may reposition getp to earlier in
* the stream, if they wish).
*
* 2. endp can never exceed size
*
* - hence, if endp is equal to size, then the stream is full, and no more
* data can be written to the stream.
*
* In other words the following must always be true, and the stream
* abstraction is allowed internally to assert that the following property
* holds true for a stream, as and when it wishes:
*
* getp <= endp <= size
*
* It is the users responsibility to ensure this property is never violated.
*
* A stream therefore can be thought of like this:
*
* ---------------------------------------------------
* |XXXXXXXXXXXXXXXXXXXXXXXX |
* ---------------------------------------------------
* ^ ^ ^
* getp endp size
*
* This shows a stream containing data (shown as 'X') up to the endp offset.
* The stream is empty from endp to size. Without adjusting getp, there are
* still endp-getp bytes of valid data to be read from the stream.
*
* Methods are provided to get and put to/from the stream, as well as
* retrieve the values of the 3 markers and manipulate the getp marker.
*
* Note:
* At the moment, newly allocated streams are zero filled. Hence, one can
* use stream_forward_endp() to effectively create arbitrary zero-fill
* padding. However, note that stream_reset() does *not* zero-out the
* stream. This property should **not** be relied upon.
*
* Best practice is to use stream_put (<stream *>, NULL, <size>) to zero out
* any part of a stream which isn't otherwise written to.
*/
/* Stream buffer. */
struct stream
{
struct stream *next;
/* Remainder is ***private*** to stream
* direct access is frowned upon!
* Use the appropriate functions/macros
*/
size_t getp; /* next get position */
size_t endp; /* last valid data position */
size_t size; /* size of data segment */
unsigned char *data; /* data pointer */
};
/* First in first out queue structure. */
struct stream_fifo
{
size_t count;
struct stream *head;
struct stream *tail;
};
/* Utility macros. */
#define STREAM_SIZE(S) ((S)->size)
/* number of bytes which can still be written */
#define STREAM_WRITEABLE(S) ((S)->size - (S)->endp)
/* number of bytes still to be read */
#define STREAM_READABLE(S) ((S)->endp - (S)->getp)
#define STREAM_CONCAT_REMAIN(S1, S2, size) \
((size) - (S1)->endp - (S2)->endp)
/* deprecated macros - do not use in new code */
#define STREAM_PNT(S) stream_pnt((S))
#define STREAM_DATA(S) ((S)->data)
#define STREAM_REMAIN(S) STREAM_WRITEABLE((S))
/* Stream prototypes.
* For stream_{put,get}S, the S suffix mean:
*
* c: character (unsigned byte)
* w: word (two bytes)
* l: long (two words)
* q: quad (four words)
*/
extern struct stream *stream_new (size_t);
extern void stream_free (struct stream *);
extern struct stream * stream_copy (struct stream *, struct stream *src);
extern struct stream *stream_dup (struct stream *);
extern size_t stream_resize (struct stream *, size_t);
extern size_t stream_get_getp (struct stream *);
extern size_t stream_get_endp (struct stream *);
extern size_t stream_get_size (struct stream *);
extern u_char *stream_get_data (struct stream *);
/**
* Create a new stream structure; copy offset bytes from s1 to the new
* stream; copy s2 data to the new stream; copy rest of s1 data to the
* new stream.
*/
extern struct stream *stream_dupcat(struct stream *s1, struct stream *s2,
size_t offset);
extern void stream_set_getp (struct stream *, size_t);
extern void stream_set_endp (struct stream *, size_t);
extern void stream_forward_getp (struct stream *, size_t);
extern void stream_forward_endp (struct stream *, size_t);
/* steam_put: NULL source zeroes out size_t bytes of stream */
extern void stream_put (struct stream *, const void *, size_t);
extern int stream_putc (struct stream *, u_char);
extern int stream_putc_at (struct stream *, size_t, u_char);
extern int stream_putw (struct stream *, u_int16_t);
extern int stream_putw_at (struct stream *, size_t, u_int16_t);
extern int stream_putl (struct stream *, u_int32_t);
extern int stream_putl_at (struct stream *, size_t, u_int32_t);
extern int stream_putq (struct stream *, uint64_t);
extern int stream_putq_at (struct stream *, size_t, uint64_t);
extern int stream_put_ipv4 (struct stream *, u_int32_t);
extern int stream_put_in_addr (struct stream *, struct in_addr *);
extern int stream_put_prefix (struct stream *, struct prefix *);
extern void stream_get (void *, struct stream *, size_t);
extern u_char stream_getc (struct stream *);
extern u_char stream_getc_from (struct stream *, size_t);
extern u_int16_t stream_getw (struct stream *);
extern u_int16_t stream_getw_from (struct stream *, size_t);
extern u_int32_t stream_getl (struct stream *);
extern u_int32_t stream_getl_from (struct stream *, size_t);
extern uint64_t stream_getq (struct stream *);
extern uint64_t stream_getq_from (struct stream *, size_t);
extern u_int32_t stream_get_ipv4 (struct stream *);
#undef stream_read
#undef stream_write
/* Deprecated: assumes blocking I/O. Will be removed.
Use stream_read_try instead. */
extern int stream_read (struct stream *, int, size_t);
/* Read up to size bytes into the stream.
Return code:
>0: number of bytes read
0: end-of-file
-1: fatal error
-2: transient error, should retry later (i.e. EAGAIN or EINTR)
This is suitable for use with non-blocking file descriptors.
*/
extern ssize_t stream_read_try(struct stream *s, int fd, size_t size);
extern ssize_t stream_recvmsg (struct stream *s, int fd, struct msghdr *,
int flags, size_t size);
extern ssize_t stream_recvfrom (struct stream *s, int fd, size_t len,
int flags, struct sockaddr *from,
socklen_t *fromlen);
extern size_t stream_write (struct stream *, const void *, size_t);
/* reset the stream. See Note above */
extern void stream_reset (struct stream *);
extern int stream_flush (struct stream *, int);
extern int stream_empty (struct stream *); /* is the stream empty? */
/* deprecated */
extern u_char *stream_pnt (struct stream *);
/* Stream fifo. */
extern struct stream_fifo *stream_fifo_new (void);
extern void stream_fifo_push (struct stream_fifo *fifo, struct stream *s);
extern struct stream *stream_fifo_pop (struct stream_fifo *fifo);
extern struct stream *stream_fifo_head (struct stream_fifo *fifo);
extern void stream_fifo_clean (struct stream_fifo *fifo);
extern void stream_fifo_free (struct stream_fifo *fifo);
#endif /* _ZEBRA_STREAM_H */

View File

@@ -0,0 +1,254 @@
/*
* Routing Table
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_TABLE_H
#define _ZEBRA_TABLE_H
/*
* Forward declarations.
*/
struct route_node;
struct route_table;
/*
* route_table_delegate_t
*
* Function vector that can be used by a client to customize the
* behavior of one or more route tables.
*/
typedef struct route_table_delegate_t_ route_table_delegate_t;
typedef struct route_node * (*route_table_create_node_func_t)
(route_table_delegate_t *, struct route_table *);
typedef void (*route_table_destroy_node_func_t)
(route_table_delegate_t *, struct route_table *, struct route_node *);
struct route_table_delegate_t_
{
route_table_create_node_func_t create_node;
route_table_destroy_node_func_t destroy_node;
};
/* Routing table top structure. */
struct route_table
{
struct route_node *top;
/*
* Delegate that performs certain functions for this table.
*/
route_table_delegate_t *delegate;
unsigned long count;
/*
* User data.
*/
void *info;
};
/*
* Macro that defines all fields in a route node.
*/
#define ROUTE_NODE_FIELDS \
/* Actual prefix of this radix. */ \
struct prefix p; \
\
/* Tree link. */ \
struct route_table *table; \
struct route_node *parent; \
struct route_node *link[2]; \
\
/* Lock of this radix */ \
unsigned int lock; \
\
/* Each node of route. */ \
void *info; \
\
/* Aggregation. */ \
void *aggregate;
/* Each routing entry. */
struct route_node
{
ROUTE_NODE_FIELDS;
#define l_left link[0]
#define l_right link[1]
};
typedef struct route_table_iter_t_ route_table_iter_t;
typedef enum
{
RT_ITER_STATE_INIT,
RT_ITER_STATE_ITERATING,
RT_ITER_STATE_PAUSED,
RT_ITER_STATE_DONE
} route_table_iter_state_t;
/*
* route_table_iter_t
*
* Structure that holds state for iterating over a route table.
*/
struct route_table_iter_t_
{
route_table_iter_state_t state;
/*
* Routing table that we are iterating over. The caller must ensure
* that that table outlives the iterator.
*/
struct route_table *table;
/*
* The node that the iterator is currently on.
*/
struct route_node *current;
/*
* The last prefix that the iterator processed before it was paused.
*/
struct prefix pause_prefix;
};
/* Prototypes. */
extern struct route_table *route_table_init (void);
extern struct route_table *
route_table_init_with_delegate (route_table_delegate_t *);
extern void route_table_finish (struct route_table *);
extern void route_unlock_node (struct route_node *node);
extern struct route_node *route_top (struct route_table *);
extern struct route_node *route_next (struct route_node *);
extern struct route_node *route_next_until (struct route_node *,
struct route_node *);
extern struct route_node *route_node_get (struct route_table *const,
struct prefix *);
extern struct route_node *route_node_lookup (const struct route_table *,
struct prefix *);
extern struct route_node *route_lock_node (struct route_node *node);
extern struct route_node *route_node_match (const struct route_table *,
const struct prefix *);
extern struct route_node *route_node_match_ipv4 (const struct route_table *,
const struct in_addr *);
#ifdef HAVE_IPV6
extern struct route_node *route_node_match_ipv6 (const struct route_table *,
const struct in6_addr *);
#endif /* HAVE_IPV6 */
extern unsigned long route_table_count (const struct route_table *);
extern struct route_node *
route_table_get_next (const struct route_table *table, struct prefix *p);
extern int
route_table_prefix_iter_cmp (struct prefix *p1, struct prefix *p2);
/*
* Iterator functions.
*/
extern void route_table_iter_init (route_table_iter_t *iter,
struct route_table *table);
extern void route_table_iter_pause (route_table_iter_t *iter);
extern void route_table_iter_cleanup (route_table_iter_t *iter);
/*
* Inline functions.
*/
/*
* route_table_iter_next
*
* Get the next node in the tree.
*/
static inline struct route_node *
route_table_iter_next (route_table_iter_t * iter)
{
struct route_node *node;
switch (iter->state)
{
case RT_ITER_STATE_INIT:
/*
* We're just starting the iteration.
*/
node = route_top (iter->table);
break;
case RT_ITER_STATE_ITERATING:
node = route_next (iter->current);
break;
case RT_ITER_STATE_PAUSED:
/*
* Start with the node following pause_prefix.
*/
node = route_table_get_next (iter->table, &iter->pause_prefix);
break;
case RT_ITER_STATE_DONE:
return NULL;
default:
assert (0);
}
iter->current = node;
if (node)
iter->state = RT_ITER_STATE_ITERATING;
else
iter->state = RT_ITER_STATE_DONE;
return node;
}
/*
* route_table_iter_is_done
*
* Returns TRUE if the iteration is complete.
*/
static inline int
route_table_iter_is_done (route_table_iter_t *iter)
{
return iter->state == RT_ITER_STATE_DONE;
}
/*
* route_table_iter_started
*
* Returns TRUE if this iterator has started iterating over the tree.
*/
static inline int
route_table_iter_started (route_table_iter_t *iter)
{
return iter->state != RT_ITER_STATE_INIT;
}
#endif /* _ZEBRA_TABLE_H */

View File

@@ -0,0 +1,241 @@
/* Thread management routine header.
* Copyright (C) 1998 Kunihiro Ishiguro
*
* 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_THREAD_H
#define _ZEBRA_THREAD_H
#include <zebra.h>
struct rusage_t
{
#ifdef HAVE_RUSAGE
struct rusage cpu;
#endif
struct timeval real;
};
#define RUSAGE_T struct rusage_t
#define GETRUSAGE(X) thread_getrusage(X)
/* Linked list of thread. */
struct thread_list
{
struct thread *head;
struct thread *tail;
int count;
};
struct pqueue;
/* Master of the theads. */
struct thread_master
{
struct thread_list read;
struct thread_list write;
struct pqueue *timer;
struct thread_list event;
struct thread_list ready;
struct thread_list unuse;
struct pqueue *background;
fd_set readfd;
fd_set writefd;
fd_set exceptfd;
unsigned long alloc;
};
typedef unsigned char thread_type;
/* Thread itself. */
struct thread
{
thread_type type; /* thread type */
thread_type add_type; /* thread type */
struct thread *next; /* next pointer of the thread */
struct thread *prev; /* previous pointer of the thread */
struct thread_master *master; /* pointer to the struct thread_master. */
int (*func) (struct thread *); /* event function */
void *arg; /* event argument */
union {
int val; /* second argument of the event. */
int fd; /* file descriptor in case of read/write. */
struct timeval sands; /* rest of time sands value. */
} u;
int index; /* used for timers to store position in queue */
struct timeval real;
struct cpu_thread_history *hist; /* cache pointer to cpu_history */
const char *funcname;
const char *schedfrom;
int schedfrom_line;
};
struct cpu_thread_history
{
int (*func)(struct thread *);
unsigned int total_calls;
struct time_stats
{
unsigned long total, max;
} real;
#ifdef HAVE_RUSAGE
struct time_stats cpu;
#endif
thread_type types;
const char *funcname;
};
/* Clocks supported by Quagga */
enum quagga_clkid {
QUAGGA_CLK_REALTIME = 0, /* ala gettimeofday() */
QUAGGA_CLK_MONOTONIC, /* monotonic, against an indeterminate base */
QUAGGA_CLK_REALTIME_STABILISED, /* like realtime, but non-decrementing */
};
/* Thread types. */
#define THREAD_READ 0
#define THREAD_WRITE 1
#define THREAD_TIMER 2
#define THREAD_EVENT 3
#define THREAD_READY 4
#define THREAD_BACKGROUND 5
#define THREAD_UNUSED 6
#define THREAD_EXECUTE 7
/* Thread yield time. */
#define THREAD_YIELD_TIME_SLOT 10 * 1000L /* 10ms */
/* Macros. */
#define THREAD_ARG(X) ((X)->arg)
#define THREAD_FD(X) ((X)->u.fd)
#define THREAD_VAL(X) ((X)->u.val)
#define THREAD_READ_ON(master,thread,func,arg,sock) \
do { \
if (! thread) \
thread = thread_add_read (master, func, arg, sock); \
} while (0)
#define THREAD_WRITE_ON(master,thread,func,arg,sock) \
do { \
if (! thread) \
thread = thread_add_write (master, func, arg, sock); \
} while (0)
#define THREAD_TIMER_ON(master,thread,func,arg,time) \
do { \
if (! thread) \
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) \
{ \
thread_cancel (thread); \
thread = NULL; \
} \
} while (0)
#define THREAD_READ_OFF(thread) THREAD_OFF(thread)
#define THREAD_WRITE_OFF(thread) THREAD_OFF(thread)
#define THREAD_TIMER_OFF(thread) THREAD_OFF(thread)
#define debugargdef const char *funcname, const char *schedfrom, int fromln
#define thread_add_read(m,f,a,v) funcname_thread_add_read(m,f,a,v,#f,__FILE__,__LINE__)
#define thread_add_write(m,f,a,v) funcname_thread_add_write(m,f,a,v,#f,__FILE__,__LINE__)
#define thread_add_timer(m,f,a,v) funcname_thread_add_timer(m,f,a,v,#f,__FILE__,__LINE__)
#define thread_add_timer_msec(m,f,a,v) funcname_thread_add_timer_msec(m,f,a,v,#f,__FILE__,__LINE__)
#define thread_add_event(m,f,a,v) funcname_thread_add_event(m,f,a,v,#f,__FILE__,__LINE__)
#define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f,__FILE__,__LINE__)
/* The 4th arg to thread_add_background is the # of milliseconds to delay. */
#define thread_add_background(m,f,a,v) funcname_thread_add_background(m,f,a,v,#f,__FILE__,__LINE__)
/* Prototypes. */
extern struct thread_master *thread_master_create (void);
extern void thread_master_free (struct thread_master *);
extern struct thread *funcname_thread_add_read (struct thread_master *,
int (*)(struct thread *),
void *, int, debugargdef);
extern struct thread *funcname_thread_add_write (struct thread_master *,
int (*)(struct thread *),
void *, int, debugargdef);
extern struct thread *funcname_thread_add_timer (struct thread_master *,
int (*)(struct thread *),
void *, long, debugargdef);
extern struct thread *funcname_thread_add_timer_msec (struct thread_master *,
int (*)(struct thread *),
void *, long, debugargdef);
extern struct thread *funcname_thread_add_event (struct thread_master *,
int (*)(struct thread *),
void *, int, debugargdef);
extern struct thread *funcname_thread_add_background (struct thread_master *,
int (*func)(struct thread *),
void *arg,
long milliseconds_to_delay,
debugargdef);
extern struct thread *funcname_thread_execute (struct thread_master *,
int (*)(struct thread *),
void *, int, debugargdef);
#undef debugargdef
extern void thread_cancel (struct thread *);
extern unsigned int thread_cancel_event (struct thread_master *, void *);
extern struct thread *thread_fetch (struct thread_master *, struct thread *);
extern void thread_call (struct thread *);
extern unsigned long thread_timer_remain_second (struct thread *);
extern int thread_should_yield (struct thread *);
extern unsigned long timeval_elapsed (struct timeval a, struct timeval b);
/* 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
* all systems, and fully monotonic on /some/ systems.
*/
extern int quagga_gettime (enum quagga_clkid, struct timeval *);
extern time_t quagga_time (time_t *);
/* Returns elapsed real (wall clock) time. */
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);
/* only for use in logging functions! */
extern struct thread *thread_current;
#endif /* _ZEBRA_THREAD_H */

View File

@@ -0,0 +1,63 @@
/*
* Generic vector interface header.
* Copyright (C) 1997, 98 Kunihiro Ishiguro
*
* 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_VECTOR_H
#define _ZEBRA_VECTOR_H
/* struct for vector */
struct _vector
{
unsigned int active; /* number of active slots */
unsigned int alloced; /* number of allocated slot */
void **index; /* index to data */
};
typedef struct _vector *vector;
#define VECTOR_MIN_SIZE 1
/* (Sometimes) usefull macros. This macro convert index expression to
array expression. */
/* Reference slot at given index, caller must ensure slot is active */
#define vector_slot(V,I) ((V)->index[(I)])
/* Number of active slots.
* Note that this differs from vector_count() as it the count returned
* will include any empty slots
*/
#define vector_active(V) ((V)->active)
/* Prototypes. */
extern vector vector_init (unsigned int size);
extern void vector_ensure (vector v, unsigned int num);
extern int vector_empty_slot (vector v);
extern int vector_set (vector v, void *val);
extern int vector_set_index (vector v, unsigned int i, void *val);
extern void vector_unset (vector v, unsigned int i);
extern unsigned int vector_count (vector v);
extern void vector_only_wrapper_free (vector v);
extern void vector_only_index_free (void *index);
extern void vector_free (vector v);
extern vector vector_copy (vector v);
extern void *vector_lookup (vector, unsigned int);
extern void *vector_lookup_ensure (vector, unsigned int);
#endif /* _ZEBRA_VECTOR_H */

View File

@@ -0,0 +1,56 @@
/* lib/version.h. Generated from version.h.in by configure.
*
* Quagga version
* Copyright (C) 1997, 1999 Kunihiro Ishiguro
*
* 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_VERSION_H
#define _ZEBRA_VERSION_H
#ifdef GIT_VERSION
#include "gitversion.h"
#endif
#ifndef GIT_SUFFIX
#define GIT_SUFFIX ""
#endif
#ifndef GIT_INFO
#define GIT_INFO ""
#endif
#define QUAGGA_PROGNAME "Quagga"
#define QUAGGA_VERSION "0.99.24.1" GIT_SUFFIX
#define ZEBRA_BUG_ADDRESS "https://bugzilla.quagga.net"
#define QUAGGA_URL "http://www.quagga.net"
#define QUAGGA_COPYRIGHT "Copyright 1996-2005 Kunihiro Ishiguro, et al."
#define QUAGGA_CONFIG_ARGS "--build=arm-linux-gnueabihf --prefix=/usr --includedir=${prefix}/include --mandir=${prefix}/share/man --infodir=${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libexecdir=${prefix}/lib/quagga --disable-maintainer-mode --disable-dependency-tracking --enable-exampledir=/usr/share/doc/quagga/examples/ --localstatedir=/var/run/quagga --sbindir=/usr/lib/quagga --sysconfdir=/etc/quagga --enable-vtysh --enable-isisd --enable-watchquagga --enable-ospf-te --enable-opaque-lsa --enable-ipv6 --enable-ospfclient=yes --enable-ospfapi=yes --enable-multipath=64 --enable-user=quagga --enable-group=quagga --enable-vty-group=quaggavty --enable-configfile-mask=0640 --enable-logfile-mask=0640 --enable-rtadv --enable-gcc-rdynamic --enable-pimd --with-libpam CFLAGS=-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2 CXXFLAGS=-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security FCFLAGS=-g -O2 -fPIE -fstack-protector-strong FFLAGS=-g -O2 -fPIE -fstack-protector-strong GCJFLAGS=-g -O2 -fPIE -fstack-protector-strong LDFLAGS=-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now OBJCFLAGS=-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security OBJCXXFLAGS=-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security"
pid_t pid_output (const char *);
#ifndef HAVE_DAEMON
int daemon(int, int);
#endif
#endif /* _ZEBRA_VERSION_H */

View File

@@ -0,0 +1,254 @@
/* Virtual terminal [aka TeletYpe] interface routine
Copyright (C) 1997 Kunihiro Ishiguro
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_VTY_H
#define _ZEBRA_VTY_H
#include "thread.h"
#include "log.h"
#include "sockunion.h"
#define VTY_MAXHIST 20
/* VTY struct. */
struct vty
{
/* File descripter of this vty. */
int fd;
/* Is this vty connect to file or not */
enum {VTY_TERM, VTY_FILE, VTY_SHELL, VTY_SHELL_SERV} type;
/* Node status of this vty */
int node;
/* Failure count */
int fail;
/* Output buffer. */
struct buffer *obuf;
/* Command input buffer */
char *buf;
/* Command cursor point */
int cp;
/* Command length */
int length;
/* Command max length. */
int max;
/* Histry of command */
char *hist[VTY_MAXHIST];
/* History lookup current point */
int hp;
/* History insert end point */
int hindex;
/* For current referencing point of interface, route-map,
access-list etc... */
void *index;
/* For multiple level index treatment such as key chain and key. */
void *index_sub;
/* For escape character. */
unsigned char escape;
/* Current vty status. */
enum {VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE} status;
/* IAC handling: was the last character received the
IAC (interpret-as-command) escape character (and therefore the next
character will be the command code)? Refer to Telnet RFC 854. */
unsigned char iac;
/* IAC SB (option subnegotiation) handling */
unsigned char iac_sb_in_progress;
/* At the moment, we care only about the NAWS (window size) negotiation,
and that requires just a 5-character buffer (RFC 1073):
<NAWS char> <16-bit width> <16-bit height> */
#define TELNET_NAWS_SB_LEN 5
unsigned char sb_buf[TELNET_NAWS_SB_LEN];
/* How many subnegotiation characters have we received? We just drop
those that do not fit in the buffer. */
size_t sb_len;
/* Window width/height. */
int width;
int height;
/* Configure lines. */
int lines;
/* Terminal monitor. */
int monitor;
/* In configure mode. */
int config;
/* Read and write thread. */
struct thread *t_read;
struct thread *t_write;
/* Timeout seconds and thread. */
unsigned long v_timeout;
struct thread *t_timeout;
/* What address is this vty comming from. */
char address[SU_ADDRSTRLEN];
};
/* Integrated configuration file. */
#define INTEGRATE_DEFAULT_CONFIG "Quagga.conf"
/* Small macro to determine newline is newline only or linefeed needed. */
#define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n")
/* Default time out value */
#define VTY_TIMEOUT_DEFAULT 600
/* Vty read buffer size. */
#define VTY_READ_BUFSIZ 512
/* Directory separator. */
#ifndef DIRECTORY_SEP
#define DIRECTORY_SEP '/'
#endif /* DIRECTORY_SEP */
#ifndef IS_DIRECTORY_SEP
#define IS_DIRECTORY_SEP(c) ((c) == DIRECTORY_SEP)
#endif
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
#else
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
/* Utility macros to convert VTY argument to unsigned long */
#define VTY_GET_ULONG(NAME,V,STR) \
do { \
char *endptr = NULL; \
errno = 0; \
(V) = strtoul ((STR), &endptr, 10); \
if (*(STR) == '-' || *endptr != '\0' || errno) \
{ \
vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
return CMD_WARNING; \
} \
} while (0)
/*
* The logic below ((TMPL) <= ((MIN) && (TMPL) != (MIN)) is
* done to circumvent the compiler complaining about
* comparing unsigned numbers against zero, if MIN is zero.
* NB: The compiler isn't smart enough to supress the warning
* if you write (MIN) != 0 && tmpl < (MIN).
*/
#define VTY_GET_INTEGER_RANGE_HEART(NAME,TMPL,STR,MIN,MAX) \
do { \
VTY_GET_ULONG(NAME, (TMPL), STR); \
if ( ((TMPL) <= (MIN) && (TMPL) != (MIN)) || (TMPL) > (MAX) ) \
{ \
vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE);\
return CMD_WARNING; \
} \
} while (0)
#define VTY_GET_INTEGER_RANGE(NAME,V,STR,MIN,MAX) \
do { \
unsigned long tmpl; \
VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
(V) = tmpl; \
} while (0)
#define VTY_CHECK_INTEGER_RANGE(NAME,STR,MIN,MAX) \
do { \
unsigned long tmpl; \
VTY_GET_INTEGER_RANGE_HEART(NAME,tmpl,STR,MIN,MAX); \
} while (0)
#define VTY_GET_INTEGER(NAME,V,STR) \
VTY_GET_INTEGER_RANGE(NAME,V,STR,0U,UINT32_MAX)
#define VTY_GET_IPV4_ADDRESS(NAME,V,STR) \
do { \
int retv; \
retv = inet_aton ((STR), &(V)); \
if (!retv) \
{ \
vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
return CMD_WARNING; \
} \
} while (0)
#define VTY_GET_IPV4_PREFIX(NAME,V,STR) \
do { \
int retv; \
retv = str2prefix_ipv4 ((STR), &(V)); \
if (retv <= 0) \
{ \
vty_out (vty, "%% Invalid %s value%s", NAME, VTY_NEWLINE); \
return CMD_WARNING; \
} \
} while (0)
#define VTY_WARN_EXPERIMENTAL() \
do { \
vty_out (vty, "%% WARNING: this command is experimental. Both its name and" \
" parameters may%s%% change in a future version of Quagga," \
" possibly breaking your configuration!%s", \
VTY_NEWLINE, VTY_NEWLINE); \
} while (0)
/* Exported variables */
extern char integrate_default[];
/* Prototypes. */
extern void vty_init (struct thread_master *);
extern void vty_init_vtysh (void);
extern void vty_terminate (void);
extern void vty_reset (void);
extern struct vty *vty_new (void);
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
extern void vty_read_config (char *, char *);
extern void vty_time_print (struct vty *, int);
extern void vty_serv_sock (const char *, unsigned short, const char *);
extern void vty_close (struct vty *);
extern char *vty_get_cwd (void);
extern void vty_log (const char *level, const char *proto,
const char *fmt, struct timestamp_control *, va_list);
extern int vty_config_lock (struct vty *);
extern int vty_config_unlock (struct vty *);
extern int vty_shell (struct vty *);
extern int vty_shell_serv (struct vty *);
extern void vty_hello (struct vty *);
/* Send a fixed-size message to all vty terminal monitors; this should be
an async-signal-safe function. */
extern void vty_log_fixed (char *buf, size_t len);
#endif /* _ZEBRA_VTY_H */

View File

@@ -0,0 +1,125 @@
/*
* Quagga Work Queues.
*
* Copyright (C) 2005 Sun Microsystems, Inc.
*
* This file is part of Quagga.
*
* Quagga 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.
*
* Quagga 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 Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef _QUAGGA_WORK_QUEUE_H
#define _QUAGGA_WORK_QUEUE_H
/* Hold time for the initial schedule of a queue run, in millisec */
#define WORK_QUEUE_DEFAULT_HOLD 50
/* action value, for use by item processor and item error handlers */
typedef enum
{
WQ_SUCCESS = 0,
WQ_ERROR, /* Error, run error handler if provided */
WQ_RETRY_NOW, /* retry immediately */
WQ_RETRY_LATER, /* retry later, cease processing work queue */
WQ_REQUEUE, /* requeue item, continue processing work queue */
WQ_QUEUE_BLOCKED, /* Queue cant be processed at this time.
* Similar to WQ_RETRY_LATER, but doesn't penalise
* the particular item.. */
} wq_item_status;
/* A single work queue item, unsurprisingly */
struct work_queue_item
{
void *data; /* opaque data */
unsigned short ran; /* # of times item has been run */
};
#define WQ_UNPLUGGED (1 << 0) /* available for draining */
struct work_queue
{
/* Everything but the specification struct is private
* the following may be read
*/
struct thread_master *master; /* thread master */
struct thread *thread; /* thread, if one is active */
char *name; /* work queue name */
/* Specification for this work queue.
* Public, must be set before use by caller. May be modified at will.
*/
struct {
/* optional opaque user data, global to the queue. */
void *data;
/* work function to process items with:
* First argument is the workqueue queue.
* Second argument is the item data
*/
wq_item_status (*workfunc) (struct work_queue *, void *);
/* error handling function, optional */
void (*errorfunc) (struct work_queue *, struct work_queue_item *);
/* callback to delete user specific item data */
void (*del_item_data) (struct work_queue *, void *);
/* completion callback, called when queue is emptied, optional */
void (*completion_func) (struct work_queue *);
/* max number of retries to make for item that errors */
unsigned int max_retries;
unsigned int hold; /* hold time for first run, in ms */
} spec;
/* remaining fields should be opaque to users */
struct list *items; /* queue item list */
unsigned long runs; /* runs count */
struct {
unsigned int best;
unsigned int granularity;
unsigned long total;
} cycles; /* cycle counts */
/* private state */
u_int16_t flags; /* user set flag */
};
/* User API */
/* create a new work queue, of given name.
* user must fill in the spec of the returned work queue before adding
* anything to it
*/
extern struct work_queue *work_queue_new (struct thread_master *,
const char *);
/* destroy work queue */
extern void work_queue_free (struct work_queue *);
/* Add the supplied data as an item onto the workqueue */
extern void work_queue_add (struct work_queue *, void *);
/* plug the queue, ie prevent it from being drained / processed */
extern void work_queue_plug (struct work_queue *wq);
/* unplug the queue, allow it to be drained again */
extern void work_queue_unplug (struct work_queue *wq);
/* Helpers, exported for thread.c and command.c */
extern int work_queue_run (struct thread *);
extern struct cmd_element show_work_queues_cmd;
#endif /* _QUAGGA_WORK_QUEUE_H */

View File

@@ -0,0 +1,44 @@
/*
* $Id: zassert.h,v 1.2 2004/12/03 18:01:04 ajs Exp $
*
* This file is part of Quagga.
*
* Quagga 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.
*
* Quagga 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 Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef _QUAGGA_ASSERT_H
#define _QUAGGA_ASSERT_H
extern void _zlog_assert_failed (const char *assertion, const char *file,
unsigned int line, const char *function)
__attribute__ ((noreturn));
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#define __ASSERT_FUNCTION __func__
#elif defined(__GNUC__)
#define __ASSERT_FUNCTION __FUNCTION__
#else
#define __ASSERT_FUNCTION NULL
#endif
#define zassert(EX) ((void)((EX) ? 0 : \
(_zlog_assert_failed(#EX, __FILE__, __LINE__, \
__ASSERT_FUNCTION), 0)))
#undef assert
#define assert(EX) zassert(EX)
#endif /* _QUAGGA_ASSERT_H */

View File

@@ -0,0 +1,191 @@
/* Zebra's client header.
* Copyright (C) 1999 Kunihiro Ishiguro
*
* 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_ZCLIENT_H
#define _ZEBRA_ZCLIENT_H
/* For struct zapi_ipv{4,6}. */
#include "prefix.h"
/* For struct interface and struct connected. */
#include "if.h"
/* For input/output buffer to zebra. */
#define ZEBRA_MAX_PACKET_SIZ 4096
/* Zebra header size. */
#define ZEBRA_HEADER_SIZE 6
/* Structure for the zebra client. */
struct zclient
{
/* Socket to zebra daemon. */
int sock;
/* Flag of communication to zebra is enabled or not. Default is on.
This flag is disabled by `no router zebra' statement. */
int enable;
/* Connection failure count. */
int fail;
/* Input buffer for zebra message. */
struct stream *ibuf;
/* Output buffer for zebra message. */
struct stream *obuf;
/* Buffer of data waiting to be written to zebra. */
struct buffer *wb;
/* Read and connect thread. */
struct thread *t_read;
struct thread *t_connect;
/* Thread to write buffered data to zebra. */
struct thread *t_write;
/* Redistribute information. */
u_char redist_default;
u_char redist[ZEBRA_ROUTE_MAX];
/* Redistribute defauilt. */
u_char default_information;
/* Pointer to the callback functions. */
int (*router_id_update) (int, struct zclient *, uint16_t);
int (*interface_add) (int, struct zclient *, uint16_t);
int (*interface_delete) (int, struct zclient *, uint16_t);
int (*interface_up) (int, struct zclient *, uint16_t);
int (*interface_down) (int, struct zclient *, uint16_t);
int (*interface_address_add) (int, struct zclient *, uint16_t);
int (*interface_address_delete) (int, struct zclient *, uint16_t);
int (*ipv4_route_add) (int, struct zclient *, uint16_t);
int (*ipv4_route_delete) (int, struct zclient *, uint16_t);
int (*ipv6_route_add) (int, struct zclient *, uint16_t);
int (*ipv6_route_delete) (int, struct zclient *, uint16_t);
};
/* Zebra API message flag. */
#define ZAPI_MESSAGE_NEXTHOP 0x01
#define ZAPI_MESSAGE_IFINDEX 0x02
#define ZAPI_MESSAGE_DISTANCE 0x04
#define ZAPI_MESSAGE_METRIC 0x08
/* Zserv protocol message header */
struct zserv_header
{
uint16_t length;
uint8_t marker; /* corresponds to command field in old zserv
* always set to 255 in new zserv.
*/
uint8_t version;
#define ZSERV_VERSION 2
uint16_t command;
};
/* Zebra IPv4 route message API. */
struct zapi_ipv4
{
u_char type;
u_char flags;
u_char message;
safi_t safi;
u_char nexthop_num;
struct in_addr **nexthop;
u_char ifindex_num;
unsigned int *ifindex;
u_char distance;
u_int32_t metric;
};
/* Prototypes of zebra client service functions. */
extern struct zclient *zclient_new (void);
extern void zclient_init (struct zclient *, int);
extern int zclient_start (struct zclient *);
extern void zclient_stop (struct zclient *);
extern void zclient_reset (struct zclient *);
extern void zclient_free (struct zclient *);
extern int zclient_socket_connect (struct zclient *);
extern void zclient_serv_path_set (char *path);
extern const char *const zclient_serv_path_get (void);
/* Send redistribute command to zebra daemon. Do not update zclient state. */
extern int zebra_redistribute_send (int command, struct zclient *, int type);
/* If state has changed, update state and call zebra_redistribute_send. */
extern void zclient_redistribute (int command, struct zclient *, int type);
/* If state has changed, update state and send the command to zebra. */
extern void zclient_redistribute_default (int command, struct zclient *);
/* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
Returns 0 for success or -1 on an I/O error. */
extern int zclient_send_message(struct zclient *);
/* create header for command, length to be filled in by user later */
extern void zclient_create_header (struct stream *, uint16_t);
extern struct interface *zebra_interface_add_read (struct stream *);
extern struct interface *zebra_interface_state_read (struct stream *s);
extern struct connected *zebra_interface_address_read (int, struct stream *);
extern void zebra_interface_if_set_value (struct stream *, struct interface *);
extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *,
struct zapi_ipv4 *);
#ifdef HAVE_IPV6
/* IPv6 prefix add and delete function prototype. */
struct zapi_ipv6
{
u_char type;
u_char flags;
u_char message;
safi_t safi;
u_char nexthop_num;
struct in6_addr **nexthop;
u_char ifindex_num;
unsigned int *ifindex;
u_char distance;
u_int32_t metric;
};
extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient,
struct prefix_ipv6 *p, struct zapi_ipv6 *api);
#endif /* HAVE_IPV6 */
#endif /* _ZEBRA_ZCLIENT_H */

View File

@@ -0,0 +1,564 @@
/* Zebra common header.
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
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_H
#define _ZEBRA_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#ifdef SUNOS_5
#define _XPG4_2
#define __EXTENSIONS__
typedef unsigned int u_int32_t;
typedef unsigned short u_int16_t;
typedef unsigned char u_int8_t;
#endif /* SUNOS_5 */
#ifndef HAVE_SOCKLEN_T
typedef int socklen_t;
#endif /* HAVE_SOCKLEN_T */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <pwd.h>
#include <grp.h>
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif /* HAVE_STROPTS_H */
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif /* HAVE_SYS_SELECT_H */
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_SYS_SYSCTL_H
#ifdef GNU_LINUX
#include <linux/types.h>
#endif
#include <sys/sysctl.h>
#endif /* HAVE_SYS_SYSCTL_H */
#include <sys/ioctl.h>
#ifdef HAVE_SYS_CONF_H
#include <sys/conf.h>
#endif /* HAVE_SYS_CONF_H */
#ifdef HAVE_SYS_KSYM_H
#include <sys/ksym.h>
#endif /* HAVE_SYS_KSYM_H */
#include <syslog.h>
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif /* TIME_WITH_SYS_TIME */
#include <sys/uio.h>
#include <sys/utsname.h>
#ifdef HAVE_RUSAGE
#include <sys/resource.h>
#endif /* HAVE_RUSAGE */
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif /* HAVE_LIMITS_H */
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif /* HAVE_INTTYPES_H */
/* machine dependent includes */
#ifdef SUNOS_5
#include <strings.h>
#endif /* SUNOS_5 */
/* machine dependent includes */
#ifdef HAVE_LINUX_VERSION_H
#include <linux/version.h>
#endif /* HAVE_LINUX_VERSION_H */
#ifdef HAVE_ASM_TYPES_H
#include <asm/types.h>
#endif /* HAVE_ASM_TYPES_H */
/* misc include group */
#include <stdarg.h>
#if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
/* Not C99; do we need to define va_copy? */
#ifndef va_copy
#ifdef __va_copy
#define va_copy(DST,SRC) __va_copy(DST,SRC)
#else
/* Now we are desperate; this should work on many typical platforms.
But this is slightly dangerous, because the standard does not require
va_copy to be a macro. */
#define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list))
#warning "Not C99 and no va_copy macro available, falling back to memcpy"
#endif /* __va_copy */
#endif /* !va_copy */
#endif /* !C99 */
#ifdef HAVE_LCAPS
#include <sys/capability.h>
#include <sys/prctl.h>
#endif /* HAVE_LCAPS */
#ifdef HAVE_SOLARIS_CAPABILITIES
#include <priv.h>
#endif /* HAVE_SOLARIS_CAPABILITIES */
/* network include group */
#include <sys/socket.h>
#ifdef HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>
#endif /* HAVE_SYS_SOCKIO_H */
#ifdef __APPLE__
#define __APPLE_USE_RFC_3542
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif /* HAVE_NETINET_IN_H */
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#ifdef HAVE_NET_NETOPT_H
#include <net/netopt.h>
#endif /* HAVE_NET_NETOPT_H */
#include <net/if.h>
#ifdef HAVE_NET_IF_DL_H
#include <net/if_dl.h>
#endif /* HAVE_NET_IF_DL_H */
#ifdef HAVE_NET_IF_VAR_H
#include <net/if_var.h>
#endif /* HAVE_NET_IF_VAR_H */
#ifdef HAVE_NET_ROUTE_H
#include <net/route.h>
#endif /* HAVE_NET_ROUTE_H */
#ifdef HAVE_NETLINK
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/filter.h>
#else
#define RT_TABLE_MAIN 0
#endif /* HAVE_NETLINK */
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#include <arpa/inet.h>
#ifdef HAVE_INET_ND_H
#include <inet/nd.h>
#endif /* HAVE_INET_ND_H */
#ifdef HAVE_NETINET_IN_VAR_H
#include <netinet/in_var.h>
#endif /* HAVE_NETINET_IN_VAR_H */
#ifdef HAVE_NETINET6_IN6_VAR_H
#include <netinet6/in6_var.h>
#endif /* HAVE_NETINET6_IN6_VAR_H */
#ifdef HAVE_NETINET_IN6_VAR_H
#include <netinet/in6_var.h>
#endif /* HAVE_NETINET_IN6_VAR_H */
#ifdef HAVE_NETINET6_IN_H
#include <netinet6/in.h>
#endif /* HAVE_NETINET6_IN_H */
#ifdef HAVE_NETINET6_IP6_H
#include <netinet6/ip6.h>
#endif /* HAVE_NETINET6_IP6_H */
#ifdef HAVE_NETINET_ICMP6_H
#include <netinet/icmp6.h>
#endif /* HAVE_NETINET_ICMP6_H */
#ifdef HAVE_NETINET6_ND6_H
#include <netinet6/nd6.h>
#endif /* HAVE_NETINET6_ND6_H */
/* Some systems do not define UINT32_MAX, etc.. from inttypes.h
* e.g. this makes life easier for FBSD 4.11 users.
*/
#ifndef INT8_MAX
#define INT8_MAX (127)
#endif
#ifndef INT16_MAX
#define INT16_MAX (32767)
#endif
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX (255U)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX (65535U)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#ifdef HAVE_GLIBC_BACKTRACE
#include <execinfo.h>
#endif /* HAVE_GLIBC_BACKTRACE */
/* Local includes: */
#if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
#define __attribute__(x)
#endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
#include "zassert.h"
#include "str.h"
#ifdef HAVE_BROKEN_CMSG_FIRSTHDR
/* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
/* Check that msg_controllen is large enough. */
#define ZCMSG_FIRSTHDR(mhdr) \
(((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \
CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL)
#warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
#else /* HAVE_BROKEN_CMSG_FIRSTHDR */
#define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
#endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
/*
* RFC 3542 defines several macros for using struct cmsghdr.
* Here, we define those that are not present
*/
/*
* Internal defines, for use only in this file.
* These are likely wrong on other than ILP32 machines, so warn.
*/
#ifndef _CMSG_DATA_ALIGN
#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
#endif /* _CMSG_DATA_ALIGN */
#ifndef _CMSG_HDR_ALIGN
#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
#endif /* _CMSG_HDR_ALIGN */
/*
* CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
* version.
*/
#ifndef CMSG_SPACE
#define CMSG_SPACE(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \
_CMSG_HDR_ALIGN(l))
#warning "assuming 4-byte alignment for CMSG_SPACE"
#endif /* CMSG_SPACE */
#ifndef CMSG_LEN
#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
#warning "assuming 4-byte alignment for CMSG_LEN"
#endif /* CMSG_LEN */
/* The definition of struct in_pktinfo is missing in old version of
GLIBC 2.1 (Redhat 6.1). */
#if defined (GNU_LINUX) && ! defined (HAVE_STRUCT_IN_PKTINFO)
struct in_pktinfo
{
int ipi_ifindex;
struct in_addr ipi_spec_dst;
struct in_addr ipi_addr;
};
#endif
/*
* OSPF Fragmentation / fragmented writes
*
* ospfd can support writing fragmented packets, for cases where
* kernel will not fragment IP_HDRINCL and/or multicast destined
* packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However,
* SunOS, probably BSD too, clobber the user supplied IP ID and IP
* flags fields, hence user-space fragmentation will not work.
* Only Linux is known to leave IP header unmolested.
* Further, fragmentation really should be done the kernel, which already
* supports it, and which avoids nasty IP ID state problems.
*
* Fragmentation of OSPF packets can be required on networks with router
* with many many interfaces active in one area, or on networks with links
* with low MTUs.
*/
#ifdef GNU_LINUX
#define WANT_OSPF_WRITE_FRAGMENT
#endif
/*
* IP_HDRINCL / struct ip byte order
*
* Linux: network byte order
* *BSD: network, except for length and offset. (cf Stevens)
* SunOS: nominally as per BSD. but bug: network order on LE.
* OpenBSD: network byte order, apart from older versions which are as per
* *BSD
*/
#if defined(__NetBSD__) \
|| (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
|| (defined(__OpenBSD__) && (OpenBSD < 200311)) \
|| (defined(__APPLE__)) \
|| (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
#define HAVE_IP_HDRINCL_BSD_ORDER
#endif
/* Define BYTE_ORDER, if not defined. Useful for compiler conditional
* code, rather than preprocessor conditional.
* Not all the world has this BSD define.
*/
#ifndef BYTE_ORDER
#define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */
#define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
#if defined(WORDS_BIGENDIAN)
#define BYTE_ORDER BIG_ENDIAN
#else /* !WORDS_BIGENDIAN */
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* WORDS_BIGENDIAN */
#endif /* ndef BYTE_ORDER */
/* MAX / MIN are not commonly defined, but useful */
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
#define ZEBRA_NUM_OF(x) (sizeof (x) / sizeof (x[0]))
/* For old definition. */
#ifndef IN6_ARE_ADDR_EQUAL
#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
#endif /* IN6_ARE_ADDR_EQUAL */
/* default zebra TCP port for zclient */
#define ZEBRA_PORT 2600
/* Zebra message types. */
#define ZEBRA_INTERFACE_ADD 1
#define ZEBRA_INTERFACE_DELETE 2
#define ZEBRA_INTERFACE_ADDRESS_ADD 3
#define ZEBRA_INTERFACE_ADDRESS_DELETE 4
#define ZEBRA_INTERFACE_UP 5
#define ZEBRA_INTERFACE_DOWN 6
#define ZEBRA_IPV4_ROUTE_ADD 7
#define ZEBRA_IPV4_ROUTE_DELETE 8
#define ZEBRA_IPV6_ROUTE_ADD 9
#define ZEBRA_IPV6_ROUTE_DELETE 10
#define ZEBRA_REDISTRIBUTE_ADD 11
#define ZEBRA_REDISTRIBUTE_DELETE 12
#define ZEBRA_REDISTRIBUTE_DEFAULT_ADD 13
#define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14
#define ZEBRA_IPV4_NEXTHOP_LOOKUP 15
#define ZEBRA_IPV6_NEXTHOP_LOOKUP 16
#define ZEBRA_IPV4_IMPORT_LOOKUP 17
#define ZEBRA_IPV6_IMPORT_LOOKUP 18
#define ZEBRA_INTERFACE_RENAME 19
#define ZEBRA_ROUTER_ID_ADD 20
#define ZEBRA_ROUTER_ID_DELETE 21
#define ZEBRA_ROUTER_ID_UPDATE 22
#define ZEBRA_HELLO 23
#define ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB 24
#define ZEBRA_MESSAGE_MAX 25
/* Marker value used in new Zserv, in the byte location corresponding
* the command value in the old zserv header. To allow old and new
* Zserv headers to be distinguished from each other.
*/
#define ZEBRA_HEADER_MARKER 255
/* 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
* updated! */
/* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
extern const char *zebra_route_string(unsigned int route_type);
/* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
extern char zebra_route_char(unsigned int route_type);
/* Map a zserv command type to the same string,
* 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);
/* Zebra's family types. */
#define ZEBRA_FAMILY_IPV4 1
#define ZEBRA_FAMILY_IPV6 2
#define ZEBRA_FAMILY_MAX 3
/* Error codes of zebra. */
#define ZEBRA_ERR_NOERROR 0
#define ZEBRA_ERR_RTEXIST -1
#define ZEBRA_ERR_RTUNREACH -2
#define ZEBRA_ERR_EPERM -3
#define ZEBRA_ERR_RTNOEXIST -4
#define ZEBRA_ERR_KERNEL -5
/* Zebra message flags */
#define ZEBRA_FLAG_INTERNAL 0x01
#define ZEBRA_FLAG_SELFROUTE 0x02
#define ZEBRA_FLAG_BLACKHOLE 0x04
#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
/* Zebra nexthop flags. */
#define ZEBRA_NEXTHOP_IFINDEX 1
#define ZEBRA_NEXTHOP_IFNAME 2
#define ZEBRA_NEXTHOP_IPV4 3
#define ZEBRA_NEXTHOP_IPV4_IFINDEX 4
#define ZEBRA_NEXTHOP_IPV4_IFNAME 5
#define ZEBRA_NEXTHOP_IPV6 6
#define ZEBRA_NEXTHOP_IPV6_IFINDEX 7
#define ZEBRA_NEXTHOP_IPV6_IFNAME 8
#define ZEBRA_NEXTHOP_BLACKHOLE 9
#ifndef INADDR_LOOPBACK
#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
#endif
/* Address family numbers from RFC1700. */
#define AFI_IP 1
#define AFI_IP6 2
#define AFI_MAX 3
/* Subsequent Address Family Identifier. */
#define SAFI_UNICAST 1
#define SAFI_MULTICAST 2
#define SAFI_RESERVED_3 3
#define SAFI_MPLS_VPN 4
#define SAFI_MAX 5
/* Filter direction. */
#define FILTER_IN 0
#define FILTER_OUT 1
#define FILTER_MAX 2
/* Default Administrative Distance of each protocol. */
#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
#define ZEBRA_RIP_DISTANCE_DEFAULT 120
#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
/* Flag manipulation macros. */
#define CHECK_FLAG(V,F) ((V) & (F))
#define SET_FLAG(V,F) (V) |= (F)
#define UNSET_FLAG(V,F) (V) &= ~(F)
/* AFI and SAFI type. */
typedef u_int16_t afi_t;
typedef u_int8_t safi_t;
/* Zebra types. Used in Zserv message header. */
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 */