You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smtp_ip_parser.rl 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. %%{
  2. machine smtp_ip_parser;
  3. action IP6_start {
  4. in_v6 = 1;
  5. ip_start = p;
  6. }
  7. action IP6_end {
  8. in_v6 = 0;
  9. ip_end = p;
  10. }
  11. action IP4_start {
  12. if (!in_v6) {
  13. ip_start = p;
  14. }
  15. }
  16. action IP4_end {
  17. if (!in_v6) {
  18. ip_end = p;
  19. }
  20. }
  21. action Domain_addr_start {}
  22. action Domain_addr_end {}
  23. include smtp_base "smtp_base.rl";
  24. include smtp_ip "smtp_ip.rl";
  25. main := address_literal | non_conformant_address_literal;
  26. }%%
  27. #include "smtp_parsers.h"
  28. #include "util.h"
  29. #include "addr.h"
  30. %% write data;
  31. rspamd_inet_addr_t *
  32. rspamd_parse_smtp_ip (const char *data, size_t len, rspamd_mempool_t *pool)
  33. {
  34. const char *p = data, *pe = data + len, *eof = data + len;
  35. const char *ip_start = NULL, *ip_end = NULL;
  36. gboolean in_v6 = FALSE;
  37. int cs = 0;
  38. %% write init;
  39. %% write exec;
  40. if (ip_start && ip_end && ip_end > ip_start) {
  41. return rspamd_parse_inet_address_pool (ip_start, ip_end - ip_start, pool,
  42. RSPAMD_INET_ADDRESS_PARSE_NO_UNIX|RSPAMD_INET_ADDRESS_PARSE_REMOTE);
  43. }
  44. return NULL;
  45. }