diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-03-09 15:43:22 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2006-03-09 15:43:22 +0000 |
commit | e4497c3c905ad1759e82776389c7203ad0db8cd6 (patch) | |
tree | 35ffda46762ffc7a23e40b595b0a871e1c3e52fc | |
parent | 9b974d6e64eaeae2c2b0581c685e30dd96b79e45 (diff) |
Move *_name functions to log.c and use these for both ospfd and ospfctl.
Stuff that is only used in ospfd debug messages is simplified.
OK norby@
-rw-r--r-- | usr.sbin/ospfd/interface.c | 70 | ||||
-rw-r--r-- | usr.sbin/ospfd/log.c | 113 | ||||
-rw-r--r-- | usr.sbin/ospfd/neighbor.c | 50 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfd.h | 74 | ||||
-rw-r--r-- | usr.sbin/ospfd/ospfe.h | 64 |
5 files changed, 183 insertions, 188 deletions
diff --git a/usr.sbin/ospfd/interface.c b/usr.sbin/ospfd/interface.c index fa2eaf4afd3..7bee9a1b0d9 100644 --- a/usr.sbin/ospfd/interface.c +++ b/usr.sbin/ospfd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.44 2006/03/09 13:37:04 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.45 2006/03/09 15:43:21 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -87,20 +87,6 @@ const char * const if_action_names[] = { "RESET" }; -const char * const if_type_names[] = { - "POINTOPOINT", - "BROADCAST", - "NBMA", - "POINTOMULTIPOINT", - "VIRTUALLINK" -}; - -const char * const if_auth_names[] = { - "none", - "simple", - "crypt" -}; - int if_fsm(struct iface *iface, enum iface_event event) { @@ -121,7 +107,7 @@ if_fsm(struct iface *iface, enum iface_event event) /* event outside of the defined fsm, ignore it. */ log_debug("if_fsm: interface %s, " "event %s not expected in state %s", iface->name, - if_event_name(event), if_state_name(old_state)); + if_event_names[event], if_state_name(old_state)); return (0); } @@ -142,7 +128,7 @@ if_fsm(struct iface *iface, enum iface_event event) if (ret) { log_debug("if_fsm: error changing state for interface %s, " - "event %s, state %s", iface->name, if_event_name(event), + "event %s, state %s", iface->name, if_event_names[event], if_state_name(old_state)); return (-1); } @@ -155,7 +141,7 @@ if_fsm(struct iface *iface, enum iface_event event) log_debug("if_fsm: event %s resulted in action %s and changing " "state for interface %s from %s to %s", - if_event_name(event), if_action_name(iface_fsm[i].action), + if_event_names[event], if_action_names[iface_fsm[i].action], iface->name, if_state_name(old_state), if_state_name(iface->state)); return (ret); @@ -694,54 +680,6 @@ if_to_ctl(struct iface *iface) return (&ictl); } -/* names */ -const char * -if_state_name(int state) -{ - switch (state) { - case IF_STA_DOWN: - return ("DOWN"); - case IF_STA_LOOPBACK: - return ("LOOPBACK"); - case IF_STA_WAITING: - return ("WAITING"); - case IF_STA_POINTTOPOINT: - return ("POINT-TO-POINT"); - case IF_STA_DROTHER: - return ("DROTHER"); - case IF_STA_BACKUP: - return ("BACKUP"); - case IF_STA_DR: - return ("DR"); - default: - return ("UNKNOWN"); - } -} - -const char * -if_event_name(int event) -{ - return (if_event_names[event]); -} - -const char * -if_action_name(int action) -{ - return (if_action_names[action]); -} - -const char * -if_type_name(int type) -{ - return (if_type_names[type]); -} - -const char * -if_auth_name(int type) -{ - return (if_auth_names[type]); -} - /* misc */ int if_set_mcast_ttl(int fd, u_int8_t ttl) diff --git a/usr.sbin/ospfd/log.c b/usr.sbin/ospfd/log.c index 6b198cbfbe9..14b90726c01 100644 --- a/usr.sbin/ospfd/log.c +++ b/usr.sbin/ospfd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.3 2006/03/08 15:36:28 claudio Exp $ */ +/* $OpenBSD: log.c,v 1.4 2006/03/09 15:43:21 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -162,3 +162,114 @@ fatalx(const char *emsg) fatal(emsg); } +/* names */ +const char * +nbr_state_name(int state) +{ + switch (state) { + case NBR_STA_DOWN: + return ("DOWN"); + case NBR_STA_ATTEMPT: + return ("ATTMP"); + case NBR_STA_INIT: + return ("INIT"); + case NBR_STA_2_WAY: + return ("2-WAY"); + case NBR_STA_XSTRT: + return ("EXSTA"); + case NBR_STA_SNAP: + return ("SNAP"); + case NBR_STA_XCHNG: + return ("EXCHG"); + case NBR_STA_LOAD: + return ("LOAD"); + case NBR_STA_FULL: + return ("FULL"); + default: + return ("UNKNW"); + } +} + +const char * +if_state_name(int state) +{ + switch (state) { + case IF_STA_DOWN: + return ("DOWN"); + case IF_STA_LOOPBACK: + return ("LOOP"); + case IF_STA_WAITING: + return ("WAIT"); + case IF_STA_POINTTOPOINT: + return ("P2P"); + case IF_STA_DROTHER: + return ("OTHER"); + case IF_STA_BACKUP: + return ("BCKUP"); + case IF_STA_DR: + return ("DR"); + default: + return ("UNKNW"); + } +} + +const char * +if_type_name(enum iface_type type) +{ + switch (type) { + case IF_TYPE_POINTOPOINT: + return ("POINTOPOINT"); + case IF_TYPE_BROADCAST: + return ("BROADCAST"); + case IF_TYPE_NBMA: + return ("NBMA"); + case IF_TYPE_POINTOMULTIPOINT: + return ("POINTOMULTIPOINT"); + case IF_TYPE_VIRTUALLINK: + return ("VIRTUALLINK"); + } + return ("UNKNOWN"); +} + +const char * +if_auth_name(enum auth_type type) +{ + switch (type) { + case AUTH_NONE: + return ("none"); + case AUTH_SIMPLE: + return ("simple"); + case AUTH_CRYPT: + return ("crypt"); + } + return ("unknown"); +} + +const char * +dst_type_name(enum dst_type type) +{ + switch (type) { + case DT_NET: + return ("Network"); + case DT_RTR: + return ("Router"); + } + return ("unknown"); +} + +const char * +path_type_name(enum path_type type) +{ + switch (type) { + case PT_INTRA_AREA: + return ("Intra-Area"); + case PT_INTER_AREA: + return ("Inter-Area"); + case PT_TYPE1_EXT: + return ("Type 1 ext"); + case PT_TYPE2_EXT: + return ("Type 2 ext"); + } + return ("unknown"); +} + diff --git a/usr.sbin/ospfd/neighbor.c b/usr.sbin/ospfd/neighbor.c index b703e7da138..e19c521124e 100644 --- a/usr.sbin/ospfd/neighbor.c +++ b/usr.sbin/ospfd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.30 2006/02/19 21:48:56 norby Exp $ */ +/* $OpenBSD: neighbor.c,v 1.31 2006/03/09 15:43:21 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -137,7 +137,7 @@ nbr_fsm(struct nbr *nbr, enum nbr_event event) /* XXX event outside of the defined fsm, ignore it. */ log_warnx("nbr_fsm: neighbor ID %s, " "event %s not expected in state %s", - inet_ntoa(nbr->id), nbr_event_name(event), + inet_ntoa(nbr->id), nbr_event_names[event], nbr_state_name(old_state)); return (0); } @@ -185,7 +185,7 @@ nbr_fsm(struct nbr *nbr, enum nbr_event event) if (ret) { log_warnx("nbr_fsm: error changing state for neighbor ID %s, " "event %s, state %s", inet_ntoa(nbr->id), - nbr_event_name(event), nbr_state_name(old_state)); + nbr_event_names[event], nbr_state_name(old_state)); return (-1); } @@ -218,8 +218,8 @@ nbr_fsm(struct nbr *nbr, enum nbr_event event) log_debug("nbr_fsm: event %s resulted in action %s and " "changing state for neighbor ID %s from %s to %s", - nbr_event_name(event), - nbr_action_name(nbr_fsm_tbl[i].action), + nbr_event_names[event], + nbr_action_names[nbr_fsm_tbl[i].action], inet_ntoa(nbr->id), nbr_state_name(old_state), nbr_state_name(nbr->state)); @@ -697,46 +697,6 @@ nbr_to_ctl(struct nbr *nbr) return (&nctl); } -/* names */ -const char * -nbr_state_name(int state) -{ - switch (state) { - case NBR_STA_DOWN: - return ("DOWN"); - case NBR_STA_ATTEMPT: - return ("ATTEMPT"); - case NBR_STA_INIT: - return ("INIT"); - case NBR_STA_2_WAY: - return ("2-WAY"); - case NBR_STA_XSTRT: - return ("EXSTART"); - case NBR_STA_SNAP: - return ("SNAPSHOT"); - case NBR_STA_XCHNG: - return ("EXCHANGE"); - case NBR_STA_LOAD: - return ("LOADING"); - case NBR_STA_FULL: - return ("FULL"); - default: - return ("UNKNOWN"); - } -} - -const char * -nbr_event_name(int event) -{ - return (nbr_event_names[event]); -} - -const char * -nbr_action_name(int action) -{ - return (nbr_action_names[action]); -} - struct lsa_hdr * lsa_hdr_new(void) { diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h index 2fb88807bd0..1829da5ba12 100644 --- a/usr.sbin/ospfd/ospfd.h +++ b/usr.sbin/ospfd/ospfd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfd.h,v 1.49 2006/03/09 09:43:03 claudio Exp $ */ +/* $OpenBSD: ospfd.h,v 1.50 2006/03/09 15:43:21 claudio Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -220,6 +220,58 @@ enum iface_type { IF_TYPE_VIRTUALLINK }; +/* neighbor states */ +#define NBR_STA_DOWN 0x0001 +#define NBR_STA_ATTEMPT 0x0002 +#define NBR_STA_INIT 0x0004 +#define NBR_STA_2_WAY 0x0008 +#define NBR_STA_XSTRT 0x0010 +#define NBR_STA_SNAP 0x0020 +#define NBR_STA_XCHNG 0x0040 +#define NBR_STA_LOAD 0x0080 +#define NBR_STA_FULL 0x0100 +#define NBR_STA_ACTIVE (~NBR_STA_DOWN) +#define NBR_STA_FLOOD (NBR_STA_XCHNG | NBR_STA_LOAD | NBR_STA_FULL) +#define NBR_STA_ADJFORM (NBR_STA_XSTRT | NBR_STA_SNAP | NBR_STA_FLOOD) +#define NBR_STA_BIDIR (NBR_STA_2_WAY | NBR_STA_ADJFORM) +#define NBR_STA_PRELIM (NBR_STA_DOWN | NBR_STA_ATTEMPT | NBR_STA_INIT) +#define NBR_STA_ANY 0xffff + +/* neighbor events */ +enum nbr_event { + NBR_EVT_NOTHING, + NBR_EVT_HELLO_RCVD, + NBR_EVT_2_WAY_RCVD, + NBR_EVT_NEG_DONE, + NBR_EVT_SNAP_DONE, + NBR_EVT_XCHNG_DONE, + NBR_EVT_BAD_LS_REQ, + NBR_EVT_LOAD_DONE, + NBR_EVT_ADJ_OK, + NBR_EVT_SEQ_NUM_MIS, + NBR_EVT_1_WAY_RCVD, + NBR_EVT_KILL_NBR, + NBR_EVT_ITIMER, + NBR_EVT_LL_DOWN, + NBR_EVT_ADJTMOUT +}; + +/* neighbor actions */ +enum nbr_action { + NBR_ACT_NOTHING, + NBR_ACT_RST_ITIMER, + NBR_ACT_STRT_ITIMER, + NBR_ACT_EVAL, + NBR_ACT_SNAP, + NBR_ACT_SNAP_DONE, + NBR_ACT_XCHNG_DONE, + NBR_ACT_ADJ_OK, + NBR_ACT_RESTRT_DD, + NBR_ACT_DEL, + NBR_ACT_CLR_LST, + NBR_ACT_HELLO_CHK +}; + /* auth types */ enum auth_type { AUTH_NONE, @@ -240,11 +292,6 @@ enum dst_type { DT_RTR }; -static const char * const dst_type_names[] = { - "Network", - "Router" -}; - enum path_type { PT_INTRA_AREA, PT_INTER_AREA, @@ -258,13 +305,6 @@ enum rib_type { RIB_EXT }; -static const char * const path_type_names[] = { - "Intra-Area", - "Inter-Area", - "Type 1 ext", - "Type 2 ext" -}; - struct auth_md { TAILQ_ENTRY(auth_md) entry; char key[MD5_DIGEST_LENGTH]; @@ -506,6 +546,14 @@ struct kif *kif_findname(char *); u_int8_t mask2prefixlen(in_addr_t); in_addr_t prefixlen2mask(u_int8_t); +/* log.h */ +const char *nbr_state_name(int); +const char *if_state_name(int); +const char *if_type_name(enum iface_type); +const char *if_auth_name(enum auth_type); +const char *dst_type_name(enum dst_type); +const char *path_type_name(enum path_type); + /* ospfd.c */ void main_imsg_compose_ospfe(int, pid_t, void *, u_int16_t); void main_imsg_compose_rde(int, pid_t, void *, u_int16_t); diff --git a/usr.sbin/ospfd/ospfe.h b/usr.sbin/ospfd/ospfe.h index 15c3a6d9690..b61812265b4 100644 --- a/usr.sbin/ospfd/ospfe.h +++ b/usr.sbin/ospfd/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.25 2006/03/09 13:31:57 claudio Exp $ */ +/* $OpenBSD: ospfe.h,v 1.26 2006/03/09 15:43:21 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -29,58 +29,6 @@ TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; -/* neighbor states */ -#define NBR_STA_DOWN 0x0001 -#define NBR_STA_ATTEMPT 0x0002 -#define NBR_STA_INIT 0x0004 -#define NBR_STA_2_WAY 0x0008 -#define NBR_STA_XSTRT 0x0010 -#define NBR_STA_SNAP 0x0020 -#define NBR_STA_XCHNG 0x0040 -#define NBR_STA_LOAD 0x0080 -#define NBR_STA_FULL 0x0100 -#define NBR_STA_ACTIVE (~NBR_STA_DOWN) -#define NBR_STA_FLOOD (NBR_STA_XCHNG | NBR_STA_LOAD | NBR_STA_FULL) -#define NBR_STA_ADJFORM (NBR_STA_XSTRT | NBR_STA_SNAP | NBR_STA_FLOOD) -#define NBR_STA_BIDIR (NBR_STA_2_WAY | NBR_STA_ADJFORM) -#define NBR_STA_PRELIM (NBR_STA_DOWN | NBR_STA_ATTEMPT | NBR_STA_INIT) -#define NBR_STA_ANY 0xffff - -/* neighbor events */ -enum nbr_event { - NBR_EVT_NOTHING, - NBR_EVT_HELLO_RCVD, - NBR_EVT_2_WAY_RCVD, - NBR_EVT_NEG_DONE, - NBR_EVT_SNAP_DONE, - NBR_EVT_XCHNG_DONE, - NBR_EVT_BAD_LS_REQ, - NBR_EVT_LOAD_DONE, - NBR_EVT_ADJ_OK, - NBR_EVT_SEQ_NUM_MIS, - NBR_EVT_1_WAY_RCVD, - NBR_EVT_KILL_NBR, - NBR_EVT_ITIMER, - NBR_EVT_LL_DOWN, - NBR_EVT_ADJTMOUT -}; - -/* neighbor actions */ -enum nbr_action { - NBR_ACT_NOTHING, - NBR_ACT_RST_ITIMER, - NBR_ACT_STRT_ITIMER, - NBR_ACT_EVAL, - NBR_ACT_SNAP, - NBR_ACT_SNAP_DONE, - NBR_ACT_XCHNG_DONE, - NBR_ACT_ADJ_OK, - NBR_ACT_RESTRT_DD, - NBR_ACT_DEL, - NBR_ACT_CLR_LST, - NBR_ACT_HELLO_CHK -}; - struct lsa_entry { TAILQ_ENTRY(lsa_entry) entry; union { @@ -195,12 +143,6 @@ int if_act_reset(struct iface *); struct ctl_iface *if_to_ctl(struct iface *); -const char *if_state_name(int); -const char *if_event_name(int); -const char *if_action_name(int); -const char *if_type_name(int); -const char *if_auth_name(int); - int if_join_group(struct iface *, struct in_addr *); int if_leave_group(struct iface *, struct in_addr *); int if_set_mcast(struct iface *); @@ -285,10 +227,6 @@ int nbr_act_hello_check(struct nbr *); struct ctl_nbr *nbr_to_ctl(struct nbr *); -const char *nbr_state_name(int); -const char *nbr_event_name(int); -const char *nbr_action_name(int); - struct lsa_hdr *lsa_hdr_new(void); /* packet.c */ |