]>
Commit | Line | Data |
---|---|---|
ad02a0eb SH |
1 | /* |
2 | * brstate.c RTnetlink port state change | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Stephen Hemminger <shemminger@osdl.org> | |
10 | * | |
11 | * Modified by Srinivas Aji <Aji_Srinivas@emc.com> for use | |
12 | * in RSTP daemon. - 2006-09-01 | |
13 | */ | |
14 | ||
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | #include <unistd.h> | |
18 | #include <syslog.h> | |
19 | #include <fcntl.h> | |
20 | #include <sys/socket.h> | |
21 | #include <sys/time.h> | |
22 | #include <net/if.h> | |
23 | #include <netinet/in.h> | |
24 | #include <linux/if_bridge.h> | |
25 | #include <string.h> | |
26 | ||
27 | #include "libnetlink.h" | |
28 | ||
ad02a0eb SH |
29 | static int br_set_state(struct rtnl_handle *rth, unsigned ifindex, __u8 state) |
30 | { | |
31 | struct { | |
11904a35 SH |
32 | struct nlmsghdr n; |
33 | struct ifinfomsg ifi; | |
34 | char buf[256]; | |
ad02a0eb SH |
35 | } req; |
36 | ||
37 | memset(&req, 0, sizeof(req)); | |
38 | ||
39 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); | |
11904a35 | 40 | req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_REPLACE; |
ad02a0eb SH |
41 | req.n.nlmsg_type = RTM_SETLINK; |
42 | req.ifi.ifi_family = AF_BRIDGE; | |
43 | req.ifi.ifi_index = ifindex; | |
44 | ||
45 | addattr32(&req.n, sizeof(req.buf), IFLA_PROTINFO, state); | |
11904a35 | 46 | |
ad02a0eb SH |
47 | return rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL); |
48 | } | |
49 | ||
50 | static int br_send_bpdu(struct rtnl_handle *rth, unsigned ifindex, | |
11904a35 | 51 | const unsigned char *data, int len) |
ad02a0eb SH |
52 | { |
53 | struct { | |
11904a35 SH |
54 | struct nlmsghdr n; |
55 | struct ifinfomsg ifi; | |
56 | char buf[256]; | |
ad02a0eb SH |
57 | } req; |
58 | ||
59 | memset(&req, 0, sizeof(req)); | |
60 | ||
61 | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); | |
11904a35 | 62 | req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_REPLACE; |
ad02a0eb SH |
63 | req.n.nlmsg_type = RTM_SETLINK; |
64 | req.ifi.ifi_family = AF_BRIDGE; | |
65 | req.ifi.ifi_index = ifindex; | |
66 | ||
67 | addattr_l(&req.n, sizeof(req.buf), IFLA_PRIORITY, data, len); | |
11904a35 | 68 | |
ad02a0eb SH |
69 | return rtnl_talk(rth, &req.n, 0, 0, NULL, NULL, NULL); |
70 | } | |
71 | ||
ad02a0eb SH |
72 | #include "bridge_ctl.h" |
73 | ||
74 | extern struct rtnl_handle rth_state; | |
75 | ||
76 | int bridge_set_state(int ifindex, int brstate) | |
77 | { | |
11904a35 SH |
78 | int err = br_set_state(&rth_state, ifindex, brstate); |
79 | if (err < 0) { | |
80 | fprintf(stderr, | |
81 | "Couldn't set bridge state, ifindex %d, state %d\n", | |
82 | ifindex, brstate); | |
83 | return -1; | |
84 | } | |
85 | return 0; | |
ad02a0eb SH |
86 | } |
87 | ||
88 | int bridge_send_bpdu(int ifindex, const unsigned char *data, int len) | |
89 | { | |
11904a35 SH |
90 | int err = br_send_bpdu(&rth_state, ifindex, data, len); |
91 | if (err < 0) { | |
92 | fprintf(stderr, "Couldn't send bpdu, ifindex %d\n", ifindex); | |
93 | return -1; | |
94 | } | |
95 | return 0; | |
ad02a0eb | 96 | } |