Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 6369
b: refs/heads/master
c: 9a4595b
h: refs/heads/master
i:
  6367: c759821
v: v3
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Aug 29, 2005
1 parent 8363146 commit 78f4ee7
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f7fa9b10edbb9391bdd4ec8e8b3d621d0664b198
refs/heads/master: 9a4595bc7e67962f13232ee55a64e063062c3a99
9 changes: 9 additions & 0 deletions trunk/include/linux/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ struct nlmsgerr
struct nlmsghdr msg;
};

#define NETLINK_ADD_MEMBERSHIP 1
#define NETLINK_DROP_MEMBERSHIP 2
#define NETLINK_PKTINFO 3

struct nl_pktinfo
{
__u32 group;
};

#define NET_MAJOR 36 /* Major 36 is reserved for networking */

enum {
Expand Down
1 change: 1 addition & 0 deletions trunk/include/linux/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct ucred {
#define SOL_NETBEUI 267
#define SOL_LLC 268
#define SOL_DCCP 269
#define SOL_NETLINK 270

/* IPX options */
#define IPX_TYPE 1
Expand Down
95 changes: 93 additions & 2 deletions trunk/net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct netlink_sock {
};

#define NETLINK_KERNEL_SOCKET 0x1
#define NETLINK_RECV_PKTINFO 0x2

static inline struct netlink_sock *nlk_sk(struct sock *sk)
{
Expand Down Expand Up @@ -946,6 +947,94 @@ void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)
read_unlock(&nl_table_lock);
}

static int netlink_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, int optlen)
{
struct sock *sk = sock->sk;
struct netlink_sock *nlk = nlk_sk(sk);
int val = 0, err;

if (level != SOL_NETLINK)
return -ENOPROTOOPT;

if (optlen >= sizeof(int) &&
get_user(val, (int __user *)optval))
return -EFAULT;

switch (optname) {
case NETLINK_PKTINFO:
if (val)
nlk->flags |= NETLINK_RECV_PKTINFO;
else
nlk->flags &= ~NETLINK_RECV_PKTINFO;
err = 0;
break;
case NETLINK_ADD_MEMBERSHIP:
case NETLINK_DROP_MEMBERSHIP: {
unsigned int subscriptions;
int old, new = optname == NETLINK_ADD_MEMBERSHIP ? 1 : 0;

if (!netlink_capable(sock, NL_NONROOT_RECV))
return -EPERM;
if (!val || val - 1 >= nlk->ngroups)
return -EINVAL;
netlink_table_grab();
old = test_bit(val - 1, nlk->groups);
subscriptions = nlk->subscriptions - old + new;
if (new)
__set_bit(val - 1, nlk->groups);
else
__clear_bit(val - 1, nlk->groups);
netlink_update_subscriptions(sk, subscriptions);
netlink_table_ungrab();
err = 0;
break;
}
default:
err = -ENOPROTOOPT;
}
return err;
}

static int netlink_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen)
{
struct sock *sk = sock->sk;
struct netlink_sock *nlk = nlk_sk(sk);
int len, val, err;

if (level != SOL_NETLINK)
return -ENOPROTOOPT;

if (get_user(len, optlen))
return -EFAULT;
if (len < 0)
return -EINVAL;

switch (optname) {
case NETLINK_PKTINFO:
if (len < sizeof(int))
return -EINVAL;
len = sizeof(int);
val = nlk->flags & NETLINK_RECV_PKTINFO ? 1 : 0;
put_user(len, optlen);
put_user(val, optval);
err = 0;
break;
default:
err = -ENOPROTOOPT;
}
return err;
}

static void netlink_cmsg_recv_pktinfo(struct msghdr *msg, struct sk_buff *skb)
{
struct nl_pktinfo info;

info.group = NETLINK_CB(skb).dst_group;
put_cmsg(msg, SOL_NETLINK, NETLINK_PKTINFO, sizeof(info), &info);
}

static inline void netlink_rcv_wake(struct sock *sk)
{
struct netlink_sock *nlk = nlk_sk(sk);
Expand Down Expand Up @@ -1091,6 +1180,8 @@ static int netlink_recvmsg(struct kiocb *kiocb, struct socket *sock,
netlink_dump(sk);

scm_recv(sock, msg, siocb->scm, flags);
if (nlk->flags & NETLINK_RECV_PKTINFO)
netlink_cmsg_recv_pktinfo(msg, skb);

out:
netlink_rcv_wake(sk);
Expand Down Expand Up @@ -1465,8 +1556,8 @@ static struct proto_ops netlink_ops = {
.ioctl = sock_no_ioctl,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.setsockopt = sock_no_setsockopt,
.getsockopt = sock_no_getsockopt,
.setsockopt = netlink_setsockopt,
.getsockopt = netlink_getsockopt,
.sendmsg = netlink_sendmsg,
.recvmsg = netlink_recvmsg,
.mmap = sock_no_mmap,
Expand Down

0 comments on commit 78f4ee7

Please sign in to comment.