Changeset b4aa23f3434227874cce728d4f56f2e3c74b4e98

Show
Ignore:
Timestamp:
07/03/12 21:17:58 (2 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1341350278 -0400
git-parent:

[618dd9f44bc6087b76e06e01b9d71dd16de7f1bd]

git-author:
Philip Maddox <pmaddox@circonus.com> 1341346134 -0400
Message:

Added DHCP check

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules-lua/Makefile.in

    rde30ea9 rb4aa23f  
    4444        noit/module/nrpe.lua \ 
    4545        noit/module/redis.lua \ 
    46         noit/module/nginx.lua 
     46        noit/module/nginx.lua \ 
     47        noit/module/dhcp.lua 
    4748 
    4849all: 
  • src/modules-lua/noit/extras.lua

    rde30ea9 rb4aa23f  
    6060end 
    6161 
     62function iptonumber(str) 
     63  local num = 0 
     64  for elem in str:gmatch("%d+") do 
     65    num = (num * 256) + elem 
     66  end 
     67  return num 
     68end 
     69 
  • src/modules/lua_noit.c

    r618dd9f rb4aa23f  
    447447  int8_t family; 
    448448  int rv; 
     449  int flag; 
    449450  union { 
    450451    struct sockaddr_in sin4; 
     
    483484    a.sin4.sin_family = family; 
    484485    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)); 
    485488  } 
    486489 
     
    494497  lua_pushstring(L, strerror(errno)); 
    495498  return 2; 
     499} 
     500static int 
     501noit_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; 
    496561} 
    497562static int 
     
    918983     LUA_DISPATCH(send, noit_lua_socket_send); 
    919984     LUA_DISPATCH(sendto, noit_lua_socket_sendto); 
     985     LUA_DISPATCH(setsockopt, noit_lua_socket_setsockopt); 
    920986     LUA_DISPATCH(ssl_upgrade_socket, noit_lua_socket_connect_ssl); 
    921987     LUA_DISPATCH(ssl_ctx, noit_lua_socket_ssl_ctx); 
  • src/noit.conf.in

    red271b2 rb4aa23f  
    7474    <module loader="lua" name="smtp" object="noit.module.smtp"/> 
    7575    <module loader="lua" name="ntp" object="noit.module.ntp"/> 
     76    <module loader="lua" name="dhcp" object="noit.module.dhcp"/> 
    7677    <jezebel> 
    7778      <config><url>http://127.0.0.1:8083/dispatch</url></config>