]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/vlan-util.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / shared / vlan-util.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
267fabd2
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2016 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
267fabd2 21#include "conf-parser.h"
0d6c68eb
TJ
22#include "parse-util.h"
23#include "string-util.h"
24#include "vlan-util.h"
267fabd2
LP
25
26int parse_vlanid(const char *p, uint16_t *ret) {
27 uint16_t id;
28 int r;
29
30 r = safe_atou16(p, &id);
31 if (r < 0)
32 return r;
33 if (!vlanid_is_valid(id))
34 return -ERANGE;
35
36 *ret = id;
37 return 0;
38}
39
0d6c68eb
TJ
40int config_parse_default_port_vlanid(
41 const char *unit,
42 const char *filename,
43 unsigned line,
44 const char *section,
45 unsigned section_line,
46 const char *lvalue,
47 int ltype,
48 const char *rvalue,
49 void *data,
50 void *userdata) {
51 uint16_t *id = data;
52
53 assert(lvalue);
54 assert(rvalue);
55 assert(data);
56
57 if (streq(rvalue, "none")) {
58 *id = 0;
59 return 0;
60 }
61
62 return config_parse_vlanid(unit, filename, line, section, section_line,
63 lvalue, ltype, rvalue, data, userdata);
64}
65
267fabd2
LP
66int config_parse_vlanid(
67 const char *unit,
68 const char *filename,
69 unsigned line,
70 const char *section,
71 unsigned section_line,
72 const char *lvalue,
73 int ltype,
74 const char *rvalue,
75 void *data,
76 void *userdata) {
77
78 uint16_t *id = data;
79 int r;
80
81 assert(filename);
82 assert(lvalue);
83 assert(rvalue);
84 assert(data);
85
86 r = parse_vlanid(rvalue, id);
87 if (r == -ERANGE) {
88 log_syntax(unit, LOG_ERR, filename, line, r, "VLAN identifier outside of valid range 0…4094, ignoring: %s", rvalue);
89 return 0;
90 }
91 if (r < 0) {
92 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse VLAN identifier value, ignoring: %s", rvalue);
93 return 0;
94 }
95
96 return 0;
97}