All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eldad Zack <eldad@fogrefinery.com>
To: netdev@vger.kernel.org
Cc: Eldad Zack <eldad@fogrefinery.com>
Subject: [PATCH 3/8] LLDP: Sysctl interface
Date: Mon, 25 Jun 2012 20:28:15 +0200	[thread overview]
Message-ID: <1340648900-6547-4-git-send-email-eldad@fogrefinery.com> (raw)
In-Reply-To: <1340648900-6547-1-git-send-email-eldad@fogrefinery.com>

Add 3 config items to LLDP via sysctl:
* Operational mode
* Message transmission interval
* Hold multiplier

Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
---
 net/lldp/sysctl_net_lldp.c |   94 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 net/lldp/sysctl_net_lldp.c

diff --git a/net/lldp/sysctl_net_lldp.c b/net/lldp/sysctl_net_lldp.c
new file mode 100644
index 0000000..dd5f5e3
--- /dev/null
+++ b/net/lldp/sysctl_net_lldp.c
@@ -0,0 +1,94 @@
+/* LLDP		Link Layer Discovery Protocol impementation for Linux
+ *		IEEE Std 802.1ab
+ *
+ * Author:	Eldad Zack <eldad@fogrefinery.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/sysctl.h>
+#include <linux/skbuff.h>
+#include <linux/socket.h>
+#include <linux/netdevice.h>
+#include <linux/init.h>
+#include "lldp.h"
+
+static int lldp_ttl_min = 1;
+static int lldp_ttl_max = 65535;
+
+/* Validate: (10.5.3, 10.5.4.1)
+ * 0 < transmit_interval * hold_multiplier <= 65535
+ */
+static int proc_dointvec_lldp_validate_ttl(ctl_table *table, int write,
+					void __user *buffer,
+					size_t *lenp, loff_t *ppos)
+{
+	int val, val2, ttl, ret;
+
+	ctl_table tmp = {
+		.data =		&val,
+		.maxlen =	sizeof(int),
+		.mode =		table->mode,
+		.extra1 =	&lldp_ttl_min,
+		.extra2 =	&lldp_ttl_max,
+	};
+
+	if (!write)
+		return proc_dointvec(table, write, buffer, lenp, ppos);
+
+	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+	if (ret == 0) {
+		val2 = *((int *)table->extra1);
+		ttl = val * val2;
+
+		if ((ttl >= lldp_ttl_min) && (ttl <= lldp_ttl_max))
+			*((int *)table->data) = val;
+		else
+			return -EINVAL;
+	}
+
+	return ret;
+}
+
+static struct ctl_table_header *lldp_table_header;
+
+static struct ctl_table lldp_table[] = {
+	{
+		.procname =	"lldp_op_mode",
+		.data =		&sysctl_lldp_operational_mode,
+		.maxlen =	sizeof(int),
+		.mode =		0644,
+		.proc_handler =	proc_dointvec,
+	},
+	{
+		.procname =	"transmit_interval",
+		.data =		&sysctl_lldp_transmit_interval,
+		.maxlen =	sizeof(int),
+		.mode =		0644,
+		.proc_handler =	proc_dointvec_lldp_validate_ttl,
+		.extra1 =	&sysctl_lldp_hold_multiplier,
+	},
+	{
+		.procname =	"hold_multiplier",
+		.data =		&sysctl_lldp_hold_multiplier,
+		.maxlen =	sizeof(int),
+		.mode =		0644,
+		.proc_handler =	proc_dointvec_lldp_validate_ttl,
+		.extra1 =	&sysctl_lldp_transmit_interval,
+	},
+	{ 0, },
+};
+
+void __init lldp_register_sysctl(void)
+{
+	lldp_table_header = register_net_sysctl(&init_net, "net/lldp",
+		lldp_table);
+}
+
+void __exit lldp_unregister_sysctl(void)
+{
+	unregister_net_sysctl_table(lldp_table_header);
+}
-- 
1.7.10

  parent reply	other threads:[~2012-06-25 18:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-25 18:28 [PATCH RFC 0/8] LLDP implementation for Linux Eldad Zack
2012-06-25 18:28 ` [PATCH 1/8] if_ether.h: Add LLDP ethertype Eldad Zack
2012-06-25 18:48   ` Eldad Zack
2012-06-25 18:28 ` [PATCH 2/8] LLDP: Header Eldad Zack
2012-06-25 18:28 ` Eldad Zack [this message]
2012-06-25 18:28 ` [PATCH 4/8] LLDP: PDU-handling routines Eldad Zack
2012-06-25 18:28 ` [PATCH 5/8] LLDP: Output routines Eldad Zack
2012-06-25 18:28 ` [PATCH 6/8] LLDP: Core routines Eldad Zack
2012-06-25 18:28 ` [PATCH 7/8] LLDP: Kconfig and Makefile Eldad Zack
2012-06-25 18:28 ` [PATCH 8/8] 8021q/vlan: process NETDEV_GOING_DOWN Eldad Zack
2012-06-25 18:33 ` [PATCH RFC 0/8] LLDP implementation for Linux Eldad Zack
2012-06-25 18:54 ` Stephen Hemminger
2012-06-25 20:05   ` Eldad Zack
2012-06-25 19:00 ` John Fastabend
2012-06-25 20:21   ` Eldad Zack

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=1340648900-6547-4-git-send-email-eldad@fogrefinery.com \
    --to=eldad@fogrefinery.com \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.