allow setting transport addresses for interfaces into config file
also move passive-interface functionality under interface block report the correct line for config parsing errors
This commit is contained in:
parent
4a806b5236
commit
f86d4fa943
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: conffile.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */
|
/* $NetBSD: conffile.c,v 1.7 2013/10/17 18:10:23 kefren Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||||
@ -63,13 +63,21 @@ static int Fneighbour(char*);
|
|||||||
static int Gneighbour(struct conf_neighbour *, char *);
|
static int Gneighbour(struct conf_neighbour *, char *);
|
||||||
static int Fnodefault(char*);
|
static int Fnodefault(char*);
|
||||||
static int Floopdetection(char*);
|
static int Floopdetection(char*);
|
||||||
static int Fpassiveif(char*);
|
static int Finterface(char*);
|
||||||
|
static int Ginterface(struct conf_interface *, char *);
|
||||||
|
static int Ipassive(struct conf_interface *, char *);
|
||||||
|
static int Itaddr(struct conf_interface *, char *);
|
||||||
|
|
||||||
struct conf_func {
|
struct conf_func {
|
||||||
char com[64];
|
char com[64];
|
||||||
int (* func)(char *);
|
int (* func)(char *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct intf_func {
|
||||||
|
char com[64];
|
||||||
|
int (* func)(struct conf_interface *, char *);
|
||||||
|
};
|
||||||
|
|
||||||
struct conf_func main_commands[] = {
|
struct conf_func main_commands[] = {
|
||||||
{ "hello-time", Fhellotime },
|
{ "hello-time", Fhellotime },
|
||||||
{ "keepalive-time", Fkeepalive },
|
{ "keepalive-time", Fkeepalive },
|
||||||
@ -77,26 +85,33 @@ struct conf_func main_commands[] = {
|
|||||||
{ "command-port", Fport },
|
{ "command-port", Fport },
|
||||||
{ "min-label", Fminlabel },
|
{ "min-label", Fminlabel },
|
||||||
{ "max-label", Fmaxlabel },
|
{ "max-label", Fmaxlabel },
|
||||||
{ "LDP-ID", Fldpid },
|
{ "ldp-id", Fldpid },
|
||||||
{ "neighbor", Fneighbour },
|
{ "neighbor", Fneighbour },
|
||||||
{ "neighbour", Fneighbour },
|
{ "neighbour", Fneighbour },
|
||||||
{ "no-default-route", Fnodefault },
|
{ "no-default-route", Fnodefault },
|
||||||
{ "loop-detection", Floopdetection },
|
{ "loop-detection", Floopdetection },
|
||||||
{ "passive-if", Fpassiveif },
|
{ "interface", Finterface },
|
||||||
{ "", NULL },
|
{ "", NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct intf_func intf_commands[] = {
|
||||||
|
{ "passive", Ipassive },
|
||||||
|
{ "transport-address", Itaddr },
|
||||||
|
{ "", NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
static int parseline;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parses config file
|
* Parses config file
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
conf_parsefile(const char *fname)
|
conf_parsefile(const char *fname)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
char buf[LINEMAXSIZE + 1];
|
char buf[LINEMAXSIZE + 1];
|
||||||
|
|
||||||
SLIST_INIT(&conei_head);
|
SLIST_INIT(&conei_head);
|
||||||
SLIST_INIT(&passifs_head);
|
SLIST_INIT(&coifs_head);
|
||||||
conf_ldp_id.s_addr = 0;
|
conf_ldp_id.s_addr = 0;
|
||||||
|
|
||||||
confh = open(fname, O_RDONLY, 0);
|
confh = open(fname, O_RDONLY, 0);
|
||||||
@ -104,10 +119,10 @@ conf_parsefile(const char *fname)
|
|||||||
if (confh == -1)
|
if (confh == -1)
|
||||||
return E_CONF_IO;
|
return E_CONF_IO;
|
||||||
|
|
||||||
for (i = 1; conf_readline(buf, sizeof(buf)) >= 0; i++)
|
for (parseline = 1; conf_readline(buf, sizeof(buf)) >= 0; parseline++)
|
||||||
if (conf_dispatch(buf) != 0) {
|
if (conf_dispatch(buf) != 0) {
|
||||||
close(confh);
|
close(confh);
|
||||||
return i;
|
return parseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(confh);
|
close(confh);
|
||||||
@ -155,7 +170,7 @@ conf_dispatch(char *line)
|
|||||||
command = NextCommand(nline);
|
command = NextCommand(nline);
|
||||||
for (i = 0; main_commands[i].func != NULL; i++)
|
for (i = 0; main_commands[i].func != NULL; i++)
|
||||||
if (strncasecmp(main_commands[i].com, command,
|
if (strncasecmp(main_commands[i].com, command,
|
||||||
strlen(command)) == 0) {
|
strlen(main_commands[i].com)) == 0) {
|
||||||
matched++;
|
matched++;
|
||||||
last_match = i;
|
last_match = i;
|
||||||
}
|
}
|
||||||
@ -287,6 +302,7 @@ Fneighbour(char *line)
|
|||||||
SLIST_INSERT_HEAD(&conei_head, nei, neilist);
|
SLIST_INSERT_HEAD(&conei_head, nei, neilist);
|
||||||
|
|
||||||
while (conf_readline(buf, sizeof(buf)) >= 0) {
|
while (conf_readline(buf, sizeof(buf)) >= 0) {
|
||||||
|
parseline++;
|
||||||
if (buf[0] == '}')
|
if (buf[0] == '}')
|
||||||
return 0;
|
return 0;
|
||||||
if (Gneighbour(nei, buf) == -1)
|
if (Gneighbour(nei, buf) == -1)
|
||||||
@ -328,15 +344,59 @@ Floopdetection(char *line)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interface sub-commands
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
Fpassiveif(char *line)
|
Finterface(char *line)
|
||||||
{
|
{
|
||||||
struct passive_if *pif;
|
char *ifname;
|
||||||
|
struct conf_interface *conf_if = calloc(1, sizeof(*conf_if));
|
||||||
|
char buf[1024];
|
||||||
|
|
||||||
if (strlen(line) > IF_NAMESIZE - 1)
|
ifname = NextCommand(line);
|
||||||
return E_CONF_PARAM;
|
if (conf_if == NULL || ifname == NULL)
|
||||||
pif = calloc(1, sizeof(*pif));
|
return -1;
|
||||||
strlcpy(pif->if_name, line, IF_NAMESIZE);
|
strlcpy(conf_if->if_name, ifname, IF_NAMESIZE);
|
||||||
SLIST_INSERT_HEAD(&passifs_head, pif, listentry);
|
SLIST_INSERT_HEAD(&coifs_head, conf_if, iflist);
|
||||||
|
|
||||||
|
while (conf_readline(buf, sizeof(buf)) >= 0) {
|
||||||
|
parseline++;
|
||||||
|
if (buf[0] == '}')
|
||||||
|
return 0;
|
||||||
|
if (Ginterface(conf_if, buf) == -1)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Ginterface(struct conf_interface *conf_if, char *buf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; intf_commands[i].func != NULL; i++)
|
||||||
|
if (strncasecmp(buf, intf_commands[i].com,
|
||||||
|
strlen(intf_commands[i].com)) == 0)
|
||||||
|
return intf_commands[i].func(conf_if, buf +
|
||||||
|
strlen(intf_commands[i].com) + 1);
|
||||||
|
/* command not found */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sets transport address */
|
||||||
|
int
|
||||||
|
Itaddr(struct conf_interface *conf_if, char *buf)
|
||||||
|
{
|
||||||
|
if (inet_pton(AF_INET, buf, &conf_if->tr_addr) != 1)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sets passive-interface on */
|
||||||
|
int
|
||||||
|
Ipassive(struct conf_interface *conf_if, char *buf)
|
||||||
|
{
|
||||||
|
conf_if->passive = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: conffile.h,v 1.3 2013/07/11 10:46:19 kefren Exp $ */
|
/* $NetBSD: conffile.h,v 1.4 2013/10/17 18:10:23 kefren Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||||
@ -51,11 +51,13 @@ struct conf_neighbour {
|
|||||||
};
|
};
|
||||||
SLIST_HEAD(,conf_neighbour) conei_head;
|
SLIST_HEAD(,conf_neighbour) conei_head;
|
||||||
|
|
||||||
struct passive_if {
|
struct conf_interface {
|
||||||
char if_name[IF_NAMESIZE];
|
char if_name[IF_NAMESIZE];
|
||||||
SLIST_ENTRY(passive_if) listentry;
|
struct in_addr tr_addr;
|
||||||
|
int passive;
|
||||||
|
SLIST_ENTRY(conf_interface) iflist;
|
||||||
};
|
};
|
||||||
SLIST_HEAD(,passive_if) passifs_head;
|
SLIST_HEAD(,conf_interface) coifs_head;
|
||||||
|
|
||||||
int conf_parsefile(const char *fname);
|
int conf_parsefile(const char *fname);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: socketops.c,v 1.31 2013/07/27 14:35:41 kefren Exp $ */
|
/* $NetBSD: socketops.c,v 1.32 2013/10/17 18:10:23 kefren Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||||
@ -287,10 +287,11 @@ is_hello_socket(int s)
|
|||||||
static int
|
static int
|
||||||
is_passive_if(const char *if_name)
|
is_passive_if(const char *if_name)
|
||||||
{
|
{
|
||||||
struct passive_if *pif;
|
struct conf_interface *coif;
|
||||||
|
|
||||||
SLIST_FOREACH(pif, &passifs_head, listentry)
|
SLIST_FOREACH(coif, &coifs_head, iflist)
|
||||||
if (strncasecmp(if_name, pif->if_name, IF_NAMESIZE) == 0)
|
if (strncasecmp(if_name, coif->if_name, IF_NAMESIZE) == 0 &&
|
||||||
|
coif->passive != 0)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -408,6 +409,8 @@ send_hello(void)
|
|||||||
int ip4socket = -1;
|
int ip4socket = -1;
|
||||||
uint lastifindex;
|
uint lastifindex;
|
||||||
struct hello_socket *hs;
|
struct hello_socket *hs;
|
||||||
|
struct conf_interface *coif;
|
||||||
|
bool bad_tr_addr;
|
||||||
#ifdef INET6
|
#ifdef INET6
|
||||||
struct sockaddr_in6 sadest6;
|
struct sockaddr_in6 sadest6;
|
||||||
int ip6socket = -1;
|
int ip6socket = -1;
|
||||||
@ -502,6 +505,16 @@ send_hello(void)
|
|||||||
/* Send only once per interface, using primary address */
|
/* Send only once per interface, using primary address */
|
||||||
if (lastifindex == if_nametoindex(ifb->ifa_name))
|
if (lastifindex == if_nametoindex(ifb->ifa_name))
|
||||||
continue;
|
continue;
|
||||||
|
/* Check if there is transport address set for this interface */
|
||||||
|
bad_tr_addr = false;
|
||||||
|
SLIST_FOREACH(coif, &coifs_head, iflist)
|
||||||
|
if (strncasecmp(coif->if_name, ifb->ifa_name,
|
||||||
|
IF_NAMESIZE) == 0 &&
|
||||||
|
coif->tr_addr.s_addr != 0 &&
|
||||||
|
coif->tr_addr.s_addr != if_sa->sin_addr.s_addr)
|
||||||
|
bad_tr_addr = true;
|
||||||
|
if (bad_tr_addr == true)
|
||||||
|
continue;
|
||||||
lastifindex = if_nametoindex(ifb->ifa_name);
|
lastifindex = if_nametoindex(ifb->ifa_name);
|
||||||
|
|
||||||
if (setsockopt(ip4socket, IPPROTO_IP, IP_MULTICAST_IF,
|
if (setsockopt(ip4socket, IPPROTO_IP, IP_MULTICAST_IF,
|
||||||
|
Loading…
Reference in New Issue
Block a user