Changeset b4aa23f3434227874cce728d4f56f2e3c74b4e98
- Timestamp:
- 07/03/12 21:17:58 (1 year ago)
- git-parent:
- Files:
-
- docs/config/modules/noit.module.dhcp.xml (added)
- src/modules-lua/Makefile.in (modified) (1 diff)
- src/modules-lua/noit/extras.lua (modified) (1 diff)
- src/modules-lua/noit/module/dhcp.lua (added)
- src/modules/lua_noit.c (modified) (4 diffs)
- src/noit.conf.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/modules-lua/Makefile.in
rde30ea9 rb4aa23f 44 44 noit/module/nrpe.lua \ 45 45 noit/module/redis.lua \ 46 noit/module/nginx.lua 46 noit/module/nginx.lua \ 47 noit/module/dhcp.lua 47 48 48 49 all: src/modules-lua/noit/extras.lua
rde30ea9 rb4aa23f 60 60 end 61 61 62 function iptonumber(str) 63 local num = 0 64 for elem in str:gmatch("%d+") do 65 num = (num * 256) + elem 66 end 67 return num 68 end 69 src/modules/lua_noit.c
r618dd9f rb4aa23f 447 447 int8_t family; 448 448 int rv; 449 int flag; 449 450 union { 450 451 struct sockaddr_in sin4; … … 483 484 a.sin4.sin_family = family; 484 485 a.sin4.sin_port = htons(port); 486 a.sin4.sin_addr.s_addr = INADDR_ANY; 487 memset (a.sin4.sin_zero, 0, sizeof (a.sin4.sin_zero)); 485 488 } 486 489 … … 494 497 lua_pushstring(L, strerror(errno)); 495 498 return 2; 499 } 500 static int 501 noit_lua_socket_setsockopt(lua_State *L) { 502 noit_lua_check_info_t *ci; 503 eventer_t e, *eptr; 504 int rv; 505 const char *type; 506 int type_val; 507 int value; 508 509 ci = get_ci(L); 510 assert(ci); 511 512 if(lua_gettop(L) != 3) { 513 lua_pushinteger(L, -1); 514 lua_pushfstring(L, "setsockopt(type, value) wrong arguments"); 515 return 2; 516 } 517 eptr = lua_touserdata(L, lua_upvalueindex(1)); 518 if(eptr != lua_touserdata(L, 1)) 519 luaL_error(L, "must be called as method"); 520 e = *eptr; 521 type = lua_tostring(L, 2); 522 value = lua_tointeger(L, 3); 523 524 if (strcmp(type, "SO_BROADCAST") == 0) 525 type_val = SO_BROADCAST; 526 else if (strcmp(type, "SO_REUSEADDR") == 0) 527 type_val = SO_REUSEADDR; 528 else if (strcmp(type, "SO_KEEPALIVE") == 0) 529 type_val = SO_KEEPALIVE; 530 else if (strcmp(type, "SO_LINGER") == 0) 531 type_val = SO_LINGER; 532 else if (strcmp(type, "SO_OOBINLINE") == 0) 533 type_val = SO_OOBINLINE; 534 else if (strcmp(type, "SO_SNDBUF") == 0) 535 type_val = SO_SNDBUF; 536 else if (strcmp(type, "SO_RCVBUF") == 0) 537 type_val = SO_RCVBUF; 538 else if (strcmp(type, "SO_DONTROUTE") == 0) 539 type_val = SO_DONTROUTE; 540 else if (strcmp(type, "SO_RCVLOWAT") == 0) 541 type_val = SO_RCVLOWAT; 542 else if (strcmp(type, "SO_RCVTIMEO") == 0) 543 type_val = SO_RCVTIMEO; 544 else if (strcmp(type, "SO_SNDLOWAT") == 0) 545 type_val = SO_SNDLOWAT; 546 else if (strcmp(type, "SO_SNDTIMEO") == 0) 547 type_val = SO_SNDTIMEO; 548 else { 549 lua_pushinteger(L, -1); 550 lua_pushfstring(L, "Socket operation '%s' not supported\n", type); 551 return 2; 552 } 553 554 if (setsockopt(e->fd, SOL_SOCKET, type_val, (char*)&value, sizeof(value)) < 0) { 555 lua_pushinteger(L, -1); 556 lua_pushfstring(L, strerror(errno)); 557 return 2; 558 } 559 lua_pushinteger(L, 0); 560 return 1; 496 561 } 497 562 static int … … 918 983 LUA_DISPATCH(send, noit_lua_socket_send); 919 984 LUA_DISPATCH(sendto, noit_lua_socket_sendto); 985 LUA_DISPATCH(setsockopt, noit_lua_socket_setsockopt); 920 986 LUA_DISPATCH(ssl_upgrade_socket, noit_lua_socket_connect_ssl); 921 987 LUA_DISPATCH(ssl_ctx, noit_lua_socket_ssl_ctx); src/noit.conf.in
red271b2 rb4aa23f 74 74 <module loader="lua" name="smtp" object="noit.module.smtp"/> 75 75 <module loader="lua" name="ntp" object="noit.module.ntp"/> 76 <module loader="lua" name="dhcp" object="noit.module.dhcp"/> 76 77 <jezebel> 77 78 <config><url>http://127.0.0.1:8083/dispatch</url></config>
