net-snk: Move global variable definition out of the header file

The IPv6 code declares a bunch of global variables (without "extern"
keyword!) in the ipv6.h header file. This is bad style and does not
work when linking with "-fno-common" for example. So let's move
the variables to the files where they are used instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
This commit is contained in:
Thomas Huth 2016-01-14 00:10:37 +01:00 committed by Alexey Kardashevskiy
parent a9aa48d28a
commit 9308463cfd
6 changed files with 38 additions and 33 deletions

View File

@ -27,6 +27,8 @@ static uint8_t tid[3];
static uint32_t dhcpv6_state = -1;
static filename_ip_t *my_fn_ip;
static struct ip6addr_list_entry all_dhcpv6_ll; /* All DHCPv6 servers address */
void
dhcpv6_generate_transaction_id(void)
{
@ -115,6 +117,9 @@ dhcpv6 ( char *ret_buffer, void *fn_ip)
{
int fd;
all_dhcpv6_ll.addr.part.prefix = 0xff02000000000000ULL;
all_dhcpv6_ll.addr.part.interface_id = 0x10002ULL;
my_fn_ip = (filename_ip_t *) fn_ip;
fd = my_fn_ip->fd;

View File

@ -40,9 +40,8 @@ send_router_solicitation (int fd)
sizeof(struct ip6hdr));
/* Destination is "All routers multicast address" (link-local) */
dest_addr.part.prefix = all_routers_ll.addr.part.prefix;
dest_addr.part.interface_id = all_routers_ll.addr.part.interface_id;
dest_addr.part.prefix = 0xff02000000000000ULL;
dest_addr.part.interface_id = 2;
/* Fill IPv6 header */
fill_ip6hdr (ether_packet + sizeof(struct ethhdr),

View File

@ -37,15 +37,23 @@ static int ip6_is_multicast (ip6_addr_t * ip);
/****************************** LOCAL VARIABLES **************************/
/* List of Ipv6 Addresses */
static struct ip6addr_list_entry *first_ip6;
static struct ip6addr_list_entry *last_ip6;
/* Own IPv6 address */
static struct ip6addr_list_entry *own_ip6;
/* All nodes link-local address */
struct ip6addr_list_entry all_nodes_ll;
/* Null IPv6 address */
static ip6_addr_t null_ip6;
/* helper variables */
static uint8_t null_mac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
struct ip6_config ip6_state;
/****************************** IMPLEMENTATION ***************************/
@ -365,21 +373,9 @@ ipv6_init (int fd)
/* Multicast addresses */
all_nodes_ll.addr.part.prefix = 0xff02000000000000;
all_nodes_ll.addr.part.interface_id = 1;
all_dhcpv6_ll.addr.part.prefix = 0xff02000000000000ULL;
all_dhcpv6_ll.addr.part.interface_id = 0x10002ULL;
all_routers_ll.addr.part.prefix = 0xff02000000000000;
all_routers_ll.addr.part.interface_id = 2;
ip6addr_add(&all_nodes_ll);
/* ... */
/* Router list */
first_router = NULL;
last_router = first_router;
/* Init Neighbour cache */
first_neighbor = NULL;
last_neighbor = first_neighbor;
ndp_init();
send_router_solicitation (fd);
for(i=0; i < 4 && !is_ra_received(); i++) {

View File

@ -127,28 +127,13 @@ struct ip6_config {
uint8_t managed_mode:1,
other_config:1,
reserved:6;
} ip6_state;
};
/******************** VARIABLES **********************************************/
/* Function pointer send_ip. Points either to send_ipv4() or send_ipv6() */
extern int (*send_ip) (int fd, void *, int);
/* IPv6 link-local multicast addresses */
struct ip6addr_list_entry all_routers_ll; // Routers
struct ip6addr_list_entry all_dhcpv6_ll; // DHCPv6 servers
struct ip6addr_list_entry all_nodes_ll; // All IPv6 nodes
/* List of Ipv6 Addresses */
struct ip6addr_list_entry *first_ip6;
struct ip6addr_list_entry *last_ip6;
/* Neighbor cache */
struct neighbor *first_neighbor;
struct neighbor *last_neighbor;
/* Router list */
struct router *first_router;
struct router *last_router;
extern struct ip6_config ip6_state;
/******************** FUNCTIONS *********************************************/
/* Handles IPv6-packets that are detected by receive_ether. */

View File

@ -17,6 +17,14 @@
#include <netlib/icmpv6.h>
#include <netlib/ndp.h>
/* Neighbor cache */
static struct neighbor *first_neighbor;
static struct neighbor *last_neighbor;
/* Router list */
static struct router *first_router;
static struct router *last_router;
/*
* NET: add new router to list
* @param struct router nghb - new router
@ -145,3 +153,14 @@ find_neighbor (ip6_addr_t *ip)
return NULL; /* neighbor is unknown */
}
void ndp_init(void)
{
/* Router list */
first_router = NULL;
last_router = first_router;
/* Init Neighbour cache */
first_neighbor = NULL;
last_neighbor = first_neighbor;
}

View File

@ -59,6 +59,7 @@ struct neighbor {
};
/******************** FUNCTIONS *********************************************/
void ndp_init(void);
int8_t neighbor_add (struct neighbor *);
void * neighbor_create (uint8_t *packet, struct packeth *headers);
struct neighbor * find_neighbor (ip6_addr_t *);