#define UDP_IPV4_HDRSIZE 28
#define UDP_IPV6_HDRSIZE 62
-#if __GNUC__
-extern FILE *EXPORT(debug_handle);
-#endif
-
#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))
#ifndef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#endif
};
-/**
- * defines the severity of a logging event
- */
-enum log_severity {
- SEVERITY_DEBUG, //!< SEVERITY_DEBUG
- SEVERITY_INFO, //!< SEVERITY_INFO
- SEVERITY_WARN, //!< SEVERITY_WARN
- SEVERITY_ERR, //!< SEVERITY_ERR
-
- /* this one must be the last of the enums ! */
- LOG_SEVERITY_COUNT //!< LOG_SEVERITY_COUNT
-};
-
-extern volatile enum app_state app_state;
+extern enum app_state app_state;
#endif
/* Global stuff externed in olsr_cfg.h */
struct olsr_config *olsr_cnf; /* The global configuration */
-volatile enum app_state app_state = STATE_INIT;
+enum app_state app_state = STATE_INIT;
static char copyright_string[] __attribute__ ((unused)) =
"The olsr.org Optimized Link-State Routing daemon(olsrd) Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org) All rights reserved.";
bool changes_hna;
bool changes_force;
-/**
- * Process changes functions
- */
-
-struct pcf {
- int (*function) (int, int, int);
- struct pcf *next;
-};
-
-static struct pcf *pcf_list;
-
static uint16_t message_seqno;
/**
return message_seqno++;
}
-
-void
-register_pcf(int (*f) (int, int, int))
-{
- struct pcf *new_pcf;
-
- OLSR_DEBUG(LOG_MAIN, "Registering pcf function\n");
-
- new_pcf = olsr_malloc(sizeof(struct pcf), "New PCF");
-
- new_pcf->function = f;
- new_pcf->next = pcf_list;
- pcf_list = new_pcf;
-
-}
-
-
/**
*Process changes in neighborhood or/and topology.
*Re-calculates the neighborhood/topology if there
void
olsr_process_changes(void)
{
- struct pcf *tmp_pc_list;
-
if (changes_neighborhood)
OLSR_DEBUG(LOG_MAIN, "CHANGES IN NEIGHBORHOOD\n");
if (changes_topology)
olsr_print_duplicate_table();
olsr_print_hna_set();
- for (tmp_pc_list = pcf_list; tmp_pc_list != NULL; tmp_pc_list = tmp_pc_list->next) {
- tmp_pc_list->function(changes_neighborhood, changes_topology, changes_hna);
- }
-
changes_neighborhood = false;
changes_topology = false;
changes_hna = false;
/**
* Shared code to write the message header
*/
-uint8_t *olsr_put_msg_hdr(uint8_t **curr, struct olsr_message *msg)
+uint8_t *
+olsr_put_msg_hdr(uint8_t **curr, struct olsr_message *msg)
{
uint8_t *sizeptr;
return sizeptr;
}
-/**
- *Check if a message is to be forwarded and forward
- *it if necessary.
- *
- *@param m the OLSR message recieved
- *
- *@returns positive if forwarded
- */
-int
-olsr_forward_message(struct olsr_message *msg, uint8_t *binary, struct interface *in_if, union olsr_ip_addr *from_addr)
-{
- union olsr_ip_addr *src;
- struct nbr_entry *neighbor;
- struct interface *ifn, *iterator;
- uint8_t *tmp;
-#if !defined REMOVE_LOG_DEBUG
- struct ipaddr_str buf;
-#endif
-
- /* Lookup sender address */
- src = olsr_lookup_main_addr_by_alias(from_addr);
- if (!src)
- src = from_addr;
-
- neighbor = olsr_lookup_nbr_entry(src, true);
- if (!neighbor) {
- OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because no nbr entry found for %s\n",
- msg->type, olsr_ip_to_string(&buf, src));
- return 0;
- }
- if (!neighbor->is_sym) {
- OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because received by non-symmetric neighbor %s\n",
- msg->type, olsr_ip_to_string(&buf, src));
- return 0;
- }
-
- /* Check MPR */
- if (neighbor->mprs_count == 0) {
- OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because we are no MPR for %s\n",
- msg->type, olsr_ip_to_string(&buf, src));
- /* don't forward packages if not a MPR */
- return 0;
- }
-
- /* check if we already forwarded this message */
- if (olsr_is_duplicate_message(msg, true, NULL)) {
- OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d from %s because we already forwarded it.\n",
- msg->type, olsr_ip_to_string(&buf, src));
- return 0; /* it's a duplicate, forget about it */
- }
-
- /* Treat TTL hopcnt */
- msg->hopcnt++;
- msg->ttl--;
- tmp = binary;
- olsr_put_msg_hdr(&tmp, msg);
-
- if (msg->ttl == 0) {
- OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d from %s because TTL is 0.\n",
- msg->type, olsr_ip_to_string(&buf, src));
- return 0; /* TTL 0, forget about it */
- }
- OLSR_DEBUG(LOG_PACKET_PARSING, "Forwarding message type %d from %s.\n",
- msg->type, olsr_ip_to_string(&buf, src));
-
- /* looping trough interfaces */
- OLSR_FOR_ALL_INTERFACES(ifn, iterator) {
- if (net_output_pending(ifn)) {
- /* dont forward to incoming interface if interface is mode ether */
- if (in_if->mode == IF_MODE_ETHER && ifn == in_if)
- continue;
-
- /*
- * Check if message is to big to be piggybacked
- */
- if (net_outbuffer_push(ifn, binary, msg->size) != msg->size) {
- /* Send */
- net_output(ifn);
- /* Buffer message */
- set_buffer_timer(ifn);
-
- if (net_outbuffer_push(ifn, binary, msg->size) != msg->size) {
- OLSR_WARN(LOG_NETWORKING, "Received message to big to be forwarded in %s(%d bytes)!", ifn->int_name, msg->size);
- }
- }
- } else {
- /* No forwarding pending */
- set_buffer_timer(ifn);
-
- if (net_outbuffer_push(ifn, binary, msg->size) != msg->size) {
- OLSR_WARN(LOG_NETWORKING, "Received message to big to be forwarded in %s(%d bytes)!", ifn->int_name, msg->size);
- }
- }
- }
-
- return 1;
-}
-
static void
olsr_update_willingness(void *foo __attribute__ ((unused)))
{
olsr_cnf->willingness, olsr_milli_to_txt(&tbuf, olsr_cnf->will_int));
}
-const char *
-olsr_msgtype_to_string(uint8_t msgtype)
-{
- static char type[20];
-
- switch (msgtype) {
- case (HELLO_MESSAGE):
- return "HELLO";
- case (TC_MESSAGE):
- return "TC";
- case (MID_MESSAGE):
- return "MID";
- case (HNA_MESSAGE):
- return "HNA";
- case (LQ_HELLO_MESSAGE):
- return ("LQ-HELLO");
- case (LQ_TC_MESSAGE):
- return ("LQ-TC");
- default:
- break;
- }
-
- snprintf(type, sizeof(type), "UNKNOWN(%d)", msgtype);
- return type;
-}
-
-
-const char *
-olsr_link_to_string(uint8_t linktype)
-{
- static char type[20];
-
- switch (linktype) {
- case (UNSPEC_LINK):
- return "UNSPEC";
- case (ASYM_LINK):
- return "ASYM";
- case (SYM_LINK):
- return "SYM";
- case (LOST_LINK):
- return "LOST";
- default:
- break;
- }
-
- snprintf(type, sizeof(type), "UNKNOWN(%d)", linktype);
- return type;
-}
-
-
-const char *
-olsr_status_to_string(uint8_t status)
-{
- static char type[20];
-
- switch (status) {
- case (NOT_NEIGH):
- return "NOT NEIGH";
- case (SYM_NEIGH):
- return "NEIGHBOR";
- case (MPR_NEIGH):
- return "MPR";
- default:
- break;
- }
-
- snprintf(type, sizeof(type), "UNKNOWN(%d)", status);
- return type;
-}
-
-
/**
*Termination function to be called whenever a error occures
*that requires the daemon to terminate
extern bool changes_hna;
extern bool changes_force; /* Maybe static */
-void
- register_pcf(int (*)(int, int, int));
+void olsr_process_changes(void);
-void
- olsr_process_changes(void);
-
-void
- init_msg_seqno(void);
+void init_msg_seqno(void);
uint16_t EXPORT(get_msg_seqno) (void);
uint8_t *EXPORT(olsr_put_msg_hdr)(uint8_t **curr, struct olsr_message *msg);
-int
- olsr_forward_message(struct olsr_message *, uint8_t *binary, struct interface *, union olsr_ip_addr *);
-
-void
- olsr_init_tables(void);
+void olsr_init_tables(void);
-void
- olsr_init_willingness(void);
+void olsr_init_willingness(void);
void olsr_calculate_willingness(void);
-const char *olsr_msgtype_to_string(uint8_t);
-
-const char *olsr_link_to_string(uint8_t);
-
-const char *olsr_status_to_string(uint8_t);
-
-void
- EXPORT(olsr_exit) (int);
+void EXPORT(olsr_exit) (int);
void *EXPORT(olsr_malloc) (size_t, const char *);
#define LOGBUFFER_SIZE 1024
#define MAX_LOG_HANDLER 8
+/**
+ * defines the severity of a logging event
+ */
+enum log_severity {
+ SEVERITY_DEBUG, //!< SEVERITY_DEBUG
+ SEVERITY_INFO, //!< SEVERITY_INFO
+ SEVERITY_WARN, //!< SEVERITY_WARN
+ SEVERITY_ERR, //!< SEVERITY_ERR
+
+ /* this one must be the last of the enums ! */
+ LOG_SEVERITY_COUNT //!< LOG_SEVERITY_COUNT
+};
+
/**
* these four macros should be used to generate OLSR logging output
*
static struct preprocessor_function_entry *preprocessor_functions = NULL;
static struct packetparser_function_entry *packetparser_functions = NULL;
+static int olsr_forward_message(struct olsr_message *msg,
+ uint8_t *binary, struct interface *in_if, union olsr_ip_addr *from_addr);
+
/**
*Initialize the parser.
*
}
}
+/**
+ *Check if a message is to be forwarded and forward
+ *it if necessary.
+ *
+ *@param m the OLSR message recieved
+ *
+ *@returns positive if forwarded
+ */
+static int
+olsr_forward_message(struct olsr_message *msg, uint8_t *binary, struct interface *in_if, union olsr_ip_addr *from_addr)
+{
+ union olsr_ip_addr *src;
+ struct nbr_entry *neighbor;
+ struct interface *ifn, *iterator;
+ uint8_t *tmp;
+#if !defined REMOVE_LOG_DEBUG
+ struct ipaddr_str buf;
+#endif
+
+ /* Lookup sender address */
+ src = olsr_lookup_main_addr_by_alias(from_addr);
+ if (!src)
+ src = from_addr;
+
+ neighbor = olsr_lookup_nbr_entry(src, true);
+ if (!neighbor) {
+ OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because no nbr entry found for %s\n",
+ msg->type, olsr_ip_to_string(&buf, src));
+ return 0;
+ }
+ if (!neighbor->is_sym) {
+ OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because received by non-symmetric neighbor %s\n",
+ msg->type, olsr_ip_to_string(&buf, src));
+ return 0;
+ }
+
+ /* Check MPR */
+ if (neighbor->mprs_count == 0) {
+ OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d because we are no MPR for %s\n",
+ msg->type, olsr_ip_to_string(&buf, src));
+ /* don't forward packages if not a MPR */
+ return 0;
+ }
+
+ /* check if we already forwarded this message */
+ if (olsr_is_duplicate_message(msg, true, NULL)) {
+ OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d from %s because we already forwarded it.\n",
+ msg->type, olsr_ip_to_string(&buf, src));
+ return 0; /* it's a duplicate, forget about it */
+ }
+
+ /* Treat TTL hopcnt */
+ msg->hopcnt++;
+ msg->ttl--;
+ tmp = binary;
+ olsr_put_msg_hdr(&tmp, msg);
+
+ if (msg->ttl == 0) {
+ OLSR_DEBUG(LOG_PACKET_PARSING, "Not forwarding message type %d from %s because TTL is 0.\n",
+ msg->type, olsr_ip_to_string(&buf, src));
+ return 0; /* TTL 0, forget about it */
+ }
+ OLSR_DEBUG(LOG_PACKET_PARSING, "Forwarding message type %d from %s.\n",
+ msg->type, olsr_ip_to_string(&buf, src));
+
+ /* looping trough interfaces */
+ OLSR_FOR_ALL_INTERFACES(ifn, iterator) {
+ if (net_output_pending(ifn)) {
+ /* dont forward to incoming interface if interface is mode ether */
+ if (in_if->mode == IF_MODE_ETHER && ifn == in_if)
+ continue;
+
+ /*
+ * Check if message is to big to be piggybacked
+ */
+ if (net_outbuffer_push(ifn, binary, msg->size) != msg->size) {
+ /* Send */
+ net_output(ifn);
+ /* Buffer message */
+ set_buffer_timer(ifn);
+
+ if (net_outbuffer_push(ifn, binary, msg->size) != msg->size) {
+ OLSR_WARN(LOG_NETWORKING, "Received message to big to be forwarded in %s(%d bytes)!", ifn->int_name, msg->size);
+ }
+ }
+ } else {
+ /* No forwarding pending */
+ set_buffer_timer(ifn);
+
+ if (net_outbuffer_push(ifn, binary, msg->size) != msg->size) {
+ OLSR_WARN(LOG_NETWORKING, "Received message to big to be forwarded in %s(%d bytes)!", ifn->int_name, msg->size);
+ }
+ }
+ }
+
+ return 1;
+}
+
/*
* Local Variables:
* c-basic-offset: 2