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