Archive

Author Archive

IGMP协议学习笔记(一)

June 30th, 2009 BianJiang No comments

进来在作IGMP协议栈的解析,简单记录如下:

IGMPV3 Types

   There are two IGMP message types of concern to the IGMPv3 protocol
   described in this document:

      Type Number (hex)   Message Name
      -----------------   ------------

            0x11          Membership Query

            0x22          Version 3 Membership Report

   An implementation of IGMPv3 MUST also support the following three
   message types, for interoperation with previous versions of IGMP (see
   section 7):

           0x12          Version 1 Membership Report    [RFC-1112]

           0x16          Version 2 Membership Report    [RFC-2236]

IGMP V1 Query:

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |Version| Type  |    Unused     |           Checksum            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                         Group Address                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

IGMP V2 Query:

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |      Type     | Max Resp Time |           Checksum            |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                         Group Address                         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

IGMP V3 Membership Query Message: :

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |  Type = 0x11  | Max Resp Code |           Checksum            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                         Group Address                         |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      | Resv  |S| QRV |     QQIC      |     Number of Sources (N)     |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                       Source Address [1]                      |
      +-                                                             -+
      |                       Source Address [2]                      |
      +-                              .                              -+
      .                               .                               .
      .                               .                               .
      +-                                                             -+
      |                       Source Address [N]                      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 Version 3 Membership Report Message

   Version 3 Membership Reports are sent by IP systems to report (to
   neighboring routers) the current multicast reception state, or
   changes in the multicast reception state, of their interfaces.
   Reports have the following format:

RFC 3376                         IGMPv3                     October 2002

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |  Type = 0x22  |    Reserved   |           Checksum            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |           Reserved            |  Number of Group Records (M)  |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      .                                                               .
      .                        Group Record [1]                       .
      .                                                               .
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      .                                                               .
      .                        Group Record [2]                       .
      .                                                               .
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                               .                               |
      .                               .                               .
      |                               .                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      .                                                               .
      .                        Group Record [M]                       .
      .                                                               .
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   where each Group Record has the following internal format:

      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |  Record Type  |  Aux Data Len |     Number of Sources (N)     |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                       Multicast Address                       |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                       Source Address [1]                      |
      +-                                                             -+
      |                       Source Address [2]                      |
      +-                                                             -+
      .                               .                               .
      .                               .                               .
      .                               .                               .
      +-                                                             -+
      |                       Source Address [N]                      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      .                                                               .
      .                         Auxiliary Data                        .
      .                                                               .
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Example:
Version 3 Membership Report Message
 22 00 ea 03     | Type: 22, Checksum: ea 03
 00 00 00 01     | Number of group recode 01
 04 00 00 00     | Recode type: 04, Number of Sources: 00 00
 ef ff ff fa      | Multicast Addr: 239.255.255.250
 Group Record Types

   There are a number of different types of Group Records that may be
   included in a Report message:

   o A "Current-State Record" is sent by a system in response to a Query
     received on an interface.  It reports the current reception state
     of that interface, with respect to a single multicast address.  The
     Record Type of a Current-State Record may be one of the following
     two values:

        Value  Name and Meaning
        -----  ----------------

          1    MODE_IS_INCLUDE - indicates that the interface has a
               filter mode of INCLUDE for the specified multicast
               address.  The Source Address [i] fields in this Group
               Record contain the interface's source list for the
               specified multicast address, if it is non-empty.

          2    MODE_IS_EXCLUDE - indicates that the interface has a
               filter mode of EXCLUDE for the specified multicast
               address.  The Source Address [i] fields in this Group
               Record contain the interface's source list for the
               specified multicast address, if it is non-empty.

   o A "Filter-Mode-Change Record" is sent by a system whenever a local
     invocation of IPMulticastListen causes a change of the filter mode
     (i.e., a change from INCLUDE to EXCLUDE, or from EXCLUDE to
     INCLUDE), of the interface-level state entry for a particular
     multicast address.  The Record is included in a Report sent from
     the interface on which the change occurred.  The Record Type of a
     Filter-Mode-Change Record may be one of the following two values:

          3    CHANGE_TO_INCLUDE_MODE - indicates that the interface
               has changed to INCLUDE filter mode for the specified
               multicast address.  The Source Address [i] fields
               in this Group Record contain the interface's new
               source list for the specified multicast address,
               if it is non-empty.

          4    CHANGE_TO_EXCLUDE_MODE - indicates that the interface
               has changed to EXCLUDE filter mode for the specified
               multicast address.  The Source Address [i] fields
               in this Group Record contain the interface's new
               source list for the specified multicast address,
               if it is non-empty.

   o A "Source-List-Change Record" is sent by a system whenever a local
     invocation of IPMulticastListen causes a change of source list that
     is *not* coincident with a change of filter mode, of the
     interface-level state entry for a particular multicast address.
     The Record is included in a Report sent from the interface on which
     the change occurred.  The Record Type of a Source-List-Change
     Record may be one of the following two values:

          5    ALLOW_NEW_SOURCES - indicates that the Source Address
               [i] fields in this Group Record contain a list of the
               additional sources that the system wishes to
               hear from, for packets sent to the specified
               multicast address.  If the change was to an INCLUDE
               source list, these are the addresses that were added
               to the list; if the change was to an EXCLUDE source
               list, these are the addresses that were deleted from
               the list.

          6    BLOCK_OLD_SOURCES - indicates that the Source Address
               [i] fields in this Group Record contain a list of the
               sources that the system no longer wishes to
               hear from, for packets sent to the specified
               multicast address.  If the change was to an INCLUDE
               source list, these are the addresses that were
               deleted from  the list; if the change was to an
               EXCLUDE source list, these are the addresses that
               were added to the list.

   If a change of source list results in both allowing new sources and
   blocking old sources, then two Group Records are sent for the same
   multicast address, one of type ALLOW_NEW_SOURCES and one of type
   BLOCK_OLD_SOURCES.

IGMP Query

igmp-query

IGMP Report

igmp-report

图来自  Linux Networking Architecture 17.3.4 Implementing IGMP

参考:
1. IGMPV1 rfc1112
2. IGMPV2 rfc2236
3. IGMPV3 rfc3376
4. Linux下IGMP以及多播路由分析
5. Design and Implementation of IGMPv3 for Linux (2000)  
6. Linux Kernel 2.6.26
7. 在线查看Kernel: http://lxr.linux.no/linux+v2.6.26/
8.  RFC3376 因特网组管理协议 第3版(译)
9.  Linux Networking Architecture (Chapter 17. IP Multicast for Group Communication)
10. Mapping IP Multicast to MAC-Layer Multicast 
Categories: Kernel, Tech.Notes Tags: , , ,

Twitter Weekly Updates for 2009-06-29

June 28th, 2009 BianJiang No comments

Powered by Twitter Tools.

Categories: Others Tags:

Twitter Weekly Updates for 2009-06-22

June 21st, 2009 BianJiang No comments

Powered by Twitter Tools.

Categories: Others Tags:

Twitter Weekly Updates for 2009-06-15

June 14th, 2009 BianJiang No comments

Powered by Twitter Tools.

Categories: Others Tags:

Git SVN 工作流程

June 7th, 2009 BianJiang No comments

From: http://andy.delcambre.com/2008/03/04/git-svn-workflow.html
Author: Andy Delcambre
翻译: Bian Jiang

尽管你可以从网上找到成千上万篇关于Git和git-svn,  但是本文主要介绍如何在一个以svn作为版本管理软件的项目里使用git。(假如你已经有了git-svn工具, 那我们就开始用git吧!)

先介绍些背景知识, GitLinus Torvalds 为Linux内核开发的一套版本控制软件。他对版本控制有些特殊的要求,但是没有一个能满足他的要求。Git 有两个最大的优点分布式和执行速度快,它的设计不仅有操作简单的分支(branch)还有功能强大的合并(merge).

声明:这并非是唯一“正确”的方式来使用git + svn, 只是我这样用的, 让我们开始吧。

首先: 假设我们有个subversion仓库(repository)在 http://example.com/svn/my_proj. 你需要创建一个git仓库(repo), 从subversion仓库中下载(pull).

git svn init -s http://example.com/svn/my_proj

这个命令是初始化git仓库从远程的svn上下载。 -s 参数表示 svn 仓库具有标准布局(trunk、branches、tags)。

git svn fetch

这个命令是从subversion取得所有的版本信息,在第一次运行的时候等待的时间比较长。当然你可以通过一些参数来控制只取得某些版本信息,但是我喜欢取得所以的历史版本信息。
现在你已经有了trunk所有版本信息,但是其他的分支的信息都在svn服务器上,你可以通过下面的命令查看所有的分支信息

git branch -a

显示了所有的分支信息,也包括远程的分支信息。
现在在你的本地已经有了完整的subversion历史信息,对你的仓库进行打包就显的非常重要。因为每一个版本就是一个单独的文件,下面的命令就是把这些信息打包到一个大的”pack”文件里面。这样你的仓库就会小很多,但是还是会有些小文件。

git repack -d

下一步就是在仓库里面做我们的工作,这里不推荐直接使用主干(master)分支来进行操作,因此我们要创建一个单独的分支new feature.

git checkout -b new_feature

-b 参数创建一个新的分支并切换到这个分支(chackout). 在你有了新的分支后,就可以在这个分支里进行修改或增加文件。如果你增加了文件需要通过下面的命令告诉git,git将自动跟踪这些新文件。

git add path/to/new_file

现在你可以在你的新分支(new feature)里面工作,并且提交到Git. 你的修改并不会自动提交,如果你想提交上面你增加的文件,你有两个选择: 一个是提交所有修改过的文件,另一个是只提交你想提交(部分)的文件。如果你不想比较所有你修改过的文件可以通过下面的命令完成:

git add path/to/edited_file
git add another/edited/file
git commit -m “commit message”

如果你想提交你所有的操作, 并且已经通过git add增加了所有的新文件。可以通过下面的命令实现:

git commit -a -m “commit message”

-a 参数是提交所以的变更.
现在你已经提交到git里面,但是还没有提交到subversion服务器上。应该把你的内容提交到master分支上。你需要先取得master仓库,然后与你创建的分支(new feaure)合并

git checkout master
git merge new_feature

这次合并没有任何冲突(conflicts), 如果有冲突的话,你应该先修正冲突然后在提交。

一旦你提交到master仓库中,就需要让master分支与svn 仓库同步,并且不能有冲突(如果有冲突就必须修正)

git svn rebase

master 分支与subversion 的trunk同步后,就应该把master提交到subversion仓库。

git svn dcommit

上面简单的介绍了从初始化到提交的整个过程。在接下来的几周里,我将研究一下不同的git命令是怎么工作的。下面的是简单的计划:

  • git reset
  • git rebase
  • git log
  • git stash
  • git merge
  • git mergetool

如果我忘记了一些重要的东西? 请让我知道你是怎么使用git svn 的。

Categories: Translate Tags: ,

简单的Ajax实例

June 2nd, 2009 BianJiang No comments

简单的Ajax实例

Ajax 是一种可以通过Javascript, DHTML and the XMLHttpRequest 来发送GET或POST请求,在数据返回时不必重新载入页面。 下面是一个非常简单的Ajax例子,发送一个请求,打印出请求的字符串和远程用户的IP地址。

简单的Ajax演示 (请参考原文演示: http://www.degraeve.com/reference/simple-ajax-example.php)

Html 页面

这个HTML页面提供了3个JavaScript函数,通过执行XMLHttpRequest来更新HTML页面.(AJAX调用)

<html>
<head>
<title>Simple Ajax Example</title>
<script language=”Javascript”>
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject(”Microsoft.XMLHTTP”);
}
self.xmlHttpReq.open(’POST’, strURL, true);
self.xmlHttpReq.setRequestHeader(’Content-Type’, ‘application/x-www-form-urlencoded’);
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
var form = document.forms['f1'];
var word = form.word.value;
qstr = ‘w=’ + escape(word); // NOTE: no ‘?’ before querystring
return qstr;
}

function updatepage(str){
document.getElementById(”result”).innerHTML = str;
}
</script>
</head>
<body>
<form name=”f1″>
<p>word: <input name=”word” type=”text”>
<input value=”Go” type=”button” onclick=’JavaScript:xmlhttpPost(”/cgi-bin/simple-ajax-example.cgi”)’></p>
<div id=”result”></div>
</form>
</body>
</html>

CGI 脚本

这个CGI脚本是用来应答HTML页面的JavaScript的请求。 CGI脚本可以通过简单的Python, Puby, PHP, C, Perl 等来实现。

#!/usr/bin/perl -w
use CGI;

$query = new CGI;

$secretword = $query->param(’w');
$remotehost = $query->remote_host();

print $query->header;
print “<p>The secret word is <b>$secretword</b> and your IP is <b>$remotehost</b>

原文:  http://www.degraeve.com/reference/simple-ajax-example.php

Categories: Translate Tags: ,