From: Grant Erickson <gerickson@nuovations.com>
To: connman@lists.linux.dev
Subject: [PATCH] Add self-documenting Linux rp_filter enum.
Date: Fri, 20 Oct 2023 13:19:24 -0700 [thread overview]
Message-ID: <A838BEF3-E296-4B5A-9B84-8D5D0805FB67@nuovations.com> (raw)
This improves self-documentation of the Linux reverse path filtering
(rp_filter) validation setting values by introducing a file scope
enumeration for the possible valid values
---
src/ipconfig.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 34b1724a..18240458 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -40,6 +40,14 @@
#include "connman.h"
+/* Linux reverse path filtering (rp_filter) validation setting values.
+ */
+enum {
+ __CONNMAN_LINUX_RP_FILTER_SETTING_NO_VALIDATION = 0,
+ __CONNMAN_LINUX_RP_FILTER_SETTING_STRICT_MODE_VALIDATION = 1,
+ __CONNMAN_LINUX_RP_FILTER_SETTING_LOOSE_MODE_VALIDATION = 2,
+};
+
struct connman_ipconfig {
int refcount;
int index;
@@ -406,11 +414,11 @@ static int set_rp_filter(int value)
/* 0 = no validation, 1 = strict mode, 2 = loose mode */
switch (value) {
case -1:
- value = 0;
+ value = __CONNMAN_LINUX_RP_FILTER_SETTING_NO_VALIDATION;
/* fall through */
- case 0:
- case 1:
- case 2:
+ case __CONNMAN_LINUX_RP_FILTER_SETTING_NO_VALIDATION:
+ case __CONNMAN_LINUX_RP_FILTER_SETTING_STRICT_MODE_VALIDATION:
+ case __CONNMAN_LINUX_RP_FILTER_SETTING_LOOSE_MODE_VALIDATION:
break;
default:
return -EINVAL;
@@ -421,6 +429,7 @@ static int set_rp_filter(int value)
int __connman_ipconfig_set_rp_filter()
{
+ const int default_value = __CONNMAN_LINUX_RP_FILTER_SETTING_LOOSE_MODE_VALIDATION;
int value;
value = get_rp_filter();
@@ -428,10 +437,10 @@ int __connman_ipconfig_set_rp_filter()
if (value < 0)
return value;
- set_rp_filter(2);
+ set_rp_filter(default_value);
- connman_info("rp_filter set to 2 (loose mode routing), "
- "old value was %d", value);
+ connman_info("rp_filter set to %d (loose mode routing), "
+ "old value was %d", default_value, value);
return value;
}
--
2.42.0
next reply other threads:[~2023-10-20 20:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-20 20:19 Grant Erickson [this message]
2023-10-21 21:05 ` [PATCH] Add self-documenting Linux rp_filter enum Marcus Folkesson
2023-11-07 15:24 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=A838BEF3-E296-4B5A-9B84-8D5D0805FB67@nuovations.com \
--to=gerickson@nuovations.com \
--cc=connman@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).