git: 2b5dd8b89011 - main - ipfw: use function return value to fetch insn argument.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 15 Jun 2023 06:50:09 UTC
The branch main has been updated by melifaro:
URL: https://cgit.FreeBSD.org/src/commit/?id=2b5dd8b89011098ff294dd58a5b61b087a4ef0b4
commit 2b5dd8b89011098ff294dd58a5b61b087a4ef0b4
Author: Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-06-15 06:46:42 +0000
Commit: Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-06-15 06:46:42 +0000
ipfw: use function return value to fetch insn argument.
This is a prerequsite for splitting compile_rule() into smaller
chunks.
MFC after: 2 weeks
---
sbin/ipfw/ipfw2.c | 30 +++++++++++++-----------------
sbin/ipfw/ipfw2.h | 2 +-
sbin/ipfw/ipv6.c | 7 +++----
3 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index a711514cb5dc..95f70e882096 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -1203,8 +1203,8 @@ static struct _s_x icmpcodes[] = {
{ NULL, 0 }
};
-static void
-fill_reject_code(u_short *codep, char *str)
+static uint16_t
+get_reject_code(const char *str)
{
int val;
char *s;
@@ -1214,8 +1214,7 @@ fill_reject_code(u_short *codep, char *str)
val = match_token(icmpcodes, str);
if (val < 0)
errx(EX_DATAERR, "unknown ICMP unreachable code ``%s''", str);
- *codep = val;
- return;
+ return (val);
}
static void
@@ -3965,23 +3964,20 @@ arg_or_targ(const char *arg, const char *action)
return (arg1);
}
-static void
-fill_divert_port(ipfw_insn *cmd, char *arg, const char *action)
+static uint16_t
+get_divert_port(const char *arg, const char *action)
{
uint32_t arg1 = arg_or_targ_relaxed(arg, action);
- if (arg1 != (uint32_t)(-1)) {
- cmd->arg1 = arg1;
- return;
- }
+ if (arg1 != (uint32_t)(-1))
+ return (arg1);
struct servent *s;
setservent(1);
s = getservbyname(arg, "divert");
- if (s != NULL)
- cmd->arg1 = ntohs(s->s_port);
- else
+ if (s == NULL)
errx(EX_DATAERR, "illegal divert/tee port");
+ return (ntohs(s->s_port));
}
/*
@@ -4143,7 +4139,7 @@ compile_rule(char *av[], uint32_t *rbuf, int *rbufsize, struct tidx *tstate)
case TOK_UNREACH:
action->opcode = O_REJECT;
NEED1("missing reject code");
- fill_reject_code(&action->arg1, *av);
+ action->arg1 = get_reject_code(*av);
av++;
if (action->arg1 == ICMP_UNREACH_NEEDFRAG && isdigit(**av)) {
uint16_t mtu;
@@ -4161,7 +4157,7 @@ compile_rule(char *av[], uint32_t *rbuf, int *rbufsize, struct tidx *tstate)
case TOK_UNREACH6:
action->opcode = O_UNREACH6;
NEED1("missing unreach code");
- fill_unreach6_code(&action->arg1, *av);
+ action->arg1 = get_unreach6_code(*av);
av++;
break;
@@ -4206,12 +4202,12 @@ compile_rule(char *av[], uint32_t *rbuf, int *rbufsize, struct tidx *tstate)
break;
case TOK_DIVERT:
action->opcode = O_DIVERT;
- fill_divert_port(action, av[0], *(av - 1));
+ action->arg1 = get_divert_port(av[0], *(av - 1));
av++;
break;
case TOK_TEE:
action->opcode = O_TEE;
- fill_divert_port(action, av[0], *(av - 1));
+ action->arg1 = get_divert_port(av[0], *(av - 1));
av++;
break;
case TOK_CALL:
diff --git a/sbin/ipfw/ipfw2.h b/sbin/ipfw/ipfw2.h
index 92fa05ae14b2..f787bbbb714d 100644
--- a/sbin/ipfw/ipfw2.h
+++ b/sbin/ipfw/ipfw2.h
@@ -448,7 +448,7 @@ struct _ipfw_insn *add_dstip6(struct _ipfw_insn *cmd, char *av, int cblen,
struct tidx *tstate);
void fill_flow6(struct _ipfw_insn_u32 *cmd, char *av, int cblen);
-void fill_unreach6_code(u_short *codep, char *str);
+uint16_t get_unreach6_code(const char *str);
void fill_icmp6types(struct _ipfw_insn_icmp6 *cmd, char *av, int cblen);
int fill_ext6hdr(struct _ipfw_insn *cmd, char *av);
diff --git a/sbin/ipfw/ipv6.c b/sbin/ipfw/ipv6.c
index eea313572f34..7cb12127548b 100644
--- a/sbin/ipfw/ipv6.c
+++ b/sbin/ipfw/ipv6.c
@@ -55,8 +55,8 @@ static struct _s_x icmp6codes[] = {
{ NULL, 0 }
};
-void
-fill_unreach6_code(u_short *codep, char *str)
+uint16_t
+get_unreach6_code(const char *str)
{
int val;
char *s;
@@ -66,8 +66,7 @@ fill_unreach6_code(u_short *codep, char *str)
val = match_token(icmp6codes, str);
if (val < 0)
errx(EX_DATAERR, "unknown ICMPv6 unreachable code ``%s''", str);
- *codep = val;
- return;
+ return (val);
}
void