Merge pull request #2685 from poettering/lldp-fixes2
lldp fixes, second iteration
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
@@ -17,8 +19,6 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -42,3 +42,26 @@ char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool ether_addr_is_null(const struct ether_addr *addr) {
|
||||
assert(addr);
|
||||
|
||||
return addr->ether_addr_octet[0] == 0 &&
|
||||
addr->ether_addr_octet[1] == 0 &&
|
||||
addr->ether_addr_octet[2] == 0 &&
|
||||
addr->ether_addr_octet[3] == 0 &&
|
||||
addr->ether_addr_octet[4] == 0 &&
|
||||
addr->ether_addr_octet[5] == 0;
|
||||
}
|
||||
|
||||
bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b) {
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
return a->ether_addr_octet[0] == b->ether_addr_octet[0] &&
|
||||
a->ether_addr_octet[1] == b->ether_addr_octet[1] &&
|
||||
a->ether_addr_octet[2] == b->ether_addr_octet[2] &&
|
||||
a->ether_addr_octet[3] == b->ether_addr_octet[3] &&
|
||||
a->ether_addr_octet[4] == b->ether_addr_octet[4] &&
|
||||
a->ether_addr_octet[5] == b->ether_addr_octet[5];
|
||||
}
|
||||
|
||||
@@ -20,10 +20,13 @@
|
||||
***/
|
||||
|
||||
#include <net/ethernet.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define ETHER_ADDR_FORMAT_STR "%02X%02X%02X%02X%02X%02X"
|
||||
#define ETHER_ADDR_FORMAT_VAL(x) (x).ether_addr_octet[0], (x).ether_addr_octet[1], (x).ether_addr_octet[2], (x).ether_addr_octet[3], (x).ether_addr_octet[4], (x).ether_addr_octet[5]
|
||||
|
||||
#define ETHER_ADDR_TO_STRING_MAX (3*6)
|
||||
|
||||
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]);
|
||||
|
||||
bool ether_addr_is_null(const struct ether_addr *addr);
|
||||
bool ether_addr_equal(const struct ether_addr *a, const struct ether_addr *b);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
/* gunicode.h - Unicode manipulation functions
|
||||
*
|
||||
* Copyright (C) 1999, 2000 Tom Tromey
|
||||
* Copyright 2000, 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -48,6 +48,9 @@ bool hostname_is_set(void) {
|
||||
char* gethostname_malloc(void) {
|
||||
struct utsname u;
|
||||
|
||||
/* This call tries to return something useful, either the actual hostname or it makes something up. The only
|
||||
* reason it might mail is OOM. It might even return "localhost" if that's set. */
|
||||
|
||||
assert_se(uname(&u) >= 0);
|
||||
|
||||
if (isempty(u.nodename) || streq(u.nodename, "(none)"))
|
||||
@@ -56,6 +59,31 @@ char* gethostname_malloc(void) {
|
||||
return strdup(u.nodename);
|
||||
}
|
||||
|
||||
int gethostname_strict(char **ret) {
|
||||
struct utsname u;
|
||||
char *k;
|
||||
|
||||
/* This call will rather fail than make up a name. It will not return "localhost" either. */
|
||||
|
||||
assert_se(uname(&u) >= 0);
|
||||
|
||||
if (isempty(u.nodename))
|
||||
return -ENXIO;
|
||||
|
||||
if (streq(u.nodename, "(none)"))
|
||||
return -ENXIO;
|
||||
|
||||
if (is_localhost(u.nodename))
|
||||
return -ENXIO;
|
||||
|
||||
k = strdup(u.nodename);
|
||||
if (!k)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = k;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool hostname_valid_char(char c) {
|
||||
return
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
bool hostname_is_set(void);
|
||||
|
||||
char* gethostname_malloc(void);
|
||||
int gethostname_strict(char **ret);
|
||||
|
||||
bool hostname_is_valid(const char *s, bool allow_trailing_dot) _pure_;
|
||||
char* hostname_cleanup(char *s);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
@@ -17,8 +19,6 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <linux/neighbour.h>
|
||||
#include <linux/oom.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/syscall.h>
|
||||
@@ -1171,4 +1172,8 @@ static inline key_serial_t request_key(const char *type, const char *description
|
||||
#define char16_t uint16_t
|
||||
#endif
|
||||
|
||||
#ifndef ETHERTYPE_LLDP
|
||||
#define ETHERTYPE_LLDP 0x88cc
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
@@ -17,8 +19,6 @@
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
void sigbus_install(void);
|
||||
void sigbus_reset(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user