summaryrefslogtreecommitdiff
path: root/sbin/ipsecctl
diff options
context:
space:
mode:
authorHans-Joerg Hoexer <hshoexer@cvs.openbsd.org>2006-05-29 18:43:37 +0000
committerHans-Joerg Hoexer <hshoexer@cvs.openbsd.org>2006-05-29 18:43:37 +0000
commite1f53d123151a0b4c74e8877da0a5299fd8df66a (patch)
treefd76403bb62219c316f4e15c1965432bc26937f5 /sbin/ipsecctl
parentd7495aa806c73e8d51b2f8c98a766f5e7d2258d3 (diff)
add ipsecctl_free_rule() for cleaning up rules.
Diffstat (limited to 'sbin/ipsecctl')
-rw-r--r--sbin/ipsecctl/ipsecctl.c84
1 files changed, 45 insertions, 39 deletions
diff --git a/sbin/ipsecctl/ipsecctl.c b/sbin/ipsecctl/ipsecctl.c
index d1bca5e25c4..5d61323f2f4 100644
--- a/sbin/ipsecctl/ipsecctl.c
+++ b/sbin/ipsecctl/ipsecctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ipsecctl.c,v 1.46 2006/03/31 14:24:15 hshoexer Exp $ */
+/* $OpenBSD: ipsecctl.c,v 1.47 2006/05/29 18:43:36 hshoexer Exp $ */
/*
* Copyright (c) 2004, 2005 Hans-Joerg Hoexer <hshoexer@openbsd.org>
*
@@ -44,6 +44,7 @@ int ipsecctl_rules(char *, int);
FILE *ipsecctl_fopen(const char *, const char *);
int ipsecctl_commit(int, struct ipsecctl *);
int ipsecctl_add_rule(struct ipsecctl *, struct ipsec_rule *);
+void ipsecctl_free_rule(struct ipsec_rule *);
void ipsecctl_print_addr(struct ipsec_addr_wrap *);
void ipsecctl_print_proto(u_int8_t);
void ipsecctl_print_key(struct ipsec_key *);
@@ -162,44 +163,7 @@ ipsecctl_commit(int action, struct ipsecctl *ipsec)
action == ACTION_DELETE ? "delete" : "add",
rp->nr);
}
-
- /* src and dst are always used. */
- free(rp->src->name);
- free(rp->src);
- free(rp->dst->name);
- free(rp->dst);
-
- if (rp->local) {
- free(rp->local->name);
- free(rp->local);
- }
- if (rp->peer) {
- free(rp->peer->name);
- free(rp->peer);
- }
- if (rp->auth) {
- if (rp->auth->srcid)
- free(rp->auth->srcid);
- if (rp->auth->dstid)
- free(rp->auth->dstid);
- free(rp->auth);
- }
- if (rp->ikeauth) {
- if (rp->ikeauth->string)
- free(rp->ikeauth->string);
- free(rp->ikeauth);
- }
- if (rp->xfs)
- free(rp->xfs);
- if (rp->authkey) {
- free(rp->authkey->data);
- free(rp->authkey);
- }
- if (rp->enckey) {
- free(rp->enckey->data);
- free(rp->enckey);
- }
- free(rp);
+ ipsecctl_free_rule(rp);
}
return (0);
@@ -218,6 +182,48 @@ ipsecctl_add_rule(struct ipsecctl *ipsec, struct ipsec_rule *r)
}
void
+ipsecctl_free_rule(struct ipsec_rule *rp)
+{
+ /* src and dst are always used. */
+ free(rp->src->name);
+ free(rp->src);
+ free(rp->dst->name);
+ free(rp->dst);
+
+ if (rp->local) {
+ free(rp->local->name);
+ free(rp->local);
+ }
+ if (rp->peer) {
+ free(rp->peer->name);
+ free(rp->peer);
+ }
+ if (rp->auth) {
+ if (rp->auth->srcid)
+ free(rp->auth->srcid);
+ if (rp->auth->dstid)
+ free(rp->auth->dstid);
+ free(rp->auth);
+ }
+ if (rp->ikeauth) {
+ if (rp->ikeauth->string)
+ free(rp->ikeauth->string);
+ free(rp->ikeauth);
+ }
+ if (rp->xfs)
+ free(rp->xfs);
+ if (rp->authkey) {
+ free(rp->authkey->data);
+ free(rp->authkey);
+ }
+ if (rp->enckey) {
+ free(rp->enckey->data);
+ free(rp->enckey);
+ }
+ free(rp);
+}
+
+void
ipsecctl_print_addr(struct ipsec_addr_wrap *ipa)
{
int bits;