]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/lldp-port.c
2 This file is part of systemd.
4 Copyright (C) 2014 Tom Gundersen
5 Copyright (C) 2014 Susant Sahani
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.
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.
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/>.
21 #include "alloc-util.h"
23 #include "lldp-internal.h"
24 #include "lldp-network.h"
25 #include "lldp-port.h"
27 int lldp_port_start(lldp_port
*p
) {
30 assert_return(p
, -EINVAL
);
32 r
= lldp_network_bind_raw_socket(p
->ifindex
);
38 r
= sd_event_add_io(p
->event
, &p
->lldp_port_rx
,
39 p
->rawfd
, EPOLLIN
, lldp_receive_packet
, p
);
41 log_debug_errno(r
, "Failed to allocate event source: %m");
45 r
= sd_event_source_set_priority(p
->lldp_port_rx
, p
->event_priority
);
47 log_debug_errno(r
, "Failed to set event priority: %m");
51 r
= sd_event_source_set_description(p
->lldp_port_rx
, "lldp-port-rx");
53 log_debug_errno(r
, "Failed to set event name: %m");
65 int lldp_port_stop(lldp_port
*p
) {
67 assert_return(p
, -EINVAL
);
69 p
->rawfd
= asynchronous_close(p
->rawfd
);
70 p
->lldp_port_rx
= sd_event_source_unref(p
->lldp_port_rx
);
75 void lldp_port_free(lldp_port
*p
) {
85 int lldp_port_new(int ifindex
,
87 const struct ether_addr
*addr
,
90 _cleanup_free_ lldp_port
*p
= NULL
;
92 assert_return(ifindex
, -EINVAL
);
93 assert_return(ifname
, -EINVAL
);
94 assert_return(addr
, -EINVAL
);
96 p
= new0(lldp_port
, 1);
101 p
->ifindex
= ifindex
;
103 p
->ifname
= strdup(ifname
);
107 memcpy(&p
->mac
, addr
, ETH_ALEN
);
109 p
->userdata
= userdata
;