20191212_jeffrey - silenceuncrio/diary GitHub Wiki

0855

review


準備一台 M300 方便跟 m330 做 gre tunnel keepalive 實驗

分別 build 最新的 code

m330[release/v0.08]

  • Products/Vendor = GENERIC/0_GENERIC

M300[release/v2.02]

  • Products/Vendor = M300/0_GENERIC

配置


+-------+                                           +-------+
|       |                   lan                     |       |
| m330  +-------------------------------------------+ M300  |
|       | 192.168.1.33                 192.168.1.30 |       |
+-------+                                           +-------+

先來個最基本的 socket

  • m330 送
  • M300 收

study 一下 The Linux Programming Interface - Chapter 58: Sockets: Fundamentals of TCP/IP Networks

1530

參考以下

m330

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>

int main() {
  int sd;
  struct sockaddr_in dest;
  char msg[] = "Hello, World!";

  dest.sin_family = AF_INET;
  if (inet_pton(AF_INET, "192.168.1.30", &(dest.sin_addr)) != 1) {
      printf("Bad Address!\n");
      return(1);
  }

  if ((sd = socket(AF_INET, SOCK_RAW, 253)) < 0) {
      printf("socket() failed!\n");
      return(1);
  }

  if (sendto(sd, &msg, 14, 0, (struct sockaddr*) &dest, sizeof(struct sockaddr)) < 0)  {
    printf("sendto() failed!\n");
    return(1);
  }

  return(0);
}

M300

root@M300-S:~# tcpdump -X -s0 -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
07:16:39.852368 IP 192.168.1.33 > 192.168.1.30:  ip-proto-253 14
        0x0000:  4500 0022 0000 4000 40fd b64f c0a8 0121  E.."..@[email protected]...!
        0x0010:  c0a8 011e 4865 6c6c 6f2c 2057 6f72 6c64  ....Hello,.World
        0x0020:  2100 0000 0000 0000 0000 0000 0000       !.............
07:16:39.853090 IP 192.168.1.30 > 192.168.1.33: ICMP 192.168.1.30 protocol 253 unreachable, length 42
        0x0000:  45c0 003e e1b5 0000 4001 14ba c0a8 011e  E..>....@.......
        0x0010:  c0a8 0121 0302 bbd1 0000 0000 4500 0022  ...!........E.."
        0x0020:  0000 4000 40fd b64f c0a8 0121 c0a8 011e  ..@[email protected]...!....
        0x0030:  4865 6c6c 6f2c 2057 6f72 6c64 2100       Hello,.World!.

2 packets captured
2 packets received by filter
0 packets dropped by kernel

1630

試著讓 m330 送出 gre packet


可以參考 lunux 現成的 header file - <net/gre.h>

⚠️ **GitHub.com Fallback** ⚠️