summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-10-02 09:45:30 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-10-02 09:45:30 +0000
commit9b0df37a32463efc74a0e7572c11ff3ea554f25a (patch)
tree28bb2fcc5e10a3c1b6afc7bc49fde8f8be190d11
parentabe93474673216a2bbbd5e591a3b1b671c376a1b (diff)
No need to check as->established before calling pfkey_remove().
Remove the extra checks in the caller and simplify some code because of that. OK tb@
-rw-r--r--usr.sbin/bgpd/pfkey.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/usr.sbin/bgpd/pfkey.c b/usr.sbin/bgpd/pfkey.c
index c5945c471c4..806c5496392 100644
--- a/usr.sbin/bgpd/pfkey.c
+++ b/usr.sbin/bgpd/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.70 2024/10/01 18:28:17 claudio Exp $ */
+/* $OpenBSD: pfkey.c,v 1.71 2024/10/02 09:45:29 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -544,10 +544,8 @@ pfkey_md5sig_establish(struct auth_state *as, struct auth_config *auth,
goto fail;
/* cleanup old flow if one was present */
- if (as->established) {
- if (pfkey_remove(as) == -1)
- return (-1);
- }
+ if (pfkey_remove(as) == -1)
+ return (-1);
as->established = 1;
as->method = auth->method;
@@ -613,10 +611,8 @@ pfkey_ipsec_establish(struct auth_state *as, struct auth_config *auth,
uint8_t satype = SADB_SATYPE_ESP;
/* cleanup first, unlike in the TCP MD5 case */
- if (as->established) {
- if (pfkey_remove(as) == -1)
- return (-1);
- }
+ if (pfkey_remove(as) == -1)
+ return (-1);
switch (auth->method) {
case AUTH_IPSEC_IKE_ESP:
@@ -774,22 +770,15 @@ int
pfkey_establish(struct auth_state *as, struct auth_config *auth,
const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr)
{
- int rv;
-
switch (auth->method) {
case AUTH_NONE:
- rv = 0;
- if (as->established)
- rv = pfkey_remove(as);
- break;
+ return pfkey_remove(as);
case AUTH_MD5SIG:
- rv = pfkey_md5sig_establish(as, auth, local_addr, remote_addr);
- break;
+ return pfkey_md5sig_establish(as, auth, local_addr,
+ remote_addr);
default:
- rv = pfkey_ipsec_establish(as, auth, local_addr, remote_addr);
- break;
+ return pfkey_ipsec_establish(as, auth, local_addr, remote_addr);
}
- return (rv);
}
int