diff options
-rw-r--r-- | include/net/sock.h | 1 | ||||
-rw-r--r-- | net/core/sock.c | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 1c9d059223ee..abc6341f536f 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -562,6 +562,7 @@ struct proto { | |||
562 | 562 | ||
563 | /* Keeping track of sockets in use */ | 563 | /* Keeping track of sockets in use */ |
564 | #ifdef CONFIG_PROC_FS | 564 | #ifdef CONFIG_PROC_FS |
565 | unsigned int inuse_idx; | ||
565 | struct pcounter inuse; | 566 | struct pcounter inuse; |
566 | #endif | 567 | #endif |
567 | 568 | ||
diff --git a/net/core/sock.c b/net/core/sock.c index 3ee95060dbd0..7d2c8add5f5a 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -1940,6 +1940,38 @@ EXPORT_SYMBOL(sk_common_release); | |||
1940 | static DEFINE_RWLOCK(proto_list_lock); | 1940 | static DEFINE_RWLOCK(proto_list_lock); |
1941 | static LIST_HEAD(proto_list); | 1941 | static LIST_HEAD(proto_list); |
1942 | 1942 | ||
1943 | #ifdef CONFIG_PROC_FS | ||
1944 | #define PROTO_INUSE_NR 64 /* should be enough for the first time */ | ||
1945 | |||
1946 | static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR); | ||
1947 | |||
1948 | static void assign_proto_idx(struct proto *prot) | ||
1949 | { | ||
1950 | prot->inuse_idx = find_first_zero_bit(proto_inuse_idx, PROTO_INUSE_NR); | ||
1951 | |||
1952 | if (unlikely(prot->inuse_idx == PROTO_INUSE_NR - 1)) { | ||
1953 | printk(KERN_ERR "PROTO_INUSE_NR exhausted\n"); | ||
1954 | return; | ||
1955 | } | ||
1956 | |||
1957 | set_bit(prot->inuse_idx, proto_inuse_idx); | ||
1958 | } | ||
1959 | |||
1960 | static void release_proto_idx(struct proto *prot) | ||
1961 | { | ||
1962 | if (prot->inuse_idx != PROTO_INUSE_NR - 1) | ||
1963 | clear_bit(prot->inuse_idx, proto_inuse_idx); | ||
1964 | } | ||
1965 | #else | ||
1966 | static inline void assign_proto_idx(struct proto *prot) | ||
1967 | { | ||
1968 | } | ||
1969 | |||
1970 | static inline void release_proto_idx(struct proto *prot) | ||
1971 | { | ||
1972 | } | ||
1973 | #endif | ||
1974 | |||
1943 | int proto_register(struct proto *prot, int alloc_slab) | 1975 | int proto_register(struct proto *prot, int alloc_slab) |
1944 | { | 1976 | { |
1945 | char *request_sock_slab_name = NULL; | 1977 | char *request_sock_slab_name = NULL; |
@@ -2000,6 +2032,7 @@ int proto_register(struct proto *prot, int alloc_slab) | |||
2000 | 2032 | ||
2001 | write_lock(&proto_list_lock); | 2033 | write_lock(&proto_list_lock); |
2002 | list_add(&prot->node, &proto_list); | 2034 | list_add(&prot->node, &proto_list); |
2035 | assign_proto_idx(prot); | ||
2003 | write_unlock(&proto_list_lock); | 2036 | write_unlock(&proto_list_lock); |
2004 | return 0; | 2037 | return 0; |
2005 | 2038 | ||
@@ -2026,6 +2059,7 @@ EXPORT_SYMBOL(proto_register); | |||
2026 | void proto_unregister(struct proto *prot) | 2059 | void proto_unregister(struct proto *prot) |
2027 | { | 2060 | { |
2028 | write_lock(&proto_list_lock); | 2061 | write_lock(&proto_list_lock); |
2062 | release_proto_idx(prot); | ||
2029 | list_del(&prot->node); | 2063 | list_del(&prot->node); |
2030 | write_unlock(&proto_list_lock); | 2064 | write_unlock(&proto_list_lock); |
2031 | 2065 | ||