-
Notifications
You must be signed in to change notification settings - Fork 0
/
eql_enslave.c
118 lines (100 loc) · 2.13 KB
/
eql_enslave.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* eql_enslave
*
* modeled from ifslave.c by Alan Cox (presumably?)
*
* (c) Copyright 1995 Simon Janes
* NCM: Network and Communications Management, Inc.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <linux/if.h>
#ifndef list_head
struct list_head {
struct list_head *next, *prev;
};
#endif
#include <linux/if_eql.h>
void check_running(char *device_name);
int s;
int
main(int argc, char **argv)
{
struct ifreq ifr;
slaving_request_t slaving_request;
char master_name[16];
int slave_mtu;
int master_mtu;
if (argc != 4)
{
fprintf (stderr, "usage: %s <master> <slave> <priority>\n", argv[0]);
exit (1);
}
strcpy (master_name, argv[1]);
strcpy (slaving_request.slave_name, argv[2]);
slaving_request.priority = atol (argv[3]);
s = socket (AF_INET, SOCK_DGRAM, 0);
if ( s == -1)
{
perror ("socket");
exit (1);
}
check_running (master_name);
check_running (slaving_request.slave_name);
strcpy (ifr.ifr_name, slaving_request.slave_name);
if (ioctl (s, SIOCGIFMTU, &ifr) == -1)
{
perror("get MTU on slave failed");
exit (1);
}
slave_mtu = ifr.ifr_mtu;
strcpy (ifr.ifr_name, master_name);
if (ioctl (s, SIOCGIFMTU, &ifr) == -1)
{
perror("get MTU on master failed");
exit (1);
}
master_mtu = ifr.ifr_mtu;
if ( master_mtu != slave_mtu )
{
fprintf (stderr,
"master (%d) and slave (%d) MTU settings do not match\n",
master_mtu, slave_mtu);
exit (1);
}
strcpy (ifr.ifr_name, master_name);
ifr.ifr_data = (caddr_t) &slaving_request;
if(ioctl (s,EQL_ENSLAVE, &ifr)==-1)
{
perror("EQL_ENSLAVE failed");
exit (1);
}
return 0;
}
void
check_running(char *name)
{
struct ifreq ifr;
strcpy (ifr.ifr_name, name);
if ( ioctl (s, SIOCGIFFLAGS, &ifr) == -1)
{
perror (name);
exit (1);
}
if (ifr.ifr_flags & ((IFF_RUNNING | IFF_UP) != (IFF_RUNNING | IFF_UP)))
{
fprintf (stderr, "Device '%s' is not up or running.\n", name);
exit (1);
}
}
/*
* Local Variables:
* compile-command: "gcc -Wall -Wstrict-prototypes -o eql_enslave eql_enslave.c"
* End:
*/