mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-11-05 02:29:07 +00:00
ipnetns: make net namespace cache variable size
Save some space by using variable size for nsid cache elements. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
7f9dddbe7d
commit
2f29d6bb50
@ -139,7 +139,7 @@ struct nsid_cache {
|
|||||||
struct hlist_node nsid_hash;
|
struct hlist_node nsid_hash;
|
||||||
struct hlist_node name_hash;
|
struct hlist_node name_hash;
|
||||||
int nsid;
|
int nsid;
|
||||||
char name[NAME_MAX];
|
char name[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NSIDMAP_SIZE 128
|
#define NSIDMAP_SIZE 128
|
||||||
@ -164,7 +164,7 @@ static struct nsid_cache *netns_map_get_by_nsid(int nsid)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int netns_map_add(int nsid, char *name)
|
static int netns_map_add(int nsid, const char *name)
|
||||||
{
|
{
|
||||||
struct nsid_cache *c;
|
struct nsid_cache *c;
|
||||||
uint32_t h;
|
uint32_t h;
|
||||||
@ -172,7 +172,7 @@ static int netns_map_add(int nsid, char *name)
|
|||||||
if (netns_map_get_by_nsid(nsid) != NULL)
|
if (netns_map_get_by_nsid(nsid) != NULL)
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
|
||||||
c = malloc(sizeof(*c));
|
c = malloc(sizeof(*c) + strlen(name));
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user