* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: build_msg.c,v 1.29 2005/03/10 20:43:13 kattemat Exp $
+ * $Id: build_msg.c,v 1.30 2005/05/30 13:13:37 kattemat Exp $
*/
#include "log.h"
#include "build_msg.h"
#include "local_hna_set.h"
+#include "mantissa.h"
#define BMSG_DBGLVL 5
/* Fill HELLO header */
h->willingness = message->willingness;
- h->htime = ifp->hello_etime;
+ h->htime = double_to_me(ifp->hello_etime);
memset(&h->reserved, 0, sizeof(olsr_u16_t));
/* Fill packet header */
h6->willingness = message->willingness;
- h6->htime = ifp->hello_etime;
+ h6->htime = double_to_me(ifp->hello_etime);
memset(&h6->reserved, 0, sizeof(olsr_u16_t));
/*
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: olsrd_conf.c,v 1.38 2005/05/28 19:30:47 kattemat Exp $
+ * $Id: olsrd_conf.c,v 1.39 2005/05/30 13:13:39 kattemat Exp $
*/
cnf->debug_level = DEF_DEBUGLVL;
cnf->no_fork = OLSR_FALSE;
+ cnf->host_emul = OLSR_FALSE;
cnf->ip_version = AF_INET;
cnf->allow_no_interfaces = DEF_ALLOW_NO_INTS;
cnf->tos = DEF_TOS;
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: ifnet.h,v 1.10 2005/02/15 20:40:31 kattemat Exp $
+ * $Id: ifnet.h,v 1.11 2005/05/30 13:13:37 kattemat Exp $
*/
/* Network interface configuration interface.
int
chk_if_up(struct olsr_if *, int);
+int
+add_hemu_if(struct olsr_if *);
+
#endif
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: interfaces.c,v 1.25 2005/05/29 12:47:45 br1 Exp $
+ * $Id: interfaces.c,v 1.26 2005/05/30 13:13:37 kattemat Exp $
*/
#include "defs.h"
#include "scheduler.h"
#include "olsr.h"
-
static olsr_u32_t if_property_id;
/* The interface linked-list */
}
OLSR_PRINTF(1, "\n ---- Interface configuration ---- \n\n")
- /* Run trough all interfaces immedeatly */
- for(tmp_if = olsr_cnf->interfaces; tmp_if != NULL; tmp_if = tmp_if->next)
- {
- chk_if_up(tmp_if, 1);
- }
+ /* Run trough all interfaces immedeatly */
+ for(tmp_if = olsr_cnf->interfaces; tmp_if != NULL; tmp_if = tmp_if->next)
+ {
+ if(!tmp_if->host_emul)
+ {
+ if(!olsr_cnf->host_emul) /* XXX: TEMPORARY! */
+ chk_if_up(tmp_if, 1);
+ }
+ else
+ add_hemu_if(tmp_if);
+ }
/* register network interface update function with scheduler */
olsr_register_scheduler_event(&check_interface_updates, NULL, IFCHANGES_POLL_INT, 0, NULL);
*
*@return nada
*/
-void
+struct olsr_if *
queue_if(char *name)
{
if(memcmp(interf_n->name, name, strlen(name)) == 0)
{
fprintf(stderr, "Duplicate interfaces defined... not adding %s\n", name);
- return;
+ return NULL;
}
interf_n = interf_n->next;
}
interf_n->next = olsr_cnf->interfaces;
olsr_cnf->interfaces = interf_n;
+ return interf_n;
}
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: interfaces.h,v 1.28 2005/05/29 12:47:45 br1 Exp $
+ * $Id: interfaces.h,v 1.29 2005/05/30 13:13:38 kattemat Exp $
*/
struct sockaddr_in6 int6_multaddr; /* Multicast */
/* IP independent */
union olsr_ip_addr ip_addr;
+ int is_hcif; /* Is this a emulated host-client if? */
int olsr_socket; /* The broadcast socket for this interface */
int int_metric; /* metric of interface */
int int_mtu; /* MTU of interface */
struct interface *
if_ifwithname(const char *);
-void
+struct olsr_if *
queue_if(char *);
int
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: link_set.c,v 1.59 2005/05/29 12:47:45 br1 Exp $
+ * $Id: link_set.c,v 1.60 2005/05/30 13:13:38 kattemat Exp $
*/
// find the interface for the link - we select the link with the
// best local interface metric
-
tmp_if = if_ifwithaddr(&walker->local_iface_addr);
if(!tmp_if)
*/
#ifdef DEBUG
- OLSR_PRINTF(3, "Adding %s to link set\n", olsr_ip_to_string(remote))
+ OLSR_PRINTF(1, "Adding %s=>%s to link set\n", olsr_ip_to_string(local), olsr_ip_to_string(remote))
#endif
/* a new tuple is created with... */
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: net.c,v 1.25 2005/05/17 23:53:01 kattemat Exp $
+ * $Id: net.c,v 1.26 2005/05/30 13:13:39 kattemat Exp $
*/
}
+/**
+ *Creates a nonblocking broadcast socket.
+ *@param sa sockaddr struct. Used for bind(2).
+ *@return the FD of the socket or -1 on error.
+ */
+int
+gethemusocket(struct sockaddr_in *pin)
+{
+ int sock, on = 1;
+
+ OLSR_PRINTF(1, " Connecting to switch daemon port 10150...");
+
+
+ if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ {
+ perror("hcsocket");
+ syslog(LOG_ERR, "hcsocket: %m");
+ return (-1);
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
+ {
+ perror("SO_REUSEADDR failed");
+ return (-1);
+ }
+ /* connect to PORT on HOST */
+ if (connect(sock,(struct sockaddr *) pin, sizeof(*pin)) < 0)
+ {
+ printf("FAILED\n");
+ fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno));
+ printf("connection refused\n");
+ return (-1);
+ }
+
+ printf("OK\n");
+
+ /* Keep TCP socket blocking */
+ return (sock);
+}
+
/**
*Creates a nonblocking broadcast socket.
return recvfrom(s,
buf,
len,
- 0,
+ flags,
from,
fromlen);
}
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: main.c,v 1.79 2005/05/23 18:26:33 kattemat Exp $
+ * $Id: main.c,v 1.80 2005/05/30 13:13:38 kattemat Exp $
*/
#include <unistd.h>
fprintf(stderr, " [-bcast <broadcastaddr>] [-ipc] [-dispin] [-dispout] [-delgw]\n");
fprintf(stderr, " [-hint <hello interval (secs)>] [-tcint <tc interval (secs)>]\n");
fprintf(stderr, " [-midint <mid interval (secs)>] [-hnaint <hna interval (secs)>]\n");
- fprintf(stderr, " [-T <Polling Rate (secs)>] [-nofork]\n");
+ fprintf(stderr, " [-T <Polling Rate (secs)>] [-nofork] [-hemu <ip_address>] \n");
}
continue;
}
+ /*
+ * Host emulation
+ */
+ if (strcmp(*argv, "-hemu") == 0)
+ {
+ struct in_addr in;
+ struct olsr_if *ifa;
+
+ NEXT_ARG;
+ CHECK_ARGC;
+ if(inet_pton(AF_INET, *argv, &in) < 0)
+ {
+ fprintf(stderr, "Failed converting IP address %s\n", *argv);
+ exit(EXIT_FAILURE);
+ }
+ /* Add hemu interface */
+
+ ifa = queue_if("hcif01");
+
+ if(!ifa)
+ continue;
+
+ ifa->cnf = get_default_if_config();
+ ifa->host_emul = OLSR_TRUE;
+ memcpy(&ifa->hemu_ip, &in, sizeof(union olsr_ip_addr));
+ cnf->host_emul = OLSR_TRUE;
+
+ continue;
+ }
+
/*
* Delete possible default GWs
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: net_olsr.c,v 1.2 2005/05/26 09:55:11 kattemat Exp $
+ * $Id: net_olsr.c,v 1.3 2005/05/30 13:13:38 kattemat Exp $
*/
#include "net_olsr.h"
static char *deny_ipv4_defaults[] =
{
"0.0.0.0",
- "127.0.0.1",
NULL
};
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: net_os.h,v 1.10 2005/03/04 21:30:16 kattemat Exp $
+ * $Id: net_os.h,v 1.11 2005/05/30 13:13:38 kattemat Exp $
*/
int
enable_ip_forwarding(int);
+int
+gethemusocket(struct sockaddr_in *);
+
int
getsocket(struct sockaddr *, int, char *);
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: olsr_cfg.h,v 1.24 2005/04/11 09:01:59 kattemat Exp $
+ * $Id: olsr_cfg.h,v 1.25 2005/05/30 13:13:38 kattemat Exp $
*/
char *config;
int index;
olsr_bool configured;
+ olsr_bool host_emul;
+ union olsr_ip_addr hemu_ip;
struct interface *interf;
struct if_config_options *cnf;
struct olsr_if *next;
{
int debug_level;
olsr_bool no_fork;
+ olsr_bool host_emul;
int ip_version;
olsr_bool allow_no_interfaces;
olsr_u16_t tos;
--- /dev/null
+
+CC ?= gcc
+BINNAME = olsr_switch
+INCLUDES += -I./..
+CFLAGS = -g $(INCLUDES)
+LDFLAGS =
+TOPDIR = ../../
+
+SRCS = $(wildcard *.c)
+HDRS = $(wildcard *.h)
+OBJS = $(patsubst %.c,%.o,$(SRCS))
+
+all: $(OBJS)
+ $(CC) $(LDFLAGS) -o $(TOPDIR)$(BINNAME) $(OBJS)
+
+clean:
+ rm -f *.o
+ rm -f *~
+ rm -f $(TOPDIR)$(BINNAME)
--- /dev/null
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2005, Andreas Tønnesen(andreto@olsr.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of olsr.org, olsrd 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ *
+ * Visit http://www.olsr.org for more information.
+ *
+ * If you find this software useful feel free to make a donation
+ * to the project. For more information see the website or contact
+ * the copyright holders.
+ *
+ * $Id: link_rules.c,v 1.1 2005/05/30 13:13:47 kattemat Exp $
+ */
+
+#include "link_rules.h"
+#include "olsr_host_switch.h"
+
+#define COMP_IP(ip1, ip2) (!memcmp(ip1, ip2, ipsize))
+
+
+int
+ohs_check_link(struct ohs_connection *oc, union olsr_ip_addr *dst)
+{
+ struct ohs_ip_link *links = oc->links;
+
+ while(links)
+ {
+ if(COMP_IP(&links->dst, dst))
+ {
+ return 0;
+ }
+
+ links = links->next;
+ }
+
+ return 1;
+}
--- /dev/null
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2005, Andreas Tønnesen(andreto@olsr.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of olsr.org, olsrd 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ *
+ * Visit http://www.olsr.org for more information.
+ *
+ * If you find this software useful feel free to make a donation
+ * to the project. For more information see the website or contact
+ * the copyright holders.
+ *
+ * $Id: link_rules.h,v 1.1 2005/05/30 13:13:47 kattemat Exp $
+ */
+
+
+
+#ifndef _OLSR_SWITCH_LINK_RULES
+#define _OLSR_SWITCH_LINK_RULES
+
+#include "olsr_types.h"
+#include "olsr_host_switch.h"
+int
+ohs_check_link(struct ohs_connection *, union olsr_ip_addr *);
+
+#endif
--- /dev/null
+
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2005, Andreas Tønnesen(andreto@olsr.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of olsr.org, olsrd 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ *
+ * Visit http://www.olsr.org for more information.
+ *
+ * If you find this software useful feel free to make a donation
+ * to the project. For more information see the website or contact
+ * the copyright holders.
+ *
+ * $Id: main.c,v 1.1 2005/05/30 13:13:47 kattemat Exp $
+ */
+
+/* olsrd host-switch daemon */
+
+#include "olsr_host_switch.h"
+#include "link_rules.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <signal.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+
+static int srv_socket;
+
+#define OHS_BUFSIZE 1500
+static olsr_u8_t data_buffer[OHS_BUFSIZE];
+
+static struct ohs_connection *ohs_conns;
+
+
+static int ip_version;
+int ipsize;
+static char ipv6_buf[100]; /* for address coversion */
+
+char *
+olsr_ip_to_string(union olsr_ip_addr *addr)
+{
+ static int index = 0;
+ static char buff[4][100];
+ char *ret;
+ struct in_addr in;
+
+ if(ip_version == AF_INET)
+ {
+ in.s_addr=addr->v4;
+ ret = inet_ntoa(in);
+ }
+ else
+ {
+ /* IPv6 */
+ ret = (char *)inet_ntop(AF_INET6, &addr->v6, ipv6_buf, sizeof(ipv6_buf));
+ }
+
+ strncpy(buff[index], ret, 100);
+
+ ret = buff[index];
+
+ index = (index + 1) & 3;
+
+ return ret;
+}
+
+
+static void
+ohs_close(int signal)
+{
+ printf("OHS: exit\n");
+
+ close(srv_socket);
+
+ exit(0);
+}
+
+
+int
+ohs_init_new_connection(int s)
+{
+ struct ohs_connection *oc;
+ olsr_u8_t new_addr[4];
+
+ printf("ohs_init_new_connection\n");
+
+ /* Create new client node */
+ oc = malloc(sizeof(struct ohs_connection));
+ if(!oc)
+ OHS_OUT_OF_MEMORY("New connection");
+
+ memset(oc, 0, sizeof(oc));
+
+ oc->socket = s;
+
+ oc->links = NULL;
+
+ /* Queue */
+ oc->next = ohs_conns;
+ ohs_conns = oc;
+
+ /* Get "fake IP" */
+ if(recv(oc->socket, new_addr, 4, 0) != 4)
+ {
+ printf("Failed to fetch IP address!\n");
+ return -1;
+ }
+ memcpy(&oc->ip_addr, new_addr, 4);
+ oc->ip_addr.v4 = ntohl(oc->ip_addr.v4);
+ printf("IP: %s\n", olsr_ip_to_string(&oc->ip_addr));
+}
+
+int
+ohs_delete_connection(struct ohs_connection *oc)
+{
+
+ /* Close the socket */
+ close(oc->socket);
+
+ printf("Removing entry %s\n", olsr_ip_to_string(&oc->ip_addr));
+ /* De-queue */
+ if(oc == ohs_conns)
+ {
+ ohs_conns = ohs_conns->next;
+ }
+ else
+ {
+ struct ohs_connection *curr_entry, *prev_entry;
+ curr_entry = ohs_conns->next;
+ prev_entry = ohs_conns;
+
+ while(curr_entry)
+ {
+ if(curr_entry == oc)
+ {
+ prev_entry->next = curr_entry->next;
+ break;
+ }
+ prev_entry = curr_entry;
+ curr_entry = curr_entry->next;
+ }
+ }
+ /* Free */
+ free(oc);
+}
+
+int
+ohs_route_data(struct ohs_connection *oc)
+{
+ struct ohs_connection *ohs_cs;
+ ssize_t len;
+
+ /* Read data */
+ if((len = recv(oc->socket, data_buffer, OHS_BUFSIZE, 0)) <= 0)
+ return -1;
+
+ printf("Received %d bytes from %s\n", len, olsr_ip_to_string(&oc->ip_addr));
+
+ /* Loop trough clients */
+ for(ohs_cs = ohs_conns; ohs_cs; ohs_cs = ohs_cs->next)
+ {
+ /* Check that the link is active open */
+ if(ohs_check_link(oc, &ohs_cs->ip_addr) &&
+ oc->socket != ohs_cs->socket)
+ {
+ ssize_t sent;
+
+ /* Send link addr */
+ if(send(ohs_cs->socket, oc->ip_addr.v6.s6_addr, ipsize, 0) != ipsize)
+ {
+ printf("Error sending link address!\n");
+ }
+ /* Send data */
+ printf("Sending %d bytes %s=>%s\n", len,
+ olsr_ip_to_string(&oc->ip_addr),
+ olsr_ip_to_string(&ohs_cs->ip_addr));
+
+ if((sent = send(ohs_cs->socket, data_buffer, len, 0)) != len)
+ {
+ printf("Error sending(buf %d != sent %d)\n", len, sent);
+ }
+ }
+ }
+
+
+}
+
+int
+ohs_init_connect_sockets()
+{
+ int i;
+ olsr_u32_t yes = 1;
+ struct sockaddr_in sin;
+
+ printf("Initiating socket TCP port %d\n", OHS_TCP_PORT);
+
+ if((srv_socket = socket(PF_INET, SOCK_STREAM, 0)) < 0)
+ {
+ printf("Could not initialize socket: %s\n", strerror(errno));
+ exit(0);
+ }
+
+ if(setsockopt(srv_socket, SOL_SOCKET, SO_REUSEADDR,
+ (char *)&yes, sizeof(yes)) < 0)
+ {
+ printf("SO_REUSEADDR failed for socket: %s\n", strerror(errno));
+ close(srv_socket);
+ exit(0);
+ }
+
+ /* complete the socket structure */
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = INADDR_ANY;
+ sin.sin_port = htons(OHS_TCP_PORT);
+
+ /* bind the socket to the port number */
+ if (bind(srv_socket, (struct sockaddr *) &sin, sizeof(sin)) == -1)
+ {
+ printf("bind failed for socket: %s\n", strerror(errno));
+ exit(0);
+ }
+
+ /* show that we are willing to listen */
+ if (listen(srv_socket, 5) == -1)
+ {
+ printf("listen failed for socket: %s\n", i, strerror(errno));
+ exit(0);
+ }
+
+}
+
+int
+ohs_configure()
+{
+
+}
+
+void
+ohs_listen_loop()
+{
+ int n;
+ fd_set ibits;
+
+ printf("ohs_listen_loop\n");
+
+ while(1)
+ {
+ int i, high;
+
+ struct ohs_connection *ohs_cs;
+
+ high = 0;
+ FD_ZERO(&ibits);
+
+ /* Add server socket */
+ high = srv_socket;
+ FD_SET(srv_socket, &ibits);
+
+ /* Add clients */
+ for(ohs_cs = ohs_conns; ohs_cs; ohs_cs = ohs_cs->next)
+ {
+ if(ohs_cs->socket > high)
+ high = ohs_cs->socket;
+
+ FD_SET(ohs_cs->socket, &ibits);
+ }
+
+ /* block */
+ n = select(high + 1, &ibits, 0, 0, NULL);
+
+ if(n == 0)
+ continue;
+
+ /* Did somethig go wrong? */
+ if (n < 0)
+ {
+ if(errno == EINTR)
+ continue;
+
+ printf("Error select: %s", strerror(errno));
+ continue;
+ }
+
+ /* Check server socket */
+ if(FD_ISSET(srv_socket, &ibits))
+ {
+ struct sockaddr_in pin;
+ socklen_t addrlen = sizeof(pin);
+ int s;
+
+ memset(&pin, 0 , sizeof(pin));
+
+ if((s = accept(srv_socket, (struct sockaddr *)&pin, &addrlen)) < 0)
+ {
+ printf("accept failed socket: %s\n", strerror(errno));
+ }
+ else
+ {
+ /* Create new node */
+ ohs_init_new_connection(s);
+ }
+ }
+ /* Loop trough clients */
+ ohs_cs = ohs_conns;
+ while(ohs_cs)
+ {
+ struct ohs_connection *ohs_tmp = ohs_cs;
+ ohs_cs = ohs_cs->next;
+
+ if(FD_ISSET(ohs_tmp->socket, &ibits))
+ {
+ if(ohs_route_data(ohs_tmp) < 0)
+ ohs_delete_connection(ohs_tmp);
+ }
+ }
+
+ }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("olsrd host-switch daemon version %s starting\n", OHS_VERSION);
+
+ ip_version = AF_INET;
+ ipsize = 4;
+
+ ohs_init_connect_sockets();
+
+ signal(SIGINT, ohs_close);
+ signal(SIGTERM, ohs_close);
+
+ ohs_configure();
+
+ ohs_listen_loop();
+
+ ohs_close(0);
+
+}
--- /dev/null
+/*
+ * The olsr.org Optimized Link-State Routing daemon(olsrd)
+ * Copyright (c) 2005, Andreas Tønnesen(andreto@olsr.org)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of olsr.org, olsrd 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ *
+ * Visit http://www.olsr.org for more information.
+ *
+ * If you find this software useful feel free to make a donation
+ * to the project. For more information see the website or contact
+ * the copyright holders.
+ *
+ * $Id: olsr_host_switch.h,v 1.1 2005/05/30 13:13:47 kattemat Exp $
+ */
+
+#ifndef _OLSR_HOST_SWITCH
+#define _OLSR_HOST_SWITCH
+
+#include "olsr_types.h"
+
+#define OHS_TCP_PORT 10150
+
+#define OHS_VERSION "0.1"
+
+#define OHS_OUT_OF_MEMORY(s) \
+ { printf("ohsd: out of memory \"%s\"!\n", s); ohs_close(0);}
+
+
+struct ohs_ip_link
+{
+ union olsr_ip_addr dst;
+ olsr_u8_t quality; /* 0 - 100 */
+ struct ohs_ip_link *next;
+};
+
+struct ohs_connection
+{
+ union olsr_ip_addr ip_addr;
+ int socket;
+ struct ohs_ip_link *links;
+ struct ohs_connection *next;
+};
+
+extern int ipsize;
+
+#endif
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: parser.c,v 1.24 2005/05/29 12:47:45 br1 Exp $
+ * $Id: parser.c,v 1.25 2005/05/30 13:13:38 kattemat Exp $
*/
#include "parser.h"
struct interface *olsr_in_if;
union olsr_ip_addr from_addr;
-
for (;;)
{
fromlen = sizeof(struct sockaddr_storage);
/* IPv6 sender address */
COPY_IP(&from_addr, &((struct sockaddr_in6 *)&from)->sin6_addr);
}
-
- /* are we talking to ourselves? */
- if(if_ifwithaddr(&from_addr) != NULL)
- return;
-
+
+
#ifdef DEBUG
OLSR_PRINTF(5, "Recieved a packet from %s\n", olsr_ip_to_string((union olsr_ip_addr *)&((struct sockaddr_in *)&from)->sin_addr.s_addr))
#endif
- //printf("\nCC: %d FROMLEN: %d\n\n", cc, fromlen);
- if ((olsr_cnf->ip_version == AF_INET) && (fromlen != sizeof (struct sockaddr_in)))
- break;
- else if ((olsr_cnf->ip_version == AF_INET6) && (fromlen != sizeof (struct sockaddr_in6)))
- break;
-
- //printf("Recieved data on socket %d\n", socknr);
-
-
+
+ if ((olsr_cnf->ip_version == AF_INET) && (fromlen != sizeof (struct sockaddr_in)))
+ break;
+ else if ((olsr_cnf->ip_version == AF_INET6) && (fromlen != sizeof (struct sockaddr_in6)))
+ break;
+
+ /* are we talking to ourselves? */
+ if(if_ifwithaddr(&from_addr) != NULL)
+ return;
+
if((olsr_in_if = if_ifwithsock(fd)) == NULL)
{
OLSR_PRINTF(1, "Could not find input interface for message from %s size %d\n",
}
+
+
+/**
+ *Processing OLSR data from socket. Reading data, setting
+ *wich interface recieved the message, Sends IPC(if used)
+ *and passes the packet on to parse_packet().
+ *
+ *@param fd the filedescriptor that data should be read from.
+ *@return nada
+ */
+void
+olsr_input_hostemu(int fd)
+{
+ /* sockaddr_in6 is bigger than sockaddr !!!! */
+ struct sockaddr_storage from;
+ size_t fromlen;
+ int cc;
+ struct interface *olsr_in_if;
+ union olsr_ip_addr from_addr;
+ olsr_u16_t pcklen;
+
+ /* Host emulator receives IP address first to emulate
+ direct link */
+
+ if((cc = recv(fd, from_addr.v6.s6_addr, ipsize, 0)) != (int)ipsize)
+ {
+ fprintf(stderr, "Error receiving host-client IP hook(%d) %s!\n", cc, strerror(errno));
+ COPY_IP(&from_addr, &((struct olsr *)inbuf)->olsr_msg->originator);
+ }
+
+ /* are we talking to ourselves? */
+ if(if_ifwithaddr(&from_addr) != NULL)
+ return;
+
+ /* Extract size */
+ if((cc = recv(fd, &pcklen, 2, MSG_PEEK)) != 2)
+ {
+ fprintf(stderr, "[hust-emu] error extracting size(%d) %s!\n", cc, strerror(errno));
+ return;
+ }
+ else
+ {
+ pcklen = ntohs(pcklen);
+ }
+
+ fromlen = sizeof(struct sockaddr_storage);
+
+ cc = olsr_recvfrom(fd,
+ inbuf,
+ pcklen,
+ 0,
+ (struct sockaddr *)&from,
+ &fromlen);
+
+ if (cc <= 0)
+ {
+ if (cc < 0 && errno != EWOULDBLOCK)
+ {
+ OLSR_PRINTF(1, "error recvfrom: %s", strerror(errno))
+ olsr_syslog(OLSR_LOG_ERR, "error recvfrom: %m");
+ }
+ return;
+ }
+
+ if(cc != pcklen)
+ {
+ printf("Could not read whole packet(size %d, read %d)\n", pcklen, cc);
+ return;
+ }
+
+ if((olsr_in_if = if_ifwithsock(fd)) == NULL)
+ {
+ OLSR_PRINTF(1, "Could not find input interface for message from %s size %d\n",
+ olsr_ip_to_string(&from_addr),
+ cc)
+ olsr_syslog(OLSR_LOG_ERR, "Could not find input interface for message from %s size %d\n",
+ olsr_ip_to_string(&from_addr),
+ cc);
+ return;
+ }
+
+ /*
+ * &from - sender
+ * &inbuf.olsr
+ * cc - bytes read
+ */
+ parse_packet((struct olsr *)inbuf, cc, olsr_in_if, &from_addr);
+
+}
+
+
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: parser.h,v 1.9 2005/05/29 12:47:45 br1 Exp $
+ * $Id: parser.h,v 1.10 2005/05/30 13:13:38 kattemat Exp $
*/
void
olsr_input(int);
+void
+olsr_input_hostemu(int);
+
void
olsr_parser_add_function(void (*)(union olsr_message *, struct interface *, union olsr_ip_addr *), olsr_u32_t, int);
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: process_routes.c,v 1.26 2005/05/29 12:47:45 br1 Exp $
+ * $Id: process_routes.c,v 1.27 2005/05/30 13:13:38 kattemat Exp $
*/
int metric_counter = 1;
olsr_bool last_run = OLSR_FALSE;
+
/* Find highest metric */
for(destination_ptr = delete_kernel_list;
destination_ptr != NULL;
olsr_ip_to_string(&destination_ptr->destination->rt_dst),
destination_ptr->destination->rt_metric)
#endif
-
- if(olsr_cnf->ip_version == AF_INET)
- error = olsr_ioctl_del_route(destination_ptr->destination);
- else
- error = olsr_ioctl_del_route6(destination_ptr->destination);
-
- if(error < 0)
- {
- OLSR_PRINTF(1, "Delete route(%s):%s\n", olsr_ip_to_string(&destination_ptr->destination->rt_dst), strerror(errno))
- olsr_syslog(OLSR_LOG_ERR, "Delete route:%m");
+ if(!olsr_cnf->host_emul)
+ {
+ if(olsr_cnf->ip_version == AF_INET)
+ error = olsr_ioctl_del_route(destination_ptr->destination);
+ else
+ error = olsr_ioctl_del_route6(destination_ptr->destination);
+
+ if(error < 0)
+ {
+ OLSR_PRINTF(1, "Delete route(%s):%s\n", olsr_ip_to_string(&destination_ptr->destination->rt_dst), strerror(errno))
+ olsr_syslog(OLSR_LOG_ERR, "Delete route:%m");
+ }
}
/* Getting rid of this node and hooking up the broken point */
destination_kernel->destination->rt_metric)
#endif
- if(olsr_cnf->ip_version == AF_INET)
- error=olsr_ioctl_add_route(destination_kernel->destination);
- else
- error=olsr_ioctl_add_route6(destination_kernel->destination);
-
- if(error < 0)
- {
- OLSR_PRINTF(1, "Add route(%s): %s\n", olsr_ip_to_string(&destination_kernel->destination->rt_dst), strerror(errno))
- olsr_syslog(OLSR_LOG_ERR, "Add route:%m");
- }
+ if(!olsr_cnf->host_emul)
+ {
+ if(olsr_cnf->ip_version == AF_INET)
+ error=olsr_ioctl_add_route(destination_kernel->destination);
+ else
+ error=olsr_ioctl_add_route6(destination_kernel->destination);
+
+ if(error < 0)
+ {
+ OLSR_PRINTF(1, "Add route(%s): %s\n", olsr_ip_to_string(&destination_kernel->destination->rt_dst), strerror(errno))
+ olsr_syslog(OLSR_LOG_ERR, "Add route:%m");
+ }
+ }
+
/* Getting rid of this node and hooking up the broken point */
if(destination_kernel == add_kernel_list)
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: ifnet.c,v 1.26 2005/05/17 23:44:26 kattemat Exp $
+ * $Id: ifnet.c,v 1.27 2005/05/30 13:13:47 kattemat Exp $
*/
for(tmp_if = olsr_cnf->interfaces; tmp_if != NULL; tmp_if = tmp_if->next)
{
+ if(tmp_if->host_emul)
+ continue;
+
+ if(olsr_cnf->host_emul) /* XXX: TEMPORARY! */
+ continue;
if(tmp_if->configured)
chk_if_changed(tmp_if);
goto remove_interface;
}
+ ifp->is_hcif = OLSR_FALSE;
/* trying to detect if interface is wireless. */
ifp->is_wireless = check_wireless_interface(ifr.ifr_name);
}
+/**
+ * Initializes the special interface used in
+ * host-client emulation
+ */
+int
+add_hemu_if(struct olsr_if *iface)
+{
+ struct interface *ifp;
+ union olsr_ip_addr null_addr;
+ olsr_u32_t addr[4];
+
+ if(!iface->host_emul)
+ return -1;
+
+ ifp = olsr_malloc(sizeof (struct interface), "Interface update 2");
+
+ memset(ifp, 0, sizeof (struct interface));
+
+ iface->configured = OLSR_TRUE;
+ iface->interf = ifp;
+
+ ifp->is_hcif = OLSR_TRUE;
+ ifp->int_name = olsr_malloc(strlen("hcif01") + 1, "Interface update 3");
+ ifp->int_metric = 0;
+
+ strcpy(ifp->int_name, "hcif01");
+
+ OLSR_PRINTF(1, "Adding %s(host emulation):\n", ifp->int_name)
+
+ OLSR_PRINTF(1, " Address:%s\n", olsr_ip_to_string(&iface->hemu_ip));
+
+ OLSR_PRINTF(1, " Index:%d\n", iface->index);
+
+ OLSR_PRINTF(1, " NB! This is a emulated interface\n that does not exist in the kernel!\n");
+
+ ifp->int_next = ifnet;
+ ifnet = ifp;
+
+ memset(&null_addr, 0, ipsize);
+ if(COMP_IP(&null_addr, &main_addr))
+ {
+ COPY_IP(&main_addr, &iface->hemu_ip);
+ OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&main_addr))
+ olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&main_addr));
+ }
+
+ /* setting the interfaces number*/
+ ifp->if_nr = iface->index;
+
+ ifp->int_mtu = OLSR_DEFAULT_MTU;
+
+ ifp->int_mtu -= (olsr_cnf->ip_version == AF_INET6) ? UDP_IPV6_HDRSIZE : UDP_IPV4_HDRSIZE;
+
+ /* Set up buffer */
+ net_add_buffer(ifp);
+
+
+ if(olsr_cnf->ip_version == AF_INET)
+ {
+ struct sockaddr_in sin;
+
+ memset(&sin, 0, sizeof(sin));
+
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ sin.sin_port = htons(10150);
+
+ /* IP version 4 */
+ ifp->ip_addr.v4 = iface->hemu_ip.v4;
+
+ memcpy(&((struct sockaddr_in *)&ifp->int_addr)->sin_addr, &iface->hemu_ip, ipsize);
+
+ /*
+ *We create one socket for each interface and bind
+ *the socket to it. This to ensure that we can control
+ *on what interface the message is transmitted
+ */
+
+ ifp->olsr_socket = gethemusocket(&sin);
+
+ if (ifp->olsr_socket < 0)
+ {
+ fprintf(stderr, "Could not initialize socket... exiting!\n\n");
+ olsr_syslog(OLSR_LOG_ERR, "Could not initialize socket... exiting!\n\n");
+ exit_value = EXIT_FAILURE;
+ kill(getpid(), SIGINT);
+ }
+ }
+ else
+ {
+ /* IP version 6 */
+ memcpy(&ifp->ip_addr, &iface->hemu_ip, ipsize);
+
+#if 0
+ /*
+ *We create one socket for each interface and bind
+ *the socket to it. This to ensure that we can control
+ *on what interface the message is transmitted
+ */
+
+ ifp->olsr_socket = gethcsocket6(&addrsock6, bufspace, ifp->int_name);
+
+ join_mcast(ifp, ifp->olsr_socket);
+
+ if (ifp->olsr_socket < 0)
+ {
+ fprintf(stderr, "Could not initialize socket... exiting!\n\n");
+ olsr_syslog(OLSR_LOG_ERR, "Could not initialize socket... exiting!\n\n");
+ exit_value = EXIT_FAILURE;
+ kill(getpid(), SIGINT);
+ }
+
+#endif
+ }
+
+ /* Send IP as first 4/16 bytes on socket */
+ memcpy(addr, iface->hemu_ip.v6.s6_addr, ipsize);
+ addr[0] = htonl(addr[0]);
+ addr[1] = htonl(addr[1]);
+ addr[2] = htonl(addr[2]);
+ addr[3] = htonl(addr[3]);
+
+ if(send(ifp->olsr_socket, addr , ipsize, 0) != (int)ipsize)
+ {
+ fprintf(stderr, "Error sending IP!");
+ }
+
+ /* Register socket */
+ add_olsr_socket(ifp->olsr_socket, &olsr_input_hostemu);
+
+
+ if (olsr_cnf->lq_level == 0)
+ {
+ olsr_register_scheduler_event(&generate_hello,
+ ifp,
+ iface->cnf->hello_params.emission_interval,
+ 0,
+ NULL);
+ olsr_register_scheduler_event(&generate_tc,
+ ifp,
+ iface->cnf->tc_params.emission_interval,
+ 0,
+ NULL);
+ }
+
+ else
+ {
+ olsr_register_scheduler_event(&olsr_output_lq_hello,
+ ifp,
+ iface->cnf->hello_params.emission_interval,
+ 0,
+ NULL);
+ olsr_register_scheduler_event(&olsr_output_lq_tc,
+ ifp,
+ iface->cnf->tc_params.emission_interval,
+ 0,
+ NULL);
+ }
+
+ olsr_register_scheduler_event(&generate_mid,
+ ifp,
+ iface->cnf->mid_params.emission_interval,
+ 0,
+ NULL);
+ olsr_register_scheduler_event(&generate_hna,
+ ifp,
+ iface->cnf->hna_params.emission_interval,
+ 0,
+ NULL);
+
+ /* Recalculate max jitter */
+
+ if((max_jitter == 0) || ((iface->cnf->hello_params.emission_interval / 4) < max_jitter))
+ max_jitter = iface->cnf->hello_params.emission_interval / 4;
+
+ /* Recalculate max topology hold time */
+ if(max_tc_vtime < iface->cnf->tc_params.emission_interval)
+ max_tc_vtime = iface->cnf->tc_params.emission_interval;
+
+ ifp->hello_etime = iface->cnf->hello_params.emission_interval;
+ ifp->valtimes.hello = double_to_me(iface->cnf->hello_params.validity_time);
+ ifp->valtimes.tc = double_to_me(iface->cnf->tc_params.validity_time);
+ ifp->valtimes.mid = double_to_me(iface->cnf->mid_params.validity_time);
+ ifp->valtimes.hna = double_to_me(iface->cnf->hna_params.validity_time);
+
+ return 1;
+}
/**
* Initializes a interface described by iface,
int tos_bits = IPTOS_TOS(olsr_cnf->tos);
#endif
+ if(iface->host_emul)
+ return -1;
+
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, iface->name, IFNAMSIZ);
return 0;
}
+ ifs.is_hcif = OLSR_FALSE;
+
/* trying to detect if interface is wireless. */
ifs.is_wireless = check_wireless_interface(ifr.ifr_name);
if(max_tc_vtime < iface->cnf->tc_params.emission_interval)
max_tc_vtime = iface->cnf->tc_params.emission_interval;
- ifp->hello_etime = double_to_me(iface->cnf->hello_params.emission_interval);
+ ifp->hello_etime = iface->cnf->hello_params.emission_interval;
ifp->valtimes.hello = double_to_me(iface->cnf->hello_params.validity_time);
ifp->valtimes.tc = double_to_me(iface->cnf->tc_params.validity_time);
ifp->valtimes.mid = double_to_me(iface->cnf->mid_params.validity_time);
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: ifnet.c,v 1.25 2005/05/26 21:04:22 kattemat Exp $
+ * $Id: ifnet.c,v 1.26 2005/05/30 13:13:48 kattemat Exp $
*/
#include "interfaces.h"
if(max_tc_vtime < IntConf->cnf->tc_params.emission_interval)
max_tc_vtime = IntConf->cnf->tc_params.emission_interval;
- New->hello_etime =
- double_to_me(IntConf->cnf->hello_params.emission_interval);
+ New->hello_etime = IntConf->cnf->hello_params.emission_interval;
New->valtimes.hello = double_to_me(IntConf->cnf->hello_params.validity_time);
New->valtimes.tc = double_to_me(IntConf->cnf->tc_params.validity_time);