Skip to content

Commit

Permalink
reindented the code
Browse files Browse the repository at this point in the history
... with  indent -linux -l180 *.c *.h
  • Loading branch information
reubenhwk committed Jan 5, 2014
1 parent cccce0f commit ac6fc18
Show file tree
Hide file tree
Showing 21 changed files with 922 additions and 1,372 deletions.
72 changes: 34 additions & 38 deletions defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#define MAX2(X,Y) ( (( X ) >= ( Y )) ? ( X ) : ( Y ))


/* Router Configuration Variables: */

/* For each multicast interface: */
Expand All @@ -51,17 +50,17 @@

/* Each prefix has an associated: */

#define DFLT_AdvValidLifetime 86400 /* seconds */
#define DFLT_AdvValidLifetime 86400 /* seconds */
#define DFLT_AdvOnLinkFlag 1
#define DFLT_AdvPreferredLifetime 14400 /* seconds */
#define DFLT_AdvPreferredLifetime 14400 /* seconds */
#define DFLT_AdvAutonomousFlag 1
#define DFLT_DeprecatePrefixFlag 0
#define DFLT_DecrementLifetimesFlag 0

/* Each route has an associated: */
#define DFLT_AdvRouteLifetime(iface) (3 * (iface)->MaxRtrAdvInterval)

#define DFLT_AdvRoutePreference 0 /* medium*/
#define DFLT_AdvRoutePreference 0 /* medium */
#define DFLT_RemoveRouteFlag 1

/* RDNSS */
Expand All @@ -81,7 +80,7 @@
#define MAX_FINAL_RTR_ADVERTISEMENTS 3
#define MIN_DELAY_BETWEEN_RAS 3.0
#define MIN_DELAY_BETWEEN_RAS_MIPv6 (30.0/1000.0)
#define MAX_RA_DELAY_TIME (1000.0/2.0) /* milliseconds */
#define MAX_RA_DELAY_TIME (1000.0/2.0) /* milliseconds */

/* Host constants: */

Expand All @@ -95,8 +94,8 @@
#define MAX_UNICAST_SOLICIT 3
#define MAX_ANYCAST_DELAY_TIME 1
#define MAX_NEIGHBOR_ADVERTISEMENT 3
#define REACHABLE_TIME 30000 /* milliseconds */
#define RETRANS_TIMER 1000 /* milliseconds */
#define REACHABLE_TIME 30000 /* milliseconds */
#define RETRANS_TIMER 1000 /* milliseconds */
#define DELAY_FIRST_PROBE_TIME 5
#define MIN_RANDOM_FACTOR (1.0/2.0)
#define MAX_RANDOM_FACTOR (3.0/2.0)
Expand All @@ -116,7 +115,7 @@
#define MAX_AdvLinkMTU 131072

#define MIN_AdvReachableTime 100
#define MAX_AdvReachableTime 3600000 /* 1 hour in milliseconds */
#define MAX_AdvReachableTime 3600000 /* 1 hour in milliseconds */

#define MIN_AdvRetransTimer 10
#define MAX_AdvRetransTimer 3600000
Expand Down Expand Up @@ -153,33 +152,31 @@
#define ND_OPT_ROUTE_INFORMATION 24

/* XXX: some libc's like KAME already had nd_opt_route_info! */
struct nd_opt_route_info_local /* route information */
{
uint8_t nd_opt_ri_type;
uint8_t nd_opt_ri_len;
uint8_t nd_opt_ri_prefix_len;
uint8_t nd_opt_ri_flags_reserved;
uint32_t nd_opt_ri_lifetime;
struct in6_addr nd_opt_ri_prefix;
};
struct nd_opt_route_info_local { /* route information */
uint8_t nd_opt_ri_type;
uint8_t nd_opt_ri_len;
uint8_t nd_opt_ri_prefix_len;
uint8_t nd_opt_ri_flags_reserved;
uint32_t nd_opt_ri_lifetime;
struct in6_addr nd_opt_ri_prefix;
};

/* the reserved field is 8 bits and we're interested of the middle two: 000xx000 */
#define ND_OPT_RI_PRF_SHIFT 3
#define ND_OPT_RI_PRF_MASK (3 << ND_OPT_RI_PRF_SHIFT) /* 00011000 = 0x18 */
#define ND_OPT_RI_PRF_MASK (3 << ND_OPT_RI_PRF_SHIFT) /* 00011000 = 0x18 */

#undef ND_OPT_RDNSS_INFORMATION
#define ND_OPT_RDNSS_INFORMATION 25

/* */
struct nd_opt_rdnss_info_local
{
uint8_t nd_opt_rdnssi_type;
uint8_t nd_opt_rdnssi_len;
uint16_t nd_opt_rdnssi_pref_flag_reserved;
uint32_t nd_opt_rdnssi_lifetime;
struct in6_addr nd_opt_rdnssi_addr1;
struct in6_addr nd_opt_rdnssi_addr2;
struct in6_addr nd_opt_rdnssi_addr3;
struct nd_opt_rdnss_info_local {
uint8_t nd_opt_rdnssi_type;
uint8_t nd_opt_rdnssi_len;
uint16_t nd_opt_rdnssi_pref_flag_reserved;
uint32_t nd_opt_rdnssi_lifetime;
struct in6_addr nd_opt_rdnssi_addr1;
struct in6_addr nd_opt_rdnssi_addr2;
struct in6_addr nd_opt_rdnssi_addr3;
};
/* pref/flag/reserved field : yyyyx00000000000 (big endian) - 00000000yyyyx000 (little indian); where yyyy = pref, x = flag */
#if BYTE_ORDER == BIG_ENDIAN
Expand All @@ -193,13 +190,12 @@ struct nd_opt_rdnss_info_local
#define ND_OPT_DNSSL_INFORMATION 31

/* */
struct nd_opt_dnssl_info_local
{
uint8_t nd_opt_dnssli_type;
uint8_t nd_opt_dnssli_len;
uint16_t nd_opt_dnssli_reserved;
uint32_t nd_opt_dnssli_lifetime;
unsigned char nd_opt_dnssli_suffixes[];
struct nd_opt_dnssl_info_local {
uint8_t nd_opt_dnssli_type;
uint8_t nd_opt_dnssli_len;
uint16_t nd_opt_dnssli_reserved;
uint32_t nd_opt_dnssli_lifetime;
unsigned char nd_opt_dnssli_suffixes[];
};

/* Flags */
Expand Down Expand Up @@ -227,13 +223,13 @@ struct nd_opt_dnssl_info_local

#define MIN_MinRtrAdvInterval_MIPv6 (3.0/100.0)
#define MIN_MaxRtrAdvInterval_MIPv6 (7.0/100.0)
#define RTR_SOLICITATION_INTERVAL_MIPv6 1 /* Recommended value by MIPv6 */
#define RTR_SOLICITATION_INTERVAL_MIPv6 1 /* Recommended value by MIPv6 */

#define Cautious_MaxRtrAdvInterval (2.0/10.0)
#define Cautious_MaxRtrAdvInterval_Leeway (2.0/100.0)

#define MIN_HomeAgentLifetime 1 /* 0 must NOT be used */
#define MAX_HomeAgentLifetime 65520 /* 18.2 hours in secs */
#define MIN_HomeAgentLifetime 1 /* 0 must NOT be used */
#define MAX_HomeAgentLifetime 65520 /* 18.2 hours in secs */

/* #define MAX_RTR_SOLICITATIONS This MAY be ignored by MIPv6 */

Expand All @@ -245,7 +241,7 @@ struct nd_opt_dnssl_info_local
#ifndef ND_OPT_HAI_FLAG_SUPPORT_MR
#if BYTE_ORDER == BIG_ENDIAN
#define ND_OPT_HAI_FLAG_SUPPORT_MR 0x8000
#else /* BYTE_ORDER == LITTLE_ENDIAN */
#else /* BYTE_ORDER == LITTLE_ENDIAN */
#define ND_OPT_HAI_FLAG_SUPPORT_MR 0x0080
#endif
#endif
Expand Down
90 changes: 32 additions & 58 deletions device-bsd44.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@ static uint8_t ll_prefix[] = { 0xfe, 0x80 };
* determines the link layer token length and checks it against
* the defined prefixes
*/
int
update_device_info(struct Interface *iface)
int update_device_info(struct Interface *iface)
{
struct ifaddrs *addresses = 0, *ifa;

struct ifreq ifr;
struct AdvPrefix *prefix;
char zero[sizeof(iface->if_addr)];

if(if_nametoindex(iface->Name) == 0){
if (if_nametoindex(iface->Name) == 0) {
flog(LOG_ERR, "%s not found: %s", iface->Name, strerror(errno));
goto ret;
}

memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ - 1);
ifr.ifr_name[IFNAMSIZ - 1] = '\0';

if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) {
flog(LOG_ERR, "ioctl(SIOCGIFMTU) failed for %s: %s", iface->Name, strerror(errno));
Expand All @@ -51,14 +50,12 @@ update_device_info(struct Interface *iface)
dlog(LOG_DEBUG, 3, "mtu for %s is %d", iface->Name, ifr.ifr_mtu);
iface->if_maxmtu = ifr.ifr_mtu;

if (getifaddrs(&addresses) != 0)
{
if (getifaddrs(&addresses) != 0) {
flog(LOG_ERR, "getifaddrs failed: %s(%d)", strerror(errno), errno);
goto ret;
}

for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next)
{
for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next) {
if (strcmp(ifa->ifa_name, iface->Name) != 0)
continue;

Expand All @@ -68,21 +65,17 @@ update_device_info(struct Interface *iface)
if (ifa->ifa_addr->sa_family != AF_LINK)
continue;

struct sockaddr_dl *dl = (struct sockaddr_dl*)ifa->ifa_addr;
struct sockaddr_dl *dl = (struct sockaddr_dl *)ifa->ifa_addr;


if (dl->sdl_alen > sizeof(iface->if_addr))
{
flog(LOG_ERR, "address length %d too big for",
dl->sdl_alen,
iface->Name);
if (dl->sdl_alen > sizeof(iface->if_addr)) {
flog(LOG_ERR, "address length %d too big for", dl->sdl_alen, iface->Name);
goto ret;
}

memcpy(iface->if_hwaddr, LLADDR(dl), dl->sdl_alen);
iface->if_hwaddr_len = dl->sdl_alen << 3;

switch(dl->sdl_type) {
switch (dl->sdl_type) {
case IFT_ETHER:
case IFT_ISO88023:
iface->if_prefix_len = 64;
Expand All @@ -96,27 +89,20 @@ update_device_info(struct Interface *iface)
break;
}

dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name,
iface->if_hwaddr_len);
dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name, iface->if_hwaddr_len);

dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name,
iface->if_prefix_len);
dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name, iface->if_prefix_len);

if (iface->if_prefix_len != -1) {
memset(zero, 0, dl->sdl_alen);
if (!memcmp(iface->if_hwaddr, zero, dl->sdl_alen))
flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!",
iface->Name);
flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!", iface->Name);
}

prefix = iface->AdvPrefixList;
while (prefix)
{
if ((iface->if_prefix_len != -1) &&
(iface->if_prefix_len != prefix->PrefixLen))
{
flog(LOG_WARNING, "prefix length should be %d for %s",
iface->if_prefix_len, iface->Name);
while (prefix) {
if ((iface->if_prefix_len != -1) && (iface->if_prefix_len != prefix->PrefixLen)) {
flog(LOG_WARNING, "prefix length should be %d for %s", iface->if_prefix_len, iface->Name);
}

prefix = prefix->next;
Expand All @@ -126,8 +112,7 @@ update_device_info(struct Interface *iface)
return 0;
}


ret:
ret:
iface->if_maxmtu = -1;
iface->if_hwaddr_len = -1;
iface->if_prefix_len = -1;
Expand All @@ -144,22 +129,20 @@ int setup_linklocal_addr(struct Interface *iface)
{
struct ifaddrs *addresses = 0, *ifa;

if (getifaddrs(&addresses) != 0)
{
if (getifaddrs(&addresses) != 0) {
flog(LOG_ERR, "getifaddrs failed: %s(%d)", strerror(errno), errno);
goto ret;
}

for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next)
{
for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next) {
if (strcmp(ifa->ifa_name, iface->Name) != 0)
continue;

if (ifa->ifa_addr == NULL)
continue;

if (ifa->ifa_addr->sa_family == AF_LINK) {
struct sockaddr_dl *dl = (struct sockaddr_dl*)ifa->ifa_addr;
struct sockaddr_dl *dl = (struct sockaddr_dl *)ifa->ifa_addr;
if (memcmp(iface->Name, dl->sdl_data, dl->sdl_nlen) == 0)
iface->if_index = dl->sdl_index;
continue;
Expand All @@ -168,7 +151,7 @@ int setup_linklocal_addr(struct Interface *iface)
if (ifa->ifa_addr->sa_family != AF_INET6)
continue;

struct sockaddr_in6 *a6 = (struct sockaddr_in6*)ifa->ifa_addr;
struct sockaddr_in6 *a6 = (struct sockaddr_in6 *)ifa->ifa_addr;

/* Skip if it is not a linklocal address */
if (memcmp(&(a6->sin6_addr), ll_prefix, sizeof(ll_prefix)) != 0)
Expand All @@ -179,8 +162,8 @@ int setup_linklocal_addr(struct Interface *iface)
return 0;
}

ret:
if(addresses)
ret:
if (addresses)
freeifaddrs(addresses);
flog(LOG_ERR, "no linklocal address configured for %s", iface->Name);
return -1;
Expand All @@ -196,35 +179,26 @@ int check_allrouters_membership(struct Interface *iface)
return (0);
}

int
set_interface_linkmtu(const char *iface, uint32_t mtu)
int set_interface_linkmtu(const char *iface, uint32_t mtu)
{
dlog(LOG_DEBUG, 4, "setting LinkMTU (%u) for %s is not supported",
mtu, iface);
dlog(LOG_DEBUG, 4, "setting LinkMTU (%u) for %s is not supported", mtu, iface);
return -1;
}

int
set_interface_curhlim(const char *iface, uint8_t hlim)
int set_interface_curhlim(const char *iface, uint8_t hlim)
{
dlog(LOG_DEBUG, 4, "setting CurHopLimit (%u) for %s is not supported",
hlim, iface);
dlog(LOG_DEBUG, 4, "setting CurHopLimit (%u) for %s is not supported", hlim, iface);
return -1;
}

int
set_interface_reachtime(const char *iface, uint32_t rtime)
int set_interface_reachtime(const char *iface, uint32_t rtime)
{
dlog(LOG_DEBUG, 4, "setting BaseReachableTime (%u) for %s is not supported",
rtime, iface);
dlog(LOG_DEBUG, 4, "setting BaseReachableTime (%u) for %s is not supported", rtime, iface);
return -1;
}

int
set_interface_retranstimer(const char *iface, uint32_t rettimer)
int set_interface_retranstimer(const char *iface, uint32_t rettimer)
{
dlog(LOG_DEBUG, 4, "setting RetransTimer (%u) for %s is not supported",
rettimer, iface);
dlog(LOG_DEBUG, 4, "setting RetransTimer (%u) for %s is not supported", rettimer, iface);
return -1;
}

Loading

0 comments on commit ac6fc18

Please sign in to comment.