Check-in [3c94381d8b]
Overview
Comment:Added brctl support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3c94381d8b7062ede247dc83bfffcb01e8a6191d
User & Date: rkeene on 2012-08-22 03:31:33
Other Links: manifest | tags
Context
2012-08-22
03:36
Added stub for "vconfig" check-in: e327d24256 user: rkeene tags: trunk
03:31
Added brctl support check-in: 3c94381d8b user: rkeene tags: trunk
2012-08-11
23:17
Corrected bug in "ifconfig" check-in: 34b2401d6e user: rkeene tags: trunk
Changes

Modified initrd/admin-tclkit/kitcreator-modules/system/build-dyn.sh from [02da656833] to [078554ca42].

1
2
3
4
5
6
7
8
9
10
11
12
# /bin/bash

# Perform common build options
. build-common.sh

# Compile using the same options as Tcl
TCLCONFIGSH="$(find /usr/lib /usr/local/lib /lib -name tclConfig.sh -print -quit)"

. "${TCLCONFIGSH}"

echo "${TCL_CC} -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c"
eval ${TCL_CC} -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c






|



|
|
1
2
3
4
5
6
7
8
9
10
11
12
# /bin/bash

# Perform common build options
. build-common.sh

# Compile using the same options as Tcl
TCLCONFIGSH="$(find /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /lib /lib64 -name tclConfig.sh -print -quit)"

. "${TCLCONFIGSH}"

echo "${TCL_CC} -fPIC -DPIC -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c"
eval ${TCL_CC} -fPIC -DPIC -Wall -DUSE_TCL_STUBS=1 ${TCL_DEFS} ${TCL_INCLUDE_SPEC} ${TCL_STUB_LIB_SPEC} -shared -rdynamic -o system.so system.c

Modified initrd/admin-tclkit/kitcreator-modules/system/system.c from [382721d0da] to [1594c1fd70].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
#include <errno.h>
#include <tcl.h>

#include <linux/sockios.h>
#include <linux/route.h>
#include <linux/if.h>
#include <linux/if_arp.h>

#include <linux/loop.h>
#include <linux/fs.h>

#ifndef HOST_NAME_MAX
/* SUSv2 Limit */
#define HOST_NAME_MAX 255
#endif







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <errno.h>
#include <tcl.h>

#include <linux/sockios.h>
#include <linux/route.h>
#include <linux/if.h>
#include <linux/if_arp.h>
#include <linux/if_bridge.h>
#include <linux/loop.h>
#include <linux/fs.h>

#ifndef HOST_NAME_MAX
/* SUSv2 Limit */
#define HOST_NAME_MAX 255
#endif
114
115
116
117
118
119
120














































121
122
123
124
125
126
127
	hashval_obj = Tcl_NewObj();
	Tcl_SetWideIntObj(hashval_obj, hashval);

	Tcl_SetObjResult(interp, hashval_obj);

	return(TCL_OK);
}















































/*
 * Low-level System Call Wrapper Procedures
 *
 * These procedures should minimally wrap Linux or UNIX system calls to
 * expose to the Tcl-level.  Where possible accept symbolic names rather
 * than numeric values (.e.g, list of values to OR together to get flags).







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
	hashval_obj = Tcl_NewObj();
	Tcl_SetWideIntObj(hashval_obj, hashval);

	Tcl_SetObjResult(interp, hashval_obj);

	return(TCL_OK);
}

static int tclsystem_internal_getsock(int *sock_v4_out, int *sock_v6_out) {
	int sock_v4 = -1, sock_v6 = -1;
	int sock;

	if (sock_v4_out == NULL && sock_v6_out == NULL) {
		return(-1);
	}

	if (sock_v4_out != NULL) {
		/*
		 * Check for IPv4 support before trying to create an IPv4 socket to
		 * avoid demand-loading IPv4 (XXX: TODO)
		 */
		sock_v4 = socket(AF_INET, SOCK_DGRAM, 0);
	}

	if (sock_v6_out != NULL) {
		/*
		 * Check for IPv6 support before trying to create an IPv6 socket to
		 * avoid demand-loading IPv6 (XXX: TODO)
		 */
		sock_v6 = socket(AF_INET6, SOCK_DGRAM, 0);
	}

	/* Pick a socket to query for the interface list */
	if (sock_v4 == -1 && sock_v6 == -1) {
		return(-1);
	}

	if (sock_v6 != -1) {
		sock = sock_v6;
	} else {
		sock = sock_v4;
	}

	if (sock_v4_out != NULL) {
		*sock_v4_out = sock_v4;
	}

	if (sock_v6_out != NULL) {
		*sock_v6_out = sock_v6;
	}

	return(sock);
}

/*
 * Low-level System Call Wrapper Procedures
 *
 * These procedures should minimally wrap Linux or UNIX system calls to
 * expose to the Tcl-level.  Where possible accept symbolic names rather
 * than numeric values (.e.g, list of values to OR together to get flags).
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
	return(TCL_OK);
}

static int tclsystem_ifconfig(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	int sock_v4, sock_v6, sock;
	int retval = TCL_ERROR;

	/*
	 * Check for IPv4 support before trying to create an IPv4 socket to
	 * avoid demand-loading IPv4 (XXX: TODO)
	 */
	sock_v4 = socket(AF_INET, SOCK_DGRAM, 0);

	/*
	 * Check for IPv6 support before trying to create an IPv6 socket to
	 * avoid demand-loading IPv6 (XXX: TODO)
	 */
	sock_v6 = socket(AF_INET6, SOCK_DGRAM, 0);

	/* Pick a socket to query for the interface list */
	if (sock_v4 == -1 && sock_v6 == -1) {
		/* Report failure */
		Tcl_SetObjResult(interp, Tcl_NewStringObj("unable to create socket", -1));

		return(TCL_ERROR);
	}

	if (sock_v6 != -1) {
		sock = sock_v6;
	} else {
		sock = sock_v4;
	}

	switch (objc) {
		case 0:
		case 1: /* No arguments, list all interfaces */
			retval = tclsystem_ifconfig_list(cd, interp, objc, objv, sock);

			break;
		case 2: /* One argument, give information about the interface */







<
<
<
<
<
|
<
<
<
<
<
|
<
<
<





<
<
<
<
<
<







1458
1459
1460
1461
1462
1463
1464





1465





1466



1467
1468
1469
1470
1471






1472
1473
1474
1475
1476
1477
1478
	return(TCL_OK);
}

static int tclsystem_ifconfig(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	int sock_v4, sock_v6, sock;
	int retval = TCL_ERROR;






	sock = tclsystem_internal_getsock(&sock_v4, &sock_v6);





	if (sock == -1) {



		Tcl_SetObjResult(interp, Tcl_NewStringObj("unable to create socket", -1));

		return(TCL_ERROR);
	}







	switch (objc) {
		case 0:
		case 1: /* No arguments, list all interfaces */
			retval = tclsystem_ifconfig_list(cd, interp, objc, objv, sock);

			break;
		case 2: /* One argument, give information about the interface */
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698


























































































































1699
1700
1701
1702
1703
1704
1705
	return(TCL_OK);
}

static int tclsystem_route(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	int sock_v4, sock_v6, sock;
	int retval = TCL_ERROR;

	/*
	 * Check for IPv4 support before trying to create an IPv4 socket to
	 * avoid demand-loading IPv4 (XXX: TODO)
	 */
	sock_v4 = socket(AF_INET, SOCK_DGRAM, 0);

	/*
	 * Check for IPv6 support before trying to create an IPv6 socket to
	 * avoid demand-loading IPv6 (XXX: TODO)
	 */
	sock_v6 = socket(AF_INET6, SOCK_DGRAM, 0);

	/* Pick a socket to query for the interface list */
	if (sock_v4 == -1 && sock_v6 == -1) {
		/* Report failure */
		Tcl_SetObjResult(interp, Tcl_NewStringObj("unable to create socket", -1));

		return(TCL_ERROR);
	}

	if (sock_v6 != -1) {
		sock = sock_v6;
	} else {
		sock = sock_v4;
	}

	switch (objc) {
		case 0:
		case 1: /* No arguments, list all interfaces */
			retval = tclsystem_route_list(cd, interp, objc, objv, sock_v4, sock_v6);

			break;
		default:
			/* Otherwise, modify routes */
			retval = tclsystem_route_conf(cd, interp, objc, objv, sock_v4, sock_v6);



























































































































			break;
	}

	/* Cleanup */
	if (sock_v4 != -1) {
		close(sock_v4);
	}







<
<
<
<
<
|
<
<
<
<
<
|
<
<
<





<
<
<
<
<
<










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1684
1685
1686
1687
1688
1689
1690





1691





1692



1693
1694
1695
1696
1697






1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
	return(TCL_OK);
}

static int tclsystem_route(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	int sock_v4, sock_v6, sock;
	int retval = TCL_ERROR;






	sock = tclsystem_internal_getsock(&sock_v4, &sock_v6);





	if (sock == -1) {



		Tcl_SetObjResult(interp, Tcl_NewStringObj("unable to create socket", -1));

		return(TCL_ERROR);
	}







	switch (objc) {
		case 0:
		case 1: /* No arguments, list all interfaces */
			retval = tclsystem_route_list(cd, interp, objc, objv, sock_v4, sock_v6);

			break;
		default:
			/* Otherwise, modify routes */
			retval = tclsystem_route_conf(cd, interp, objc, objv, sock_v4, sock_v6);

			break;
	}

	/* Cleanup */
	if (sock_v4 != -1) {
		close(sock_v4);
	}

	if (sock_v6 != -1) {
		close(sock_v6);
	}

	return(retval);
}

static int tclsystem_brctl_list(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int sock) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("not implemented", -1));

	return(TCL_ERROR);
}

static int tclsystem_brctl_conf(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], int sock) {
	Tcl_Obj *operation_obj, *bridge_name_obj, *interface_name_obj;
	unsigned long arg[4];
	struct ifreq ifr;
	int ioctl_ret, ioctl_id;
	int add = 0;

	/* Determine operation */
	operation_obj = objv[1];
	switch (tclsystem_internal_simplehash_obj(operation_obj)) {
		case 0x1c993272: /* addbr */
			add = 1;
		case 0x4cbb3272: /* delbr */
			if (objc != 3) {
				if (add) {
					Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::brctl addbr bridge\"", -1));
				} else {
					Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::brctl delbr bridge\"", -1));
				}

				return(TCL_ERROR);
			}

			bridge_name_obj = objv[2];

			if (add) {
				arg[0] = BRCTL_ADD_BRIDGE;
			} else {
				arg[0] = BRCTL_DEL_BRIDGE;
			}

			arg[1] = (unsigned long) Tcl_GetString(bridge_name_obj);
			arg[2] = 0;

			ioctl_ret = ioctl(sock, SIOCGIFBR, &arg); 

			break;
		case 0x1C9937E6: /* addif */
			add = 1;
		case 0x4cbb37e6: /* delif */
			if (objc != 4) {
				if (add) {
					Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::brctl addif bridge interface\"", -1));
				} else {
					Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args: should be \"::system::syscall::brctl delif bridge interface\"", -1));
				}

				return(TCL_ERROR);
			}

			if (add) {
				ioctl_id = SIOCBRADDIF;
			} else {
				ioctl_id = SIOCBRDELIF;
			}

			bridge_name_obj = objv[2];
			interface_name_obj = objv[3];

			memset(&ifr, 0, sizeof(ifr));
			snprintf(ifr.ifr_name, IFNAMSIZ, "%s", Tcl_GetString(interface_name_obj));

			ioctl_ret = ioctl(sock, SIOCGIFINDEX, (void *) &ifr);
			if (ioctl_ret == 0) {
				snprintf(ifr.ifr_name, IFNAMSIZ, "%s", Tcl_GetString(bridge_name_obj));
				ioctl_ret = ioctl(sock, ioctl_id, (void *) &ifr);
			}

			break;
	}

	if (ioctl_ret < 0) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(strerror(errno), -1));

		return(TCL_ERROR);
	}

	return(TCL_OK);
}

static int tclsystem_brctl(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
	int sock_v4, sock_v6, sock;
	int retval = TCL_ERROR;

	sock = tclsystem_internal_getsock(&sock_v4, &sock_v6);
	if (sock == -1) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj("unable to create socket", -1));

		return(TCL_ERROR);
	}

	switch (objc) {
		case 0:
		case 1: /* No arguments, list all bridges */
			retval = tclsystem_brctl_list(cd, interp, objc, objv, sock);

			break;
		default:
			/* Otherwise, modify routes */
			retval = tclsystem_brctl_conf(cd, interp, objc, objv, sock);

			break;
	}

	/* Cleanup */
	if (sock_v4 != -1) {
		close(sock_v4);
	}
1746
1747
1748
1749
1750
1751
1752

1753
1754
1755
1756
1757
1758
1759
	Tcl_CreateObjCommand(interp, "::system::syscall::kill", tclsystem_kill, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::ps", tclsystem_ps, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::execve", tclsystem_execve, NULL, NULL);

	/* Network related commands */
	Tcl_CreateObjCommand(interp, "::system::syscall::ifconfig", tclsystem_ifconfig, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::route", tclsystem_route, NULL, NULL);


	/* Internal functions */
	Tcl_CreateObjCommand(interp, "::system::internal::hash", tclsystem_internalproc_simplehash, NULL, NULL);

	/* Define constants */
	/** Create parent namespace **/
	Tcl_CreateNamespace(interp, "::system::const", NULL, NULL);







>







1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
	Tcl_CreateObjCommand(interp, "::system::syscall::kill", tclsystem_kill, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::ps", tclsystem_ps, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::execve", tclsystem_execve, NULL, NULL);

	/* Network related commands */
	Tcl_CreateObjCommand(interp, "::system::syscall::ifconfig", tclsystem_ifconfig, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::route", tclsystem_route, NULL, NULL);
	Tcl_CreateObjCommand(interp, "::system::syscall::brctl", tclsystem_brctl, NULL, NULL);

	/* Internal functions */
	Tcl_CreateObjCommand(interp, "::system::internal::hash", tclsystem_internalproc_simplehash, NULL, NULL);

	/* Define constants */
	/** Create parent namespace **/
	Tcl_CreateNamespace(interp, "::system::const", NULL, NULL);