]>
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 | ||
ad02a0eb SH |
50 | #include "bridge_ctl.h" |
51 | ||
52 | extern struct rtnl_handle rth_state; | |
53 | ||
54 | int bridge_set_state(int ifindex, int brstate) | |
55 | { | |
11904a35 SH |
56 | int err = br_set_state(&rth_state, ifindex, brstate); |
57 | if (err < 0) { | |
58 | fprintf(stderr, | |
59 | "Couldn't set bridge state, ifindex %d, state %d\n", | |
60 | ifindex, brstate); | |
61 | return -1; | |
62 | } | |
63 | return 0; | |
ad02a0eb | 64 | } |