From: Samuel Ortiz <samuel@sortiz.org>
To: Rodolfo Giometti <giometti@enneenne.com>
Cc: netdev@vger.kernel.org
Subject: Re: Generic netlink interface help
Date: Mon, 28 May 2007 04:42:47 +0300 [thread overview]
Message-ID: <20070528014247.GC4264@sortiz.org> (raw)
In-Reply-To: <20070527173959.GU21180@enneenne.com>
Hi Rodolfo,
On Sun, May 27, 2007 at 07:39:59PM +0200, Rodolfo Giometti wrote:
> On Thu, May 24, 2007 at 09:43:30AM -0000, Samuel Ortiz wrote:
>
> > You could look at Johannes Berg 802.11 generic netlink implementation for
> > a good example (net/wireless/nl80211.c in John Linville's tree):
> > http://git.kernel.org/?p=linux/kernel/git/linville/wireless-dev.git;a=blob;f=net/wireless/nl80211.c;h=d6a44a386c2b86b81514b08d3c9b324dd2c7d229;hb=HEAD
>
> Looking at that code I suppose that if I want send/receive "struct
> pps_netlink_msg" to/from the kernel I have to define:
>
> static struct genl_family pps_gnl_family = {
> .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
> .name = "PPS",
> .hdrsize = 0, /* no private header */
> .version = PPS_FAMILY_VER,
> .maxattr = 1,
> };
>
> static struct nla_policy pps_genl_policy[1] = {
> [0] = {
> .type = NLA_BINARY,
> .len = sizeof(struct pps_netlink_msg),
> },
> };
>
> static struct genl_ops pps_gnl_ops = {
> .cmd = 0x1,
> .policy = pps_genl_policy,
> .doit = pps_genl_data_ready,
> };
>
> Then the pps_genl_data_ready() should do:
>
> static int pps_genl_data_ready(struct sk_buff *skb, struct genl_info *info)
> {
> struct pps_netlink_msg *msg = nla_data(info->attrs[0]);
> int cmd, source;
> unsigned long timeout;
> int ret;
>
> if (!msg)
> return -EINVAL;
>
> /* Do the job and put the answer into
> msg struct itself... */
>
> genlmsg_unicast(skb, info->snd_pid);
>
> return 0;
> }
>
> Is that right?
At first glance, this could work yes.
However, it seems you're trying to encapsulate your pps_netlink_msg into
a generic netlink message which itself is already encapsulated into a
netlink message, and then multiplex all your PPS commands on
ppl_genl_data_ready(). IMHO, you should have your different PPS commands
declared as a genl_ops array, and then have a specific doit routine per PPS
command. This would make your code cleaner and more secure (see the
"Operation Granularity" section at
http://linux-net.osdl.org/index.php/Generic_Netlink_HOWTO).
Cheers,
Samuel.
next prev parent reply other threads:[~2007-05-28 1:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-24 8:59 Generic netlink interface help Rodolfo Giometti
2007-05-24 9:43 ` Samuel Ortiz
2007-05-24 9:56 ` Rodolfo Giometti
2007-05-24 10:04 ` Samuel Ortiz
2007-05-24 11:21 ` Rodolfo Giometti
2007-05-24 13:21 ` Paul Moore
2007-05-24 13:51 ` jamal
2007-05-24 16:34 ` Johannes Berg
2007-05-25 22:18 ` Thomas Graf
2007-05-27 13:24 ` Johannes Berg
2007-05-27 13:50 ` Rodolfo Giometti
2007-05-27 13:54 ` Johannes Berg
2007-05-27 17:47 ` Rodolfo Giometti
2007-05-28 14:01 ` Samuel Ortiz
2007-05-30 21:45 ` Thomas Graf
2007-05-27 17:39 ` Rodolfo Giometti
2007-05-28 1:42 ` Samuel Ortiz [this message]
2007-05-28 7:41 ` Rodolfo Giometti
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=20070528014247.GC4264@sortiz.org \
--to=samuel@sortiz.org \
--cc=giometti@enneenne.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 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 NNTP newsgroup(s).