Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 255863
b: refs/heads/master
c: 670dc28
h: refs/heads/master
i:
  255861: 9c13d24
  255859: 7a06279
  255855: 7d9a93c
v: v3
  • Loading branch information
Johannes Berg authored and John W. Linville committed Jun 22, 2011
1 parent 194e31a commit 6ccacb1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c1c3daee97498f5d74bfd23531cfe23c8e14a619
refs/heads/master: 670dc2833d144375eac36ad74111495a825a9288
2 changes: 2 additions & 0 deletions trunk/include/linux/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct nlmsghdr {
#define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */
#define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
#define NLM_F_ECHO 8 /* Echo this request */
#define NLM_F_DUMP_INTR 16 /* Dump was inconsistent due to sequence change */

/* Modifiers to GET request */
#define NLM_F_ROOT 0x100 /* specify tree root */
Expand Down Expand Up @@ -221,6 +222,7 @@ struct netlink_callback {
struct netlink_callback *cb);
int (*done)(struct netlink_callback *cb);
int family;
unsigned int prev_seq, seq;
long args[6];
};

Expand Down
32 changes: 32 additions & 0 deletions trunk/include/net/genetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,38 @@ static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq,
return (char *) hdr + GENL_HDRLEN;
}

/**
* genlmsg_nlhdr - Obtain netlink header from user specified header
* @user_hdr: user header as returned from genlmsg_put()
* @family: generic netlink family
*
* Returns pointer to netlink header.
*/
static inline struct nlmsghdr *genlmsg_nlhdr(void *user_hdr,
struct genl_family *family)
{
return (struct nlmsghdr *)((char *)user_hdr -
family->hdrsize -
GENL_HDRLEN -
NLMSG_HDRLEN);
}

/**
* genl_dump_check_consistent - check if sequence is consistent and advertise if not
* @cb: netlink callback structure that stores the sequence number
* @user_hdr: user header as returned from genlmsg_put()
* @family: generic netlink family
*
* Cf. nl_dump_check_consistent(), this just provides a wrapper to make it
* simpler to use with generic netlink.
*/
static inline void genl_dump_check_consistent(struct netlink_callback *cb,
void *user_hdr,
struct genl_family *family)
{
nl_dump_check_consistent(cb, genlmsg_nlhdr(user_hdr, family));
}

/**
* genlmsg_put_reply - Add generic netlink header to a reply message
* @skb: socket buffer holding the message
Expand Down
24 changes: 24 additions & 0 deletions trunk/include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,30 @@ static inline int nlmsg_unicast(struct sock *sk, struct sk_buff *skb, u32 pid)
nlmsg_ok(pos, rem); \
pos = nlmsg_next(pos, &(rem)))

/**
* nl_dump_check_consistent - check if sequence is consistent and advertise if not
* @cb: netlink callback structure that stores the sequence number
* @nlh: netlink message header to write the flag to
*
* This function checks if the sequence (generation) number changed during dump
* and if it did, advertises it in the netlink message header.
*
* The correct way to use it is to set cb->seq to the generation counter when
* all locks for dumping have been acquired, and then call this function for
* each message that is generated.
*
* Note that due to initialisation concerns, 0 is an invalid sequence number
* and must not be used by code that uses this functionality.
*/
static inline void
nl_dump_check_consistent(struct netlink_callback *cb,
struct nlmsghdr *nlh)
{
if (cb->prev_seq && cb->seq != cb->prev_seq)
nlh->nlmsg_flags |= NLM_F_DUMP_INTR;
cb->prev_seq = cb->seq;
}

/**************************************************************************
* Netlink Attributes
**************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions trunk/net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,8 @@ static int netlink_dump(struct sock *sk)
if (!nlh)
goto errout_skb;

nl_dump_check_consistent(cb, nlh);

memcpy(nlmsg_data(nlh), &len, sizeof(len));

if (sk_filter(sk, skb))
Expand Down

0 comments on commit 6ccacb1

Please sign in to comment.