我正在嘗試使用RIOT-OS構建CoAP網絡。我正在使用VMWare模擬Ubuntu 14.04.2在Windows 7 64位上工作。客戶和主機之間的網絡連接是Nat:共享主機的IP地址不能使用Firefox-Copper插件向本地地址以外的地址發送CoAP消息(:: 1)
我基本上覆制了microcoap pkg並將其修改爲IPv6.I使用Copper Firefox插件(在客戶Ubuntu機器上)來測試if客戶端正在工作,並且如果我將套接字地址設置爲:: 1,它的工作原理沒有問題,但如果我將其更改爲其他任何我想要的東西,Copper似乎無法找到它。 (BTW我一種新的網絡建設,我從來沒有實現過一個只瞭解他們,我只知道這一定是一些瑣碎的問題,所以原諒我noobness或者,如果我提供過少的信息)
銅能始終連接到:: 1,即使CoAP客戶端沒有運行,只有當我嘗試發出一個GET/POST或任何其他命令時,它說網絡/主機是無法訪問的,但如果我嘗試其他IPv6地址說fe80 :: 20c :29ff:fe40:e46e/64或fe80 :: 20c:29ff:fe40:e46d/64(這是eth0在這種情況下的IPv6地址),它直截了當地說網絡/主機是無法訪問的。
(這是從VMware來賓Ubuntu的所有數據,我不認爲我們需要從主機Windows7的機器數據,但ofcoure我可以提供,如果你認爲是問題出在哪裏埋)
ifconfig:
docker0 Link encap:Ethernet HWaddr 22:ba:7c:00:36:d6
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::20ba:7cff:fe00:36d6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:9367 (9.3 KB)
eth0 Link encap:Ethernet HWaddr 00:0c:29:40:e4:6d
inet addr:192.168.159.130 Bcast:192.168.159.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe40:e46d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9828 errors:0 dropped:0 overruns:0 frame:0
TX packets:4668 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9443160 (9.4 MB) TX bytes:542254 (542.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1153 errors:0 dropped:0 overruns:0 frame:0
TX packets:1153 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:117380 (117.3 KB) TX bytes:117380 (117.3 KB)
起初我想過防火牆或路由問題,或Ipv6 forwarindg,但一切似乎都沒事。 奇怪的是,如果我嘗試的任何東西不是:: 1,甚至不是ICMPv6或NDP,Wireshark都不會顯示任何內容,其中at :: 1至少會在單擊GET或POST按鈕時顯示CoAP消息。
net.IPv6.conf.all.forwarding設置爲1個
ip6tables是空的,默認設置爲接受
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
我UFW看起來像這樣:
# /etc/default/ufw
#
# Set to yes to apply rules to support IPv6 (no means only IPv6 on loopback
# accepted). You will need to 'disable' and then 'enable' the firewall for
# the changes to take affect.
IPV6=yes
# Set the default input policy to ACCEPT, DROP, or REJECT. Please note that if
# you change this you will most likely want to adjust your rules.
DEFAULT_INPUT_POLICY="ACCEPT"
# Set the default output policy to ACCEPT, DROP, or REJECT. Please note that if
# you change this you will most likely want to adjust your rules.
DEFAULT_OUTPUT_POLICY="ACCEPT"
# Set the default forward policy to ACCEPT, DROP or REJECT. Please note that
# if you change this you will most likely want to adjust your rules
DEFAULT_FORWARD_POLICY="ACCEPT"
# Set the default application policy to ACCEPT, DROP, REJECT or SKIP. Please
# note that setting this to ACCEPT may be a security risk. See 'man ufw' for
# details
DEFAULT_APPLICATION_POLICY="SKIP"
# By default, ufw only touches its own chains. Set this to 'yes' to have ufw
# manage the built-in chains too. Warning: setting this to 'yes' will break
# non-ufw managed firewall rules
MANAGE_BUILTINS=no
#
# IPT backend
#
# only enable if using iptables backend
IPT_SYSCTL=/etc/ufw/sysctl.conf
# Extra connection tracking modules to load. Complete list can be found in
# net/netfilter/Kconfig of your kernel source. Some common modules:
# nf_conntrack_irc, nf_nat_irc: DCC (Direct Client to Client) support
# nf_conntrack_netbios_ns: NetBIOS (samba) client support
# nf_conntrack_pptp, nf_nat_pptp: PPTP over stateful firewall/NAT
# nf_conntrack_ftp, nf_nat_ftp: active FTP support
# nf_conntrack_tftp, nf_nat_tftp: TFTP support (server side)
IPT_MODULES="nf_conntrack_ftp nf_nat_ftp nf_conntrack_netbios_ns"
和我的路由-A inet6是這樣的(aaaa :: XXX和double fe80 ::/64 eth0只是我的試驗,試圖使它與其他IP地址一起工作):
Kernel IPv6 routing table
Destination Next Hop Flag Met Ref Use If
aaaa::212:7402:2:202/128 :: !n 1 0 12 lo
aaaa::212:7402:2:202/128 :: UH 1 0 0 eth0
fe80::20c:29ff:fe40:e46d/128 :: UH 1 0 0 eth0
fe80::/64 :: U 1 0 0 eth0
fe80::/64 :: U 256 0 0 eth0
fe80::/64 :: U 256 0 0 docker0
::/0 :: !n -1 1 412 lo
::1/128 :: Un 0 3 117 lo
fe80::/128 :: Un 0 1 0 lo
fe80::/128 :: Un 0 1 0 lo
fe80::20c:29ff:fe40:e46d/128 :: Un 0 1 79 lo
fe80::20ba:7cff:fe00:36d6/128 :: Un 0 1 0 lo
ff00::/8 :: U 256 0 0 eth0
ff00::/8 :: U 256 0 0 docker0
::/0 :: !n -1 1 412 lo
這裏是RIOT-OS的代碼我使用的,那裏的文件描述符和套接字的建立:
#include <stdio.h>
#include "shell.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdbool.h>
#include <strings.h>
#include "coap.h"
#define PORT 5683
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
puts("Starting the RIOT\n");
int fd;
struct sockaddr_in6 servaddr, cliaddr;
uint8_t buf[4096];//maybe need bigger becouse IPv6
uint8_t scratch_raw[4096];
coap_rw_buffer_t scratch_buf = {scratch_raw, sizeof(scratch_raw)};
fd = socket(AF_INET6,SOCK_DGRAM,0);//Socket file descriptor init
bzero(&servaddr,sizeof(servaddr));
servaddr.sin6_family = AF_INET6;//inet family
servaddr.sin6_flowinfo = 0;//??
servaddr.sin6_addr.s6_addr[0] = (uint8_t)0xfe;//IPv6 Address 1
servaddr.sin6_addr.s6_addr[1] = (uint8_t)0x80;
servaddr.sin6_addr.s6_addr[2] = (uint8_t)0x00;//IPv6 Address 2
servaddr.sin6_addr.s6_addr[3] = (uint8_t)0x00;
servaddr.sin6_addr.s6_addr[4] = (uint8_t)0x00;//IPv6 Address 3
servaddr.sin6_addr.s6_addr[5] = (uint8_t)0x00;
servaddr.sin6_addr.s6_addr[6] = (uint8_t)0x00;//IPv6 Address 4
servaddr.sin6_addr.s6_addr[7] = (uint8_t)0x00;
servaddr.sin6_addr.s6_addr[8] = (uint8_t)0x02;//IPv6 Address 5
servaddr.sin6_addr.s6_addr[9] = (uint8_t)0x0c;
servaddr.sin6_addr.s6_addr[10] = (uint8_t)0x29;//IPv6 Address 6
servaddr.sin6_addr.s6_addr[11] = (uint8_t)0xff;
servaddr.sin6_addr.s6_addr[12] = (uint8_t)0xfe;//IPv6 Address 7
servaddr.sin6_addr.s6_addr[13] = (uint8_t)0x40;
servaddr.sin6_addr.s6_addr[14] = (uint8_t)0xe4;//IPv6 Address 8
servaddr.sin6_addr.s6_addr[15] = (uint8_t)0x6e;
servaddr.sin6_port = htons(PORT); //PORT (5683)
bind(fd,(struct sockaddr *)&servaddr, sizeof(servaddr));
endpoint_setup();
while(1)
{
int n, rc;
socklen_t len = sizeof(cliaddr);
coap_packet_t pkt;
n = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&cliaddr, &len);
//#ifdef DEBUG
printf("Received: ");
coap_dump(buf, n, true);
printf("\n");
//#endif
if (0 != (rc = coap_parse(&pkt, buf, n)))
printf("Bad packet rc=%d\n", rc);
else
{
size_t rsplen = sizeof(buf);
coap_packet_t rsppkt;
#ifdef DEBUG
coap_dumpPacket(&pkt);
#endif
coap_handle_req(&scratch_buf, &pkt, &rsppkt);
if (0 != (rc = coap_build(buf, &rsplen, &rsppkt)))
printf("coap_build failed rc=%d\n", rc);
else
{
#ifdef DEBUG
printf("Sending: ");
coap_dump(buf, rsplen, true);
printf("\n");
#endif
#ifdef DEBUG
coap_dumpPacket(&rsppkt);
#endif
sendto(fd, buf, rsplen, 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
}
}
}
}
所以,如果我改變servaddr.sin6_addr.s6_addr到:: 1,它的工作原理,但當然我想要我給客戶的IPv6地址。
此外,我似乎無法成爲ping6 ipv6.google.com,雖然我無法從主機Windows 7機器ping它,不知道爲什麼,也不知道它是否重要。
後來我想創建超過1個客戶端同時運行,也許通過橋接,連接到TAP,在6lowpan上運行,但現在我只想讓一個設備工作。 (sry無法添加wireshark圖片,沒有聲望尚未這麼做:<)
感謝,它的工作原理,我知道它很容易,但它只適用於如果我給全局地址eth0,我想要添加這些地址到TAP設備,但我想我可以弄清楚這一部分:) – Lexandro