IPv6的網路中,
client端會依據RA(Router Advertisement)的封包來設定IPv6 address.
詳情可以參考第十篇 IPv6 Path MTU及Router Advertisement
而RA的發送有兩個時機點,
1. 固定時間發送RA
2. 當收到client端送出RS(Router Solicitation)時,立刻以RA封包回應
現在遇到的問題是,router的發送RA的間隔設定很長的話,而網路又沒有其它client端送出RS封包,如此一來,剛接上去的client端網路要很久後才會被設定,這個是使用者所不能接受的。
因此,現在要嘗試來寫一個user mode的執行檔, 可以讓我針對指定的interface送出RS封包,
在參考busybox的ping6與radvd的source code後,總算完成了。
參考了IPv6 Essentials這本書, 裡面有講到一段話, 非常清楚的說明了RS的條件
「In the IP header of a Router Solicitation message, you will usually see the all-routers multicast address of ff02::2 as a Destination address. The hop limit is set to 255. The ICMP Type field is set to 133, which is the value for the Router Solicitation message. The Code field is unused and set to 0. The following two bytes are used for the Checksum. The next four bytes are unused and reserved for future use. The sender sets them to 0, and the receiver ignores those fields. For a Router Solicitation message, a valid option is the link-layer address of the sending host, if the address of the sending host is known. If the Source address on the IP layer is the unspecified (all-zeros) address, this field is not used. More options may bedefined in future versions of ND. If a host cannot recognize an option, it should ignore the option and process the packet.
Routers that receive this Solicitation message reply with a Router Advertisement message. Routers also issue those messages periodically.」
參考radvd裡面的send_ra
把其改寫成send_rs
但是,結果確把RS封包往LAN port送, 而我是想往WAN port送,
這個時候想到ping6可以指定傳送的介面,例:
# ping6 ff02::2 -I eth2.2
在改寫完後,可以確實的把RS往指定的interface送, 但是,router確不會回傳RA.
在比對完可以正確回傳RA的RS封包與我自己傳送的RS封包後, 跟上面那一段文字比對後,發現有可能是Hop limit我設定為1,
而正常的必需要是255
而這個部分必需要用setsockopt來完成~
int sockopt;
sockopt = 255;
setsockopt(pingsock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &sockopt, sizeof(sockopt));
因為我們要送的是multi-cast的封包, 因為設定的Hop limit也是for multi-cast的,必需使用IPV6_MULTICAST_HOPS
uni-cast則是使用IPV6_UNICAST_HOPS
接下來則是sample code了
這中間使用到if_nametoindex→把eth2.2轉成index
getopt32(argc, argv, "qvc:s:I:", &opt_c, &opt_s, &opt_I);
會連動到option_mask32這一個變數,
當有發現到q則option_mask32的bit 0會被舉起來
當有發現到c的option時, 則option_mask32的bit 2會被舉起來
因-c後面要接參數, 所以opt_c接的是第一個參數
2015年2月12日 星期四
送IPv6的RS(Router Solicitation)到指定的interface
2014年12月22日 星期一
2014年12月9日 星期二
NTP client
要在router上自行更新時間,就必需要用到NTP service
參考資料:
NTP - 網路校時
解决ntp的错误 no server suitable for synchronization found
Linux RTC 時間對時校正
NTP协议以及ntpclinet使用
2012-09-15-NtpClient 选项用法
在linux中如何讀取並修改系統時間?
使用ntpdate更新系统时间
get ip address by DNS
目前要解析DNS去解析IP,
但是gethostbyname並不支援IPv6,
但有找到getaddrinfo可以達到同樣的功能,
而且同時有支援IPv4與IPv6
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
struct addrinfo hints, *res, *p;
int status;
char ipstr[INET6_ADDRSTRLEN];
if (argc != 2) {
fprintf(stderr,"usage: showip hostname\n");
return 1;
}
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
return 2;
}
printf("IP addresses for %s:\n\n", argv[1]);
for(p = res;p != NULL; p = p->ai_next) {
void *addr;
char *ipver;
// get the pointer to the address itself,
// different fields in IPv4 and IPv6:
if (p->ai_family == AF_INET) { // IPv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);/*error*/
ipver = "IPv4";
} else { // IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);/*error*/
ipver = "IPv6";
}
// convert the IP to a string and print it:
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf(" %s: %s\n", ipver, ipstr);
}
freeaddrinfo(res); // free the linked list
return 0;
}參考資料:
Sample getaddrinfo Code Compiles in Linux but not FreeBSD
getaddrinfo(3) - Linux man page
gethostbyname(), gethostbyaddr()
Porting IPv4 applications to IPv6
Porting IPv6 -- examples
2014年11月20日 星期四
linux signal相關設定
目前在寫daemon,
寫到了處理signal的程式
signal (SIGHUP, sighup_handler);
表示當這一個process收到一個SIGHUP時,
sighup_handler這一個函式會被執行。
SIGHUP
一般是用在參考檔案更新時。
可以直接透過下指令去驗証此function是否正常
kill -HUP 3077
killall -HUP a.out
SIGTERM, SIGINT
參考資料:
Sending signal to Processes
signal 小知識
Daemon函数的用法
寫 linux daemon 的注意事項
2014年11月17日 星期一
建立samba
因為compiler環境在linux,
而產生出來的image檔案必需要傳到windows上做燒錄的動作。
找了一下,有幾個方式可以完成,
FTP
WEB
網路芳鄰
目前看起來最簡單的方式應該是網路芳鄰samba
在多天的嘗試後,可以正常的使用帳號的方式連線到linux的空間,
可惜的是還沒有辦法試成功可以用匿名的方試登入(Guest)
========== 開始 ==========
0. 查詢是否有安裝samba
rpm -q samba
1. 查詢防火牆的狀態
systemctl status firewalld
2. 關掉防火牆
systemctl disable firewalld
systemctl stop firewalld
3. 新增samba使用者
smbpasswd -a caspar
若遇到以下錯誤訊息,表示系統沒有相對應的帳號。
目前的設置是linux系統有的帳號,samba才可以追加其帳號。
4. 停用samba使用者
smbpasswd -d caspar
5. 刪除samba使用者
smbpasswd -x caspar
6. 啟用samba服務
service smb start
7. 重新啟動samba服務
service smb restart
8. 查詢目前samba的狀態
service smb status
基本上新增samba使用者後,就可以由windows進入,但是,目前成功的方試,仍然要使用帳號跟密碼。
smbpasswd這一個指令可以做一些簡單的使用者帳號的操作,
但是更深入的操作方式就必需要使用pdbedit這一個指令
========== pdbedit 指令說明 ==========
pdbedit -L
列出使用者列表
pdbedit -Lv
列出詳細的使用者列表
pdbedit -Lw
列出同 smbpasswd 格式的使用者列表
pdbedit -a jerry
新增 jerry帳號
pdbedit -x jerry
刪除 jerry帳號
pdbedit -c "[D]" -u jerry
暫時停用 jerry 這個帳號
pdbedit -c "[]" -u jerry
恢復使用 jerry 這個帳號
========== 其它資訊 ==========
linux上登入window或是samba的電腦
smbclient //主機/分享的資料匣資源 -U 使用者名稱
輸入密碼就可以執行類似ftp的指令了
mount 別台機器分享的資源到本台電腦
mount -t smbfs -o username=使用者名稱 ,password=密碼 //主機名稱/分享的資源 /主機目錄
查詢使用的port
netstat -anp
查詢目前執行的程式
ps aux | grep mbd
在設定smb.conf時, 若嘗試要設定Guest登入
設定security為share
會出現以下錯誤
WARNING: Ignoring invalid value 'share' for parameter 'security'
改為以下就可以正常的
security = user
map to guest = Bad User
========== 自己安裝 samba-4.1.13 ==========
./configure
會出現以下錯誤訊息
Could not find the python development headers
安裝以下套解可以解除問題
yum install libacl-devel libblkid-devel gnutls-devel readline-devel python-devel gdb pkgconfig
參考資料:
如何檢查linux中的服務是否正常?
Samba 設定USER等級分享目錄[3]
Samba 下 Ubuntu與Win7共享資料夾設定,利用 host-only網路
Samba-4.1.13
安裝samba系統
fedora 10/11 安裝samba || windows 與 linux 的網芳設定
第十六章、檔案伺服器之二: SAMBA 伺服器
windows 網路指令
arp
可以查詢IP與MAC相對應的列表
arp -s 157.55.85.212 00-aa-00-62-c6-09 .... 新增靜態項目。
arp -a .... 顯示 ARP 表格。