[PATCH 1/4] veth: alloc link struct for peer when parsing netlink message
Thomas Graf
tgraf at suug.ch
Thu Mar 27 19:46:31 EDT 2014
On 03/27/14 at 01:41pm, Cong Wang wrote:
> On Thu, Mar 27, 2014 at 2:25 AM, Thomas Graf <tgraf at suug.ch> wrote:
> > On 03/27/14 at 09:13am, Thomas Graf wrote:
> >> On 03/23/14 at 12:02pm, Cong Wang wrote:
> >> > Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
> >> > ---
> >> > lib/route/link/veth.c | 5 ++++-
> >> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >> >
> >> > diff --git a/lib/route/link/veth.c b/lib/route/link/veth.c
> >> > index 4ce1f10..0cac428 100644
> >> > --- a/lib/route/link/veth.c
> >> > +++ b/lib/route/link/veth.c
> >> > @@ -42,7 +42,6 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
> >> > {
> >> > struct nlattr *tb[VETH_INFO_MAX+1];
> >> > struct nlattr *peer_tb[IFLA_MAX + 1];
> >> > - struct rtnl_link *peer = link->l_info;
> >> > int err;
> >> >
> >> > NL_DBG(3, "Parsing veth link info");
> >> > @@ -51,9 +50,12 @@ static int veth_parse(struct rtnl_link *link, struct nlattr *data,
> >> > goto errout;
> >> >
> >> > if (tb[VETH_INFO_PEER]) {
> >> > + struct rtnl_link *peer = rtnl_link_alloc();
> >
> > Why don't you just use io_alloc()? That way the peer link is always
> > around and you never need to check whether you have created it or not.
> >
>
> Good point! I thought each type of link should provide a rtnl_link_*_alloc()
> API to allocate the correct struct, but it seems better to implement
> ->io_alloc() so that struct would be allocate when calling rtnl_link_set_type().
>
> However, here for veth_parse() it seems rtnl_link_set_type() is not ever
> called by its caller? I suppose rtnl_link_info_parse() should call it.
link_msg_parser() should call it instead of setting l_info_kind
manually. It's a bug.
More information about the libnl
mailing list