luat_netdrv_napt.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef LUAT_NETDRV_NAPT_H
  2. #define LUAT_NETDRV_NAPT_H
  3. #include "lwip/pbuf.h"
  4. // #define IP_NAPT_TIMEOUT_MS_TCP (30*60*1000)
  5. #define IP_NAPT_TIMEOUT_MS_TCP_DISCON (20*1000)
  6. typedef struct luat_netdrv_napt_icmp
  7. {
  8. uint8_t is_vaild;
  9. uint8_t adapter_id;
  10. uint16_t inet_id;
  11. uint16_t wnet_id;
  12. uint32_t inet_ip;
  13. uint32_t wnet_ip;
  14. uint8_t inet_mac[6];
  15. uint64_t tm_ms; // 最后通信时间
  16. }luat_netdrv_napt_icmp_t;
  17. typedef struct luat_netdrv_napt_tcpudp
  18. {
  19. uint8_t is_vaild;
  20. uint8_t adapter_id;
  21. uint16_t inet_port;
  22. uint16_t wnet_port;
  23. uint16_t wnet_local_port;
  24. uint32_t inet_ip;
  25. uint32_t wnet_ip;
  26. uint8_t inet_mac[6];
  27. uint64_t tm_ms; // 最后通信时间
  28. // TCP状态记录
  29. unsigned int fin1 : 1;
  30. unsigned int fin2 : 1;
  31. unsigned int finack1 : 1;
  32. unsigned int finack2 : 1;
  33. unsigned int synack : 1;
  34. unsigned int rst : 1;
  35. }luat_netdrv_napt_tcpudp_t;
  36. typedef struct napt_ctx
  37. {
  38. luat_netdrv_t* net;
  39. uint8_t* buff;
  40. size_t len;
  41. struct eth_hdr* eth;
  42. struct ip_hdr* iphdr;
  43. int is_wnet;
  44. }napt_ctx_t;
  45. int luat_napt_icmp_handle(napt_ctx_t* ctx);
  46. int luat_napt_tcp_handle(napt_ctx_t* ctx);
  47. int luat_napt_udp_handle(napt_ctx_t* ctx);
  48. int luat_netdrv_napt_pkg_input(int id, uint8_t* buff, size_t len);
  49. #endif