netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: netdev <netdev@vger.kernel.org>, Jiri Benc <jbenc@suse.cz>,
	"John W. Linville" <linville@tuxdriver.com>
Subject: Re: [RFC] add nl80211
Date: Thu, 24 Aug 2006 19:27:17 +0200	[thread overview]
Message-ID: <20060824172717.GN3470@postel.suug.ch> (raw)
In-Reply-To: <1156435624.10283.9.camel@ux156>

* Johannes Berg <johannes@sipsolutions.net> 2006-08-24 18:07
> +static int nl80211_get_cmdlist(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct nl80211_registered_driver *drv;
> +	struct sk_buff *msg;
> +	void *hdr;
> +	int err;
> +	struct nlattr *start;
> +	u8 *data;
> +
> +	drv = nl80211_get_drv_from_info(info);
> +	if (IS_ERR(drv))
> +		return PTR_ERR(drv);
> +
> +	hdr = nl80211msg_new(&msg, info->snd_pid, info->snd_seq, 0,
> +			     NL80211_CMD_NEW_CMDLIST);
> +	if (IS_ERR(hdr)) {
> +		err = PTR_ERR(hdr);
> +		goto put_drv;
> +	}
> +
> +	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, drv->wiphy);
> +
> +	start = nla_nest_start(msg, NL80211_ATTR_CMDS);
> +	if (!start)
> +		goto nla_put_failure;
> +	data = nla_data(start);

This data variable is now unused.

> +static int nl80211_get_wiphys(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct sk_buff *msg;
> +	void *hdr;
> +	struct nlattr *start;
> +	u32 *data;
> +	struct nl80211_registered_driver *drv;
> +
> +	hdr = nl80211msg_new(&msg, info->snd_pid, info->snd_seq, 0,
> +			     NL80211_CMD_NEW_WIPHYS);
> +	if (IS_ERR(hdr))
> +		return PTR_ERR(hdr);
> +
> +	start = nla_nest_start(msg, NL80211_ATTR_WIPHY);
> +	if (!start)
> +		goto nla_put_failure;
> +	data = nla_data(start);
> +
> +	mutex_lock(&nl80211_drv_mutex);
> +	list_for_each_entry(drv, &nl80211_drv_list, list) {
> +		skb_put(msg, sizeof(*data));
> +		*data++ = drv->wiphy;
> +	}

I'd use normal u32 attributes here as well and simply
enumerate their type 1..n.

	int idx = 1
	list_for_each_entry(drv, &nl80211_drv_list, list)
		NLA_PUT_U32(msg, idx++, drv->wiphy);

The additional header seems waste but this way you stay flexible
and can extend the protocol later on. Attribute lengths are
checked with an open end in mind, i.e. you can put more stuff
behind that u32 in the future and your old applications will
still work.

You also might want to consider returning ifindex and
the associated name.

> +static int addifidx(void *data, int ifidx)
> +{
> +	struct sk_buff *msg = data;
> +	u32 *p;
> +
> +	if (unlikely(skb_tailroom(msg) < 4))
> +		return -ENOSPC;
> +
> +	p = (u32*)skb_put(msg, 4);
> +	*p = ifidx;
> +
> +	return 0;
> +}

Same here, just use nla_put_u32()

> +static int nl80211_get_intfs(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct nl80211_registered_driver *drv;
> +	struct sk_buff *msg;
> +	void *hdr;
> +	int err;
> +	struct nlattr *start;
> +	u8 *data;
> +
> +	drv = nl80211_get_drv_from_info(info);
> +	if (IS_ERR(drv))
> +		return PTR_ERR(drv);
> +
> +	hdr = nl80211msg_new(&msg, info->snd_pid, info->snd_seq, 0,
> +			     NL80211_CMD_GET_INTERFACES);
> +	if (IS_ERR(hdr)) {
> +		err = PTR_ERR(hdr);
> +		goto put_drv;
> +	}
> +
> +	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, drv->wiphy);
> +
> +	start = nla_nest_start(msg, NL80211_ATTR_IFINDEX);

Try not to reuse the same attribute type for different purposes,
it will force you to duplicate the validation policy for every
single command and things become very error prone.

  reply	other threads:[~2006-08-24 17:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-22 13:52 [RFC] add nl80211 Johannes Berg
2006-08-22 15:09 ` Johannes Berg
2006-08-23  9:40 ` Johannes Berg
2006-08-24 13:32 ` Jiri Benc
2006-08-24 14:15   ` Johannes Berg
2006-08-24 14:36 ` Thomas Graf
2006-08-24 15:20   ` Johannes Berg
2006-08-24 16:07 ` Johannes Berg
2006-08-24 17:27   ` Thomas Graf [this message]
2006-08-25  9:04     ` Johannes Berg
2006-08-25 10:30       ` Thomas Graf
2006-08-25 10:38         ` Johannes Berg
2006-08-25 11:01   ` [RFC take3] " Johannes Berg

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=20060824172717.GN3470@postel.suug.ch \
    --to=tgraf@suug.ch \
    --cc=jbenc@suse.cz \
    --cc=johannes@sipsolutions.net \
    --cc=linville@tuxdriver.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).