summaryrefslogtreecommitdiffstats
path: root/userspace
diff options
context:
space:
mode:
Diffstat (limited to 'userspace')
-rw-r--r--userspace/ebtables2/ebtables.c49
-rw-r--r--userspace/ebtables2/extensions/ebt_nat.c19
2 files changed, 23 insertions, 45 deletions
diff --git a/userspace/ebtables2/ebtables.c b/userspace/ebtables2/ebtables.c
index 21cc8b0..dddb623 100644
--- a/userspace/ebtables2/ebtables.c
+++ b/userspace/ebtables2/ebtables.c
@@ -31,6 +31,7 @@
#include <linux/netfilter_bridge/ebtables.h>
#include <linux/br_db.h> // the database
#include <netinet/in.h>
+#include <netinet/ether.h>
#include <asm/types.h>
#include "include/ebtables_u.h"
@@ -493,14 +494,12 @@ static void list_em(int hooknr)
printf("Broadcast");
goto endsrc;
}
- for (j = 0; j < ETH_ALEN; j++)
- printf("%02x%s", hlp->sourcemac[j],
- (j == ETH_ALEN - 1) ? "" : ":");
+ printf("%s", ether_ntoa((struct ether_addr *)
+ hlp->sourcemac));
if (memcmp(hlp->sourcemsk, hlpmsk, 6)) {
printf("/");
- for (j = 0; j < ETH_ALEN; j++)
- printf("%02x%s", hlp->sourcemsk[j],
- (j == ETH_ALEN - 1) ? "" : ":");
+ printf("%s", ether_ntoa((struct ether_addr *)
+ hlp->sourcemsk));
}
endsrc:
printf(", ");
@@ -526,14 +525,12 @@ endsrc:
printf("Broadcast");
goto enddst;
}
- for (j = 0; j < ETH_ALEN; j++)
- printf("%02x%s", hlp->destmac[j],
- (j == ETH_ALEN - 1) ? "" : ":");
+ printf("%s", ether_ntoa((struct ether_addr *)
+ hlp->destmac));
if (memcmp(hlp->destmsk, hlpmsk, 6)) {
printf("/");
- for (j = 0; j < ETH_ALEN; j++)
- printf("%02x%s", hlp->destmsk[j],
- (j == ETH_ALEN - 1) ? "" : ":");
+ printf("%s", ether_ntoa((struct ether_addr *)
+ hlp->destmsk));
}
enddst:
printf(", ");
@@ -1132,31 +1129,11 @@ int name_to_protocol(char *name)
}
// put the mac address into 6 (ETH_ALEN) bytes
-int getmac(char *from, char *to)
-{
- int i, tmp;
- char *buffer;
-
- if (strlen(from) != 3 * ETH_ALEN - 1)
- return -1;
- for (i = 1; i < ETH_ALEN; i++) {
- if (from[i*3 - 1] != ':')
- return -1;
- from[i*3 - 1] = '\0';
- }
- for (i = 0; i < ETH_ALEN; i++) {
- tmp = strtol(from + i*3, &buffer, 16);
- if (*buffer != '\0' || tmp > 255 || tmp < 0)
- return -1;
- to[i] = (unsigned char) tmp;
- }
- return 0;
-}
-
int getmac_and_mask(char *from, char *to, char *mask)
{
char *p;
int i;
+ struct ether_addr *addr;
if (strcasecmp(from, "Unicast") == 0) {
memcpy(to, mac_type_unicast, ETH_ALEN);
@@ -1175,12 +1152,14 @@ int getmac_and_mask(char *from, char *to, char *mask)
}
if ( (p = strrchr(from, '/')) != NULL) {
*p = '\0';
- if (getmac(p + 1, mask))
+ if (!(addr = ether_aton(p + 1)))
return -1;
+ memcpy(mask, addr, ETH_ALEN);
} else
memset(mask, 0xff, ETH_ALEN);
- if (getmac(from, to))
+ if (!(addr = ether_aton(from)))
return -1;
+ memcpy(to, addr, ETH_ALEN);
for (i = 0; i < ETH_ALEN; i++)
to[i] &= mask[i];
return 0;
diff --git a/userspace/ebtables2/extensions/ebt_nat.c b/userspace/ebtables2/extensions/ebt_nat.c
index dbdb5a4..1f88ae2 100644
--- a/userspace/ebtables2/extensions/ebt_nat.c
+++ b/userspace/ebtables2/extensions/ebt_nat.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <netinet/ether.h>
#include <linux/netfilter_bridge/ebtables.h>
#include <getopt.h>
#include "../include/ebtables_u.h"
@@ -74,13 +75,15 @@ static int parse_s(int c, char **argv, int argc,
{
int i;
struct ebt_nat_info *natinfo = (struct ebt_nat_info *)(*target)->data;
+ struct ether_addr *addr;
switch (c) {
case NAT_S:
check_option(flags, OPT_SNAT);
to_source_supplied = 1;
- if (getmac(optarg, natinfo->mac))
+ if (!(addr = ether_aton(optarg)))
print_error("Problem with specified to-source mac");
+ memcpy(natinfo->mac, addr, ETH_ALEN);
break;
case NAT_S_TARGET:
check_option(flags, OPT_SNAT_TARGET);
@@ -106,14 +109,16 @@ static int parse_d(int c, char **argv, int argc,
{
int i;
struct ebt_nat_info *natinfo = (struct ebt_nat_info *)(*target)->data;
+ struct ether_addr *addr;
switch (c) {
case NAT_D:
check_option(flags, OPT_DNAT);
to_dest_supplied = 1;
- if (getmac(optarg, natinfo->mac))
+ if (!(addr = ether_aton(optarg)))
print_error("Problem with specified "
"to-destination mac");
+ memcpy(natinfo->mac, addr, ETH_ALEN);
break;
case NAT_D_TARGET:
check_option(flags, OPT_DNAT_TARGET);
@@ -155,12 +160,9 @@ static void print_s(const struct ebt_u_entry *entry,
const struct ebt_entry_target *target)
{
struct ebt_nat_info *natinfo = (struct ebt_nat_info *)target->data;
- int i;
printf("snat - to: ");
- for (i = 0; i < ETH_ALEN; i++)
- printf("%02x%s",
- natinfo->mac[i], (i == ETH_ALEN - 1) ? "" : ":");
+ printf("%s", ether_ntoa((struct ether_addr *)natinfo->mac));
printf(" --snat-target %s", standard_targets[natinfo->target]);
}
@@ -168,12 +170,9 @@ static void print_d(const struct ebt_u_entry *entry,
const struct ebt_entry_target *target)
{
struct ebt_nat_info *natinfo = (struct ebt_nat_info *)target->data;
- int i;
printf("dnat - to: ");
- for (i = 0; i < ETH_ALEN; i++)
- printf("%02x%s",
- natinfo->mac[i], (i == ETH_ALEN - 1) ? "" : ":");
+ printf("%s", ether_ntoa((struct ether_addr *)natinfo->mac));
printf(" --dnat-target %s", standard_targets[natinfo->target]);
}