mirror of
https://github.com/systemd/systemd.git
synced 2024-11-04 13:51:24 +03:00
network: move NetworkConfigSection and related functions to networkd-util.[ch]
This commit is contained in:
parent
95dba43542
commit
48315d3dca
@ -26,42 +26,6 @@
|
||||
/* Let's assume that anything above this number is a user misconfiguration. */
|
||||
#define MAX_NTP_SERVERS 128
|
||||
|
||||
static void network_config_hash_func(const NetworkConfigSection *c, struct siphash *state) {
|
||||
siphash24_compress(c->filename, strlen(c->filename), state);
|
||||
siphash24_compress(&c->line, sizeof(c->line), state);
|
||||
}
|
||||
|
||||
static int network_config_compare_func(const NetworkConfigSection *x, const NetworkConfigSection *y) {
|
||||
int r;
|
||||
|
||||
r = strcmp(x->filename, y->filename);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
return CMP(x->line, y->line);
|
||||
}
|
||||
|
||||
DEFINE_HASH_OPS(network_config_hash_ops, NetworkConfigSection, network_config_hash_func, network_config_compare_func);
|
||||
|
||||
int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s) {
|
||||
NetworkConfigSection *cs;
|
||||
|
||||
cs = malloc0(offsetof(NetworkConfigSection, filename) + strlen(filename) + 1);
|
||||
if (!cs)
|
||||
return -ENOMEM;
|
||||
|
||||
strcpy(cs->filename, filename);
|
||||
cs->line = line;
|
||||
|
||||
*s = TAKE_PTR(cs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void network_config_section_free(NetworkConfigSection *cs) {
|
||||
free(cs);
|
||||
}
|
||||
|
||||
/* Set defaults following RFC7844 */
|
||||
void network_apply_anonymize_if_set(Network *network) {
|
||||
if (!network->dhcp_anonymize)
|
||||
|
@ -84,16 +84,6 @@ typedef enum RADVPrefixDelegation {
|
||||
_RADV_PREFIX_DELEGATION_INVALID = -1,
|
||||
} RADVPrefixDelegation;
|
||||
|
||||
typedef struct NetworkConfigSection {
|
||||
unsigned line;
|
||||
char filename[];
|
||||
} NetworkConfigSection;
|
||||
|
||||
int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
|
||||
void network_config_section_free(NetworkConfigSection *network);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
|
||||
extern const struct hash_ops network_config_hash_ops;
|
||||
|
||||
typedef struct Manager Manager;
|
||||
|
||||
struct Network {
|
||||
|
@ -102,3 +102,39 @@ int kernel_route_expiration_supported(void) {
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
static void network_config_hash_func(const NetworkConfigSection *c, struct siphash *state) {
|
||||
siphash24_compress(c->filename, strlen(c->filename), state);
|
||||
siphash24_compress(&c->line, sizeof(c->line), state);
|
||||
}
|
||||
|
||||
static int network_config_compare_func(const NetworkConfigSection *x, const NetworkConfigSection *y) {
|
||||
int r;
|
||||
|
||||
r = strcmp(x->filename, y->filename);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
return CMP(x->line, y->line);
|
||||
}
|
||||
|
||||
DEFINE_HASH_OPS(network_config_hash_ops, NetworkConfigSection, network_config_hash_func, network_config_compare_func);
|
||||
|
||||
int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s) {
|
||||
NetworkConfigSection *cs;
|
||||
|
||||
cs = malloc0(offsetof(NetworkConfigSection, filename) + strlen(filename) + 1);
|
||||
if (!cs)
|
||||
return -ENOMEM;
|
||||
|
||||
strcpy(cs->filename, filename);
|
||||
cs->line = line;
|
||||
|
||||
*s = TAKE_PTR(cs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void network_config_section_free(NetworkConfigSection *cs) {
|
||||
free(cs);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "hash-funcs.h"
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum AddressFamilyBoolean {
|
||||
@ -14,6 +15,11 @@ typedef enum AddressFamilyBoolean {
|
||||
_ADDRESS_FAMILY_BOOLEAN_INVALID = -1,
|
||||
} AddressFamilyBoolean;
|
||||
|
||||
typedef struct NetworkConfigSection {
|
||||
unsigned line;
|
||||
char filename[];
|
||||
} NetworkConfigSection;
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_address_family_boolean);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_address_family_boolean_with_kernel);
|
||||
|
||||
@ -21,3 +27,8 @@ const char *address_family_boolean_to_string(AddressFamilyBoolean b) _const_;
|
||||
AddressFamilyBoolean address_family_boolean_from_string(const char *s) _const_;
|
||||
|
||||
int kernel_route_expiration_supported(void);
|
||||
|
||||
int network_config_section_new(const char *filename, unsigned line, NetworkConfigSection **s);
|
||||
void network_config_section_free(NetworkConfigSection *network);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(NetworkConfigSection*, network_config_section_free);
|
||||
extern const struct hash_ops network_config_hash_ops;
|
||||
|
Loading…
Reference in New Issue
Block a user