mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-30 09:58:55 +00:00
cf9e0b4730
Whenever the daemon re-loads its config, it keeps any socket-based (AF_INET) SOCK_DGRAM interfaces open that are matched by the new config, but it used to close and then re-open all local (AF_UNIX) interfaces and file-based interfaces such as SOCK_FILE dummy files and SOCK_STREAM device files. This made it very difficult to develop the new 'routejava' test suite, because the Java API test harness always causes a config re-load when it sets the REST API user/password in the config, which caused the local socket interfaces to bounce, which interfered with the reachability of nodes. Now, local socket and file-based interfaces remain up after a config re-load, as long as they are still matched by the new configuration. Added INFO messages for interfaces that remain up after a config re-load, and tweak interface up/down INFO messages to be consistent.
157 lines
5.6 KiB
C
157 lines
5.6 KiB
C
/*
|
|
Serval DNA overlay network interfaces
|
|
Copyright (C) 2010 Paul Gardner-Stephen
|
|
Copyright (C) 2012-2013 Serval Project Inc.
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#ifndef __SERVAL_DNA__OVERLAY_INTERFACE_H
|
|
#define __SERVAL_DNA__OVERLAY_INTERFACE_H
|
|
|
|
#include "os.h" // for time_ms_t
|
|
#include "socket.h"
|
|
#include "limit.h"
|
|
|
|
#define INTERFACE_STATE_DOWN 0
|
|
#define INTERFACE_STATE_UP 1
|
|
|
|
struct overlay_interface;
|
|
|
|
// where should packets be sent to?
|
|
struct network_destination {
|
|
int _ref_count;
|
|
|
|
// which interface are we actually sending packets out of
|
|
struct overlay_interface *interface;
|
|
|
|
// The network destination address
|
|
// this may be the interface broadcast IP address
|
|
// but could be a unicast address
|
|
struct socket_address address;
|
|
|
|
// should outgoing packets be marked as unicast?
|
|
char unicast;
|
|
|
|
char packet_version;
|
|
|
|
struct config_mdp_iftype ifconfig;
|
|
|
|
// time last packet was sent
|
|
time_ms_t last_tx;
|
|
|
|
int min_rtt;
|
|
int max_rtt;
|
|
int resend_delay;
|
|
|
|
// sequence number of last packet sent to this destination.
|
|
// Used to allow NACKs that can request retransmission of recent packets.
|
|
int sequence_number;
|
|
int last_ack_seq;
|
|
|
|
// rate limit for outgoing packets
|
|
struct limit_state transfer_limit;
|
|
};
|
|
|
|
typedef struct overlay_interface {
|
|
struct sched_ent alarm;
|
|
|
|
// depending on ifconfig.socket_type (and address.addr.sa_family):
|
|
// - for SOCK_DGRAM (AF_INET): the interface name
|
|
// - for SOCK_DGRAM (AF_UNIX): the configured socket path (short, usually relative)
|
|
// - for SOCK_FILE: not used (zero filled)
|
|
// - for SOCK_STREAM: not used (zero filled)
|
|
// - for SOCK_EXT: not used (zero filled)
|
|
char name[256];
|
|
|
|
// depending on ifconfig.socket_type (and address.addr.sa_family):
|
|
// - for SOCK_DGRAM (AF_INET): not used (zero filled)
|
|
// - for SOCK_DGRAM (AF_UNIX): the local socket path (absolute)
|
|
// - for SOCK_FILE: the absolute path of the configured dummy file
|
|
// - for SOCK_STREAM: the absolute path of the configured device file
|
|
// - for SOCK_EXT: not used (zero filled)
|
|
char file_path[256];
|
|
|
|
short interface_type; // OVERLAY_INTERFACE_ETHERNET etc.
|
|
off_t recv_offset; /* file offset */
|
|
|
|
int recv_count;
|
|
int tx_count;
|
|
|
|
struct radio_link_state *radio_link_state;
|
|
|
|
struct config_network_interface ifconfig; // copy
|
|
|
|
char local_echo;
|
|
|
|
struct network_destination *destination;
|
|
|
|
struct subscriber *other_device;
|
|
|
|
// the actual address of the interface.
|
|
struct socket_address address;
|
|
|
|
struct in_addr netmask;
|
|
|
|
/* Use one of the INTERFACE_STATE_* constants to indicate the state of this interface.
|
|
If the interface stops working or disappears, it will be marked as DOWN and the socket closed.
|
|
But if it comes back up again, we should try to reuse this structure, even if the broadcast address has changed.
|
|
*/
|
|
int state;
|
|
} overlay_interface;
|
|
|
|
/* Maximum interface count is rather arbitrary.
|
|
Memory consumption is O(n) with respect to this parameter, so let's not make it too big for now.
|
|
*/
|
|
extern overlay_interface overlay_interfaces[OVERLAY_MAX_INTERFACES];
|
|
|
|
struct network_destination * new_destination(struct overlay_interface *interface);
|
|
struct network_destination * create_unicast_destination(struct socket_address *addr, struct overlay_interface *interface);
|
|
struct network_destination * add_destination_ref(struct network_destination *ref);
|
|
void release_destination_ref(struct network_destination *ref);
|
|
int set_destination_ref(struct network_destination **ptr, struct network_destination *ref);
|
|
|
|
struct config_mdp_iftype;
|
|
int overlay_destination_configure(struct network_destination *dest, const struct config_mdp_iftype *ifconfig);
|
|
|
|
struct config_network_interface;
|
|
int overlay_interface_configure(struct overlay_interface *interface, const struct config_network_interface *ifconfig);
|
|
|
|
int
|
|
overlay_interface_init(const char *name,
|
|
const char *file_path,
|
|
short detected_type,
|
|
const struct socket_address *addr,
|
|
const struct socket_address *netmask,
|
|
const struct socket_address *broadcast,
|
|
const struct config_network_interface *ifconfig);
|
|
void overlay_interface_close(overlay_interface *interface);
|
|
|
|
int overlay_interface_register(const char *name,
|
|
struct socket_address *addr,
|
|
const struct socket_address *netmask,
|
|
struct socket_address *broadcast);
|
|
overlay_interface * overlay_interface_get_default();
|
|
overlay_interface * overlay_interface_find(struct in_addr addr, int return_default);
|
|
overlay_interface * overlay_interface_find_name_file_addr(const char *name, const char *file_path, struct socket_address *addr);
|
|
int overlay_interface_compare(overlay_interface *one, overlay_interface *two);
|
|
int overlay_broadcast_ensemble(struct network_destination *destination, struct overlay_buffer *buffer);
|
|
void interface_state_html(struct strbuf *b, struct overlay_interface *interface);
|
|
void overlay_interface_monitor_up();
|
|
|
|
DECLARE_TRIGGER(iupdown, struct overlay_interface *, unsigned count);
|
|
|
|
#endif // __SERVAL_DNA__OVERLAY_INTERFACE_H
|