{"id":20064901,"url":"https://github.com/baidu/ttm","last_synced_at":"2025-05-05T18:31:13.105Z","repository":{"id":53562938,"uuid":"202491980","full_name":"baidu/ttm","owner":"baidu","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-24T06:30:14.000Z","size":25,"stargazers_count":16,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T02:22:07.067Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baidu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-15T07:08:21.000Z","updated_at":"2025-03-05T09:44:51.000Z","dependencies_parsed_at":"2022-09-15T17:01:35.469Z","dependency_job_id":null,"html_url":"https://github.com/baidu/ttm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fttm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fttm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fttm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2Fttm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baidu","download_url":"https://codeload.github.com/baidu/ttm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252552966,"owners_count":21766807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:48:09.771Z","updated_at":"2025-05-05T18:31:12.839Z","avatar_url":"https://github.com/baidu.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ttm\n\nTTM模块用来支持服务端应用程序获取客户端真实源IP。客户端的数据包经过高防IP转发后，会将数据包的源地址和端口号，改成高防IP回源的地址和端口号。\n如果高防IP转发报文时将客户端真实源IP和端口号添加到TCP报文的tcp option字段。源站加载TTM模块后，TTM模块通过Hook Linux内核TCP协议栈的相关函数，\n从TCP报文的tcp option字段中解析出客户端真实源IP和端口号。服务端应用程序调用getpeername或者accept获取到的就是客户端真实源IP和端口号。\n\n## 编译\n\n1. 安装编译环境\n```\nyum -y install gcc kernel-headers kernel-devel\n```\n2. 编译TTM模块，编译后会在当前目录生成bce_ttm.ko文件\n```\nmake\n```\n3. 加载TTM模块\n```\nmv bce_ttm.ko /lib/modules/$(uname -r)/kernel/net/ipv4/\ninsmod /lib/modules/$(uname -r)/kernel/net/ipv4/bce_ttm.ko\n```  \n\n## 测试\n\n可以使用testtools目录下的ttm_test.c程序进行测试，测试步骤如下：\n1. 下载编译libpcap\n```\nwget -c http://www.tcpdump.org/release/libpcap-1.5.3.tar.gz\ntar -zvxf libpcap-1.5.3.tar.gz \ncd libpcap-1.5.3/\n./configure\nmake \u0026\u0026 make install\n``` \n\u003e **注意：**\n\u003e 如果安装libpcap失败，可能是缺少依赖库bison和flex，执行yum -y install bison flex\n\n2. 编译ttm_test程序\n```\ngcc ttm_test.c -o ttm_test -lpcap\n```\n3. 配置iptables规则，丢掉被测机器的报文，不让它送入内核，否则对测试会有干扰\n ```\niptables -A INPUT -p tcp -s x.x.x.x --sport 80 -j DROP\n```\n4. 执行ttm_test测试程序\n ```\n./ttm_test -e eth0 -s x.x.x.x -d x.x.x.x -p 80\n```\n\u003e **注意：**\n\u003e -s后加的是源ip，-d后加的是目的ip，-e后加的是libpcap监听的网卡，可以通过执行./ttm_test -h查看参数说明","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Fttm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaidu%2Fttm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2Fttm/lists"}