Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

lua_upstream.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "config.h"
  17. #include "lua_common.h"
  18. /***
  19. * @module rspamd_upstream_list
  20. * This module implements upstreams manipulation from LUA API. This functionality
  21. * can be used for load balancing using different strategies including:
  22. *
  23. * - round-robin: balance upstreams one by one selecting accordingly to their weight
  24. * - hash: use stable hashing algorithm to distribute values according to some static strings
  25. * - master-slave: always prefer upstream with higher priority unless it is not available
  26. *
  27. * Here is an example of upstreams manipulations:
  28. * @example
  29. local rspamd_logger = require "rspamd_logger"
  30. local rspamd_redis = require "rspamd_redis"
  31. local upstream_list = require "rspamd_upstream_list"
  32. local upstreams = upstream_list.create('127.0.0.1,10.0.0.1,10.0.0.2', 6379)
  33. local function sym_callback(task)
  34. local upstream = upstreams:get_upstream_by_hash(task:get_from()[1]['domain'])
  35. local function cb(task, err, data)
  36. if err then
  37. upstream:fail()
  38. else
  39. upstream:ok()
  40. end
  41. end
  42. local addr = upstream:get_addr()
  43. rspamd_redis.make_request(task, addr, cb,
  44. 'PUSH', {'key', 'value'})
  45. end
  46. */
  47. /* Upstream list functions */
  48. LUA_FUNCTION_DEF(upstream_list, create);
  49. LUA_FUNCTION_DEF(upstream_list, destroy);
  50. LUA_FUNCTION_DEF(upstream_list, all_upstreams);
  51. LUA_FUNCTION_DEF(upstream_list, get_upstream_by_hash);
  52. LUA_FUNCTION_DEF(upstream_list, get_upstream_round_robin);
  53. LUA_FUNCTION_DEF(upstream_list, get_upstream_master_slave);
  54. LUA_FUNCTION_DEF(upstream_list, add_watcher);
  55. static const struct luaL_reg upstream_list_m[] = {
  56. LUA_INTERFACE_DEF(upstream_list, get_upstream_by_hash),
  57. LUA_INTERFACE_DEF(upstream_list, get_upstream_round_robin),
  58. LUA_INTERFACE_DEF(upstream_list, get_upstream_master_slave),
  59. LUA_INTERFACE_DEF(upstream_list, all_upstreams),
  60. LUA_INTERFACE_DEF(upstream_list, add_watcher),
  61. {"__tostring", rspamd_lua_class_tostring},
  62. {"__gc", lua_upstream_list_destroy},
  63. {NULL, NULL}};
  64. static const struct luaL_reg upstream_list_f[] = {
  65. LUA_INTERFACE_DEF(upstream_list, create),
  66. {NULL, NULL}};
  67. /* Upstream functions */
  68. LUA_FUNCTION_DEF(upstream, ok);
  69. LUA_FUNCTION_DEF(upstream, fail);
  70. LUA_FUNCTION_DEF(upstream, get_addr);
  71. LUA_FUNCTION_DEF(upstream, get_name);
  72. LUA_FUNCTION_DEF(upstream, get_port);
  73. LUA_FUNCTION_DEF(upstream, destroy);
  74. static const struct luaL_reg upstream_m[] = {
  75. LUA_INTERFACE_DEF(upstream, ok),
  76. LUA_INTERFACE_DEF(upstream, fail),
  77. LUA_INTERFACE_DEF(upstream, get_addr),
  78. LUA_INTERFACE_DEF(upstream, get_port),
  79. LUA_INTERFACE_DEF(upstream, get_name),
  80. {"__tostring", rspamd_lua_class_tostring},
  81. {"__gc", lua_upstream_destroy},
  82. {NULL, NULL}};
  83. /* Upstream class */
  84. struct rspamd_lua_upstream *
  85. lua_check_upstream(lua_State *L, int pos)
  86. {
  87. void *ud = rspamd_lua_check_udata(L, pos, rspamd_upstream_classname);
  88. luaL_argcheck(L, ud != NULL, 1, "'upstream' expected");
  89. return ud ? (struct rspamd_lua_upstream *) ud : NULL;
  90. }
  91. /***
  92. * @method upstream:get_addr()
  93. * Get ip of upstream
  94. * @return {ip} ip address object
  95. */
  96. static gint
  97. lua_upstream_get_addr(lua_State *L)
  98. {
  99. LUA_TRACE_POINT;
  100. struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
  101. if (up) {
  102. rspamd_lua_ip_push(L, rspamd_upstream_addr_next(up->up));
  103. }
  104. else {
  105. lua_pushnil(L);
  106. }
  107. return 1;
  108. }
  109. /***
  110. * @method upstream:get_name()
  111. * Get name of upstream
  112. * @return {string} name of the upstream
  113. */
  114. static gint
  115. lua_upstream_get_name(lua_State *L)
  116. {
  117. LUA_TRACE_POINT;
  118. struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
  119. if (up) {
  120. lua_pushstring(L, rspamd_upstream_name(up->up));
  121. }
  122. else {
  123. lua_pushnil(L);
  124. }
  125. return 1;
  126. }
  127. /***
  128. * @method upstream:get_port()
  129. * Get port of upstream
  130. * @return {int} port of the upstream
  131. */
  132. static gint
  133. lua_upstream_get_port(lua_State *L)
  134. {
  135. LUA_TRACE_POINT;
  136. struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
  137. if (up) {
  138. lua_pushinteger(L, rspamd_upstream_port(up->up));
  139. }
  140. else {
  141. lua_pushnil(L);
  142. }
  143. return 1;
  144. }
  145. /***
  146. * @method upstream:fail()
  147. * Indicate upstream failure. After certain amount of failures during specified time frame, an upstream is marked as down and does not participate in rotations.
  148. */
  149. static gint
  150. lua_upstream_fail(lua_State *L)
  151. {
  152. LUA_TRACE_POINT;
  153. struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
  154. gboolean fail_addr = FALSE;
  155. const gchar *reason = "unknown";
  156. if (up) {
  157. if (lua_isboolean(L, 2)) {
  158. fail_addr = lua_toboolean(L, 2);
  159. if (lua_isstring(L, 3)) {
  160. reason = lua_tostring(L, 3);
  161. }
  162. }
  163. else if (lua_isstring(L, 2)) {
  164. reason = lua_tostring(L, 2);
  165. }
  166. rspamd_upstream_fail(up->up, fail_addr, reason);
  167. }
  168. return 0;
  169. }
  170. /***
  171. * @method upstream:ok()
  172. * Indicates upstream success. Resets errors count for an upstream.
  173. */
  174. static gint
  175. lua_upstream_ok(lua_State *L)
  176. {
  177. LUA_TRACE_POINT;
  178. struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
  179. if (up) {
  180. rspamd_upstream_ok(up->up);
  181. }
  182. return 0;
  183. }
  184. static gint
  185. lua_upstream_destroy(lua_State *L)
  186. {
  187. LUA_TRACE_POINT;
  188. struct rspamd_lua_upstream *up = lua_check_upstream(L, 1);
  189. if (up) {
  190. /* Remove reference to the parent */
  191. luaL_unref(L, LUA_REGISTRYINDEX, up->upref);
  192. /* Upstream belongs to the upstream list, so no free here */
  193. }
  194. return 0;
  195. }
  196. /* Upstream list class */
  197. static struct upstream_list *
  198. lua_check_upstream_list(lua_State *L)
  199. {
  200. void *ud = rspamd_lua_check_udata(L, 1, rspamd_upstream_list_classname);
  201. luaL_argcheck(L, ud != NULL, 1, "'upstream_list' expected");
  202. return ud ? *((struct upstream_list **) ud) : NULL;
  203. }
  204. static struct rspamd_lua_upstream *
  205. lua_push_upstream(lua_State *L, gint up_idx, struct upstream *up)
  206. {
  207. struct rspamd_lua_upstream *lua_ups;
  208. if (up_idx < 0) {
  209. up_idx = lua_gettop(L) + up_idx + 1;
  210. }
  211. lua_ups = lua_newuserdata(L, sizeof(*lua_ups));
  212. lua_ups->up = up;
  213. rspamd_lua_setclass(L, rspamd_upstream_classname, -1);
  214. /* Store parent in the upstream to prevent gc */
  215. lua_pushvalue(L, up_idx);
  216. lua_ups->upref = luaL_ref(L, LUA_REGISTRYINDEX);
  217. return lua_ups;
  218. }
  219. /***
  220. * @function upstream_list.create(cfg, def, [default_port])
  221. * Create new upstream list from its string definition in form `<upstream>,<upstream>;<upstream>`
  222. * @param {rspamd_config} cfg configuration reference
  223. * @param {string} def upstream list definition
  224. * @param {number} default_port default port for upstreams
  225. * @return {upstream_list} upstream list structure
  226. */
  227. static gint
  228. lua_upstream_list_create(lua_State *L)
  229. {
  230. LUA_TRACE_POINT;
  231. struct upstream_list *new = NULL, **pnew;
  232. struct rspamd_config *cfg = NULL;
  233. const gchar *def;
  234. guint default_port = 0;
  235. gint top;
  236. if (lua_type(L, 1) == LUA_TUSERDATA) {
  237. cfg = lua_check_config(L, 1);
  238. top = 2;
  239. }
  240. else {
  241. top = 1;
  242. }
  243. if (lua_gettop(L) >= top + 1) {
  244. default_port = luaL_checknumber(L, top + 1);
  245. }
  246. if (lua_type(L, top) == LUA_TSTRING) {
  247. def = luaL_checkstring(L, top);
  248. new = rspamd_upstreams_create(cfg ? cfg->ups_ctx : NULL);
  249. if (rspamd_upstreams_parse_line(new, def, default_port, NULL)) {
  250. pnew = lua_newuserdata(L, sizeof(struct upstream_list *));
  251. rspamd_lua_setclass(L, rspamd_upstream_list_classname, -1);
  252. *pnew = new;
  253. }
  254. else {
  255. rspamd_upstreams_destroy(new);
  256. lua_pushnil(L);
  257. }
  258. }
  259. else if (lua_type(L, top) == LUA_TTABLE) {
  260. new = rspamd_upstreams_create(cfg ? cfg->ups_ctx : NULL);
  261. pnew = lua_newuserdata(L, sizeof(struct upstream_list *));
  262. rspamd_lua_setclass(L, rspamd_upstream_list_classname, -1);
  263. *pnew = new;
  264. lua_pushvalue(L, top);
  265. for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
  266. def = lua_tostring(L, -1);
  267. if (!def || !rspamd_upstreams_parse_line(new, def, default_port, NULL)) {
  268. msg_warn("cannot parse upstream %s", def);
  269. }
  270. }
  271. lua_pop(L, 1);
  272. }
  273. else {
  274. return luaL_error(L, "invalid arguments");
  275. }
  276. return 1;
  277. }
  278. /**
  279. * Destroy a single upstream list object
  280. * @param L
  281. * @return
  282. */
  283. static gint
  284. lua_upstream_list_destroy(lua_State *L)
  285. {
  286. LUA_TRACE_POINT;
  287. struct upstream_list *upl = lua_check_upstream_list(L);
  288. rspamd_upstreams_destroy(upl);
  289. return 0;
  290. }
  291. /***
  292. * @method upstream_list:get_upstream_by_hash(key)
  293. * Get upstream by hash from key
  294. * @param {string} key a string used as input for stable hash algorithm
  295. * @return {upstream} upstream from a list corresponding to the given key
  296. */
  297. static gint
  298. lua_upstream_list_get_upstream_by_hash(lua_State *L)
  299. {
  300. LUA_TRACE_POINT;
  301. struct upstream_list *upl;
  302. struct upstream *selected;
  303. const gchar *key;
  304. gsize keyl;
  305. upl = lua_check_upstream_list(L);
  306. if (upl) {
  307. key = luaL_checklstring(L, 2, &keyl);
  308. if (key) {
  309. selected = rspamd_upstream_get(upl, RSPAMD_UPSTREAM_HASHED, key,
  310. (guint) keyl);
  311. if (selected) {
  312. lua_push_upstream(L, 1, selected);
  313. }
  314. else {
  315. lua_pushnil(L);
  316. }
  317. }
  318. else {
  319. lua_pushnil(L);
  320. }
  321. }
  322. else {
  323. return luaL_error(L, "invalid arguments");
  324. }
  325. return 1;
  326. }
  327. /***
  328. * @method upstream_list:get_upstream_round_robin()
  329. * Get upstream round robin (by current weight)
  330. * @return {upstream} upstream from a list in round-robin matter
  331. */
  332. static gint
  333. lua_upstream_list_get_upstream_round_robin(lua_State *L)
  334. {
  335. LUA_TRACE_POINT;
  336. struct upstream_list *upl;
  337. struct upstream *selected;
  338. upl = lua_check_upstream_list(L);
  339. if (upl) {
  340. selected = rspamd_upstream_get(upl, RSPAMD_UPSTREAM_ROUND_ROBIN, NULL, 0);
  341. if (selected) {
  342. lua_push_upstream(L, 1, selected);
  343. }
  344. else {
  345. lua_pushnil(L);
  346. }
  347. }
  348. else {
  349. return luaL_error(L, "invalid arguments");
  350. }
  351. return 1;
  352. }
  353. /***
  354. * @method upstream_list:get_upstream_master_slave()
  355. * Get upstream master slave order (by static priority)
  356. * @return {upstream} upstream from a list in master-slave order
  357. */
  358. static gint
  359. lua_upstream_list_get_upstream_master_slave(lua_State *L)
  360. {
  361. LUA_TRACE_POINT;
  362. struct upstream_list *upl;
  363. struct upstream *selected;
  364. upl = lua_check_upstream_list(L);
  365. if (upl) {
  366. selected = rspamd_upstream_get(upl, RSPAMD_UPSTREAM_MASTER_SLAVE,
  367. NULL,
  368. 0);
  369. if (selected) {
  370. lua_push_upstream(L, 1, selected);
  371. }
  372. else {
  373. lua_pushnil(L);
  374. }
  375. }
  376. else {
  377. return luaL_error(L, "invalid arguments");
  378. }
  379. return 1;
  380. }
  381. struct upstream_foreach_cbdata {
  382. lua_State *L;
  383. gint ups_pos;
  384. };
  385. static void lua_upstream_inserter(struct upstream *up, guint idx, void *ud)
  386. {
  387. struct upstream_foreach_cbdata *cbd = (struct upstream_foreach_cbdata *) ud;
  388. lua_push_upstream(cbd->L, cbd->ups_pos, up);
  389. lua_rawseti(cbd->L, -2, idx + 1);
  390. }
  391. /***
  392. * @method upstream_list:all_upstreams()
  393. * Returns all upstreams for this list
  394. * @return {table|upstream} all upstreams defined
  395. */
  396. static gint
  397. lua_upstream_list_all_upstreams(lua_State *L)
  398. {
  399. LUA_TRACE_POINT;
  400. struct upstream_list *upl;
  401. struct upstream_foreach_cbdata cbd;
  402. upl = lua_check_upstream_list(L);
  403. if (upl) {
  404. cbd.L = L;
  405. cbd.ups_pos = 1;
  406. lua_createtable(L, rspamd_upstreams_count(upl), 0);
  407. rspamd_upstreams_foreach(upl, lua_upstream_inserter, &cbd);
  408. }
  409. else {
  410. return luaL_error(L, "invalid arguments");
  411. }
  412. return 1;
  413. }
  414. static inline enum rspamd_upstreams_watch_event
  415. lua_str_to_upstream_flag(const gchar *str)
  416. {
  417. enum rspamd_upstreams_watch_event fl = 0;
  418. if (strcmp(str, "success") == 0) {
  419. fl = RSPAMD_UPSTREAM_WATCH_SUCCESS;
  420. }
  421. else if (strcmp(str, "failure") == 0) {
  422. fl = RSPAMD_UPSTREAM_WATCH_FAILURE;
  423. }
  424. else if (strcmp(str, "online") == 0) {
  425. fl = RSPAMD_UPSTREAM_WATCH_ONLINE;
  426. }
  427. else if (strcmp(str, "offline") == 0) {
  428. fl = RSPAMD_UPSTREAM_WATCH_OFFLINE;
  429. }
  430. else {
  431. msg_err("invalid flag: %s", str);
  432. }
  433. return fl;
  434. }
  435. static inline const gchar *
  436. lua_upstream_flag_to_str(enum rspamd_upstreams_watch_event fl)
  437. {
  438. const gchar *res = "unknown";
  439. /* Works with single flags, not combinations */
  440. if (fl & RSPAMD_UPSTREAM_WATCH_SUCCESS) {
  441. res = "success";
  442. }
  443. else if (fl & RSPAMD_UPSTREAM_WATCH_FAILURE) {
  444. res = "failure";
  445. }
  446. else if (fl & RSPAMD_UPSTREAM_WATCH_ONLINE) {
  447. res = "online";
  448. }
  449. else if (fl & RSPAMD_UPSTREAM_WATCH_OFFLINE) {
  450. res = "offline";
  451. }
  452. else {
  453. msg_err("invalid flag: %d", fl);
  454. }
  455. return res;
  456. }
  457. struct rspamd_lua_upstream_watcher_cbdata {
  458. lua_State *L;
  459. gint cbref;
  460. gint parent_cbref; /* Reference to the upstream list */
  461. struct upstream_list *upl;
  462. };
  463. static void
  464. lua_upstream_watch_func(struct upstream *up,
  465. enum rspamd_upstreams_watch_event event,
  466. guint cur_errors,
  467. void *ud)
  468. {
  469. struct rspamd_lua_upstream_watcher_cbdata *cdata =
  470. (struct rspamd_lua_upstream_watcher_cbdata *) ud;
  471. lua_State *L;
  472. const gchar *what;
  473. gint err_idx;
  474. L = cdata->L;
  475. what = lua_upstream_flag_to_str(event);
  476. lua_pushcfunction(L, &rspamd_lua_traceback);
  477. err_idx = lua_gettop(L);
  478. lua_rawgeti(L, LUA_REGISTRYINDEX, cdata->cbref);
  479. lua_pushstring(L, what);
  480. struct rspamd_lua_upstream *lua_ups = lua_newuserdata(L, sizeof(*lua_ups));
  481. lua_ups->up = up;
  482. rspamd_lua_setclass(L, rspamd_upstream_classname, -1);
  483. /* Store parent in the upstream to prevent gc */
  484. lua_rawgeti(L, LUA_REGISTRYINDEX, cdata->parent_cbref);
  485. lua_ups->upref = luaL_ref(L, LUA_REGISTRYINDEX);
  486. lua_pushinteger(L, cur_errors);
  487. if (lua_pcall(L, 3, 0, err_idx) != 0) {
  488. msg_err("cannot call watch function for upstream: %s", lua_tostring(L, -1));
  489. lua_settop(L, 0);
  490. return;
  491. }
  492. lua_settop(L, 0);
  493. }
  494. static void
  495. lua_upstream_watch_dtor(gpointer ud)
  496. {
  497. struct rspamd_lua_upstream_watcher_cbdata *cdata =
  498. (struct rspamd_lua_upstream_watcher_cbdata *) ud;
  499. luaL_unref(cdata->L, LUA_REGISTRYINDEX, cdata->cbref);
  500. luaL_unref(cdata->L, LUA_REGISTRYINDEX, cdata->parent_cbref);
  501. g_free(cdata);
  502. }
  503. /***
  504. * @method upstream_list:add_watcher(what, cb)
  505. * Add new watcher to the upstream lists events (table or a string):
  506. * - `success` - called whenever upstream successfully used
  507. * - `failure` - called on upstream error
  508. * - `online` - called when upstream is being taken online from offline
  509. * - `offline` - called when upstream is being taken offline from online
  510. * Callback is a function: function(what, upstream, cur_errors) ... end
  511. * @example
  512. ups:add_watcher('success', function(what, up, cur_errors) ... end)
  513. ups:add_watcher({'online', 'offline'}, function(what, up, cur_errors) ... end)
  514. * @return nothing
  515. */
  516. static gint
  517. lua_upstream_list_add_watcher(lua_State *L)
  518. {
  519. LUA_TRACE_POINT;
  520. struct upstream_list *upl;
  521. upl = lua_check_upstream_list(L);
  522. if (upl &&
  523. (lua_type(L, 2) == LUA_TTABLE || lua_type(L, 2) == LUA_TSTRING) &&
  524. lua_type(L, 3) == LUA_TFUNCTION) {
  525. enum rspamd_upstreams_watch_event flags = 0;
  526. struct rspamd_lua_upstream_watcher_cbdata *cdata;
  527. if (lua_type(L, 2) == LUA_TSTRING) {
  528. flags = lua_str_to_upstream_flag(lua_tostring(L, 2));
  529. }
  530. else {
  531. for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
  532. if (lua_isstring(L, -1)) {
  533. flags |= lua_str_to_upstream_flag(lua_tostring(L, -1));
  534. }
  535. else {
  536. lua_pop(L, 1);
  537. return luaL_error(L, "invalid arguments");
  538. }
  539. }
  540. }
  541. cdata = g_malloc0(sizeof(*cdata));
  542. lua_pushvalue(L, 3); /* callback */
  543. cdata->cbref = luaL_ref(L, LUA_REGISTRYINDEX);
  544. cdata->L = L;
  545. cdata->upl = upl;
  546. lua_pushvalue(L, 1); /* upstream list itself */
  547. cdata->parent_cbref = luaL_ref(L, LUA_REGISTRYINDEX);
  548. rspamd_upstreams_add_watch_callback(upl, flags,
  549. lua_upstream_watch_func, lua_upstream_watch_dtor, cdata);
  550. }
  551. else {
  552. return luaL_error(L, "invalid arguments");
  553. }
  554. return 0;
  555. }
  556. static gint
  557. lua_load_upstream_list(lua_State *L)
  558. {
  559. lua_newtable(L);
  560. luaL_register(L, NULL, upstream_list_f);
  561. return 1;
  562. }
  563. void luaopen_upstream(lua_State *L)
  564. {
  565. rspamd_lua_new_class(L, rspamd_upstream_list_classname, upstream_list_m);
  566. lua_pop(L, 1);
  567. rspamd_lua_add_preload(L, "rspamd_upstream_list", lua_load_upstream_list);
  568. rspamd_lua_new_class(L, rspamd_upstream_classname, upstream_m);
  569. lua_pop(L, 1);
  570. }