Jump to content
  • 6

WireGuard WARP добавить настройку Reserved


avn

Question

Добрый день!

Для нормальной работы warp на keenetic хотелось бы реализовать возможность влиять на поле Reserved структуры message_header.

По аналогии с командой asc

interface {name} wireguard warp {b1} {b2} {b3}

У китайцев в Xray-Core получилось это сделать правкой двух методов Xray-core-main\proxy\wireguard\bind.go:

func (bind *netBindClient) connectTo(endpoint *netEndpoint) error {
	c, err := bind.dialer.Dial(bind.ctx, endpoint.dst)
	if err != nil {
		return err
	}
	endpoint.conn = c

	go func(readQueue <-chan *netReadInfo, endpoint *netEndpoint) {
		for {
			v, ok := <-readQueue
			if !ok {
				return
			}
			i, err := c.Read(v.buff)

			if i > 3 {
				v.buff[1] = 0
				v.buff[2] = 0
				v.buff[3] = 0
			}

			v.bytes = i
			v.endpoint = endpoint
			v.err = err
			v.waiter.Done()
			if err != nil && errors.Is(err, io.EOF) {
				endpoint.conn = nil
				return
			}
		}
	}(bind.readQueue, endpoint)

	return nil
}

func (bind *netBindClient) Send(buff [][]byte, endpoint conn.Endpoint) error {
	var err error

	nend, ok := endpoint.(*netEndpoint)
	if !ok {
		return conn.ErrWrongEndpointType
	}

	if nend.conn == nil {
		err = bind.connectTo(nend)
		if err != nil {
			return err
		}
	}

	for _, buff := range buff {
		if len(buff) > 3 && len(bind.reserved) == 3 {
			copy(buff[1:], bind.reserved)
		}
		if _, err = nend.conn.Write(buff); err != nil {
			return err
		}
	}
	return nil
}

 

Тестовый конфиг можно получить так:

bash -c "$(curl -L warp-reg.vercel.app)"

Может и нам можно добавить этот функционал?

Edited by avn
  • Upvote 2
Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0
Posted (edited)
7 часов назад, Le ecureuil сказал:

Я правильно понял, что нужно три байта подствлять в message_header при отправке, и все?

Да, правильно. Но надо помнить, что эти изменения только стороны клиента (не сервера). Также при коннекте клиентом, они их еще и зануляют.

func (bind *netBindClient) connectTo(endpoint *netEndpoint) error {
   ......
			i, err := c.Read(v.buff)

			if i > 3 {
				v.buff[1] = 0
				v.buff[2] = 0
				v.buff[3] = 0
			}

Вообще, если смотреть конфиг WARP в оригинале, запрошенный через api, то он выглядит так

Скрытый текст
{
	"id": "79647",
	"type": "a",
	"model": "PC",
	"name": "FDF5F5",
	"key": "v9NMcOaNTFw=",
	"account": {
		"id": "6714a5c",
		"account_type": "limited",
		"created": "2022-12-18T09:54:43.491648Z",
		"updated": "2024-07-30T12:12:54.223368Z",
		"premium_data": 139000000000,
		"quota": 139000000000,
		"warp_plus": true,
		"referral_count": 139,
		"referral_renewal_countdown": 0,
		"role": "child",
		"license": "87zW",
		"ttl": "2024-10-28T12:12:54.047402Z"
	},
	"config": {
		"client_id": "LHJ3",
		"peers": [
			{
				"public_key": "bmVo51h2wPfgyo=",
				"endpoint": {
					"v4": "188.114.99.229:0",
					"v6": "[2606:4700:d1::a29f:c30a]:0",
					"host": "engage.cloudflareclient.com:2408",
					"ports": [
						854,
						859,
						864,
						878,
						880,
						890,
						891,
						894,
						903,
						908,
						928,
						934,
						939,
						942,
						943,
						945,
						946,
						955,
						968,
						987,
						988,
						1002,
						1010,
						1014,
						1018,
						1070,
						1074,
						1180,
						1387,
						1843,
						2371,
						2506,
						3138,
						3476,
						3581,
						3854,
						4177,
						4198,
						4233,
						5279,
						5956,
						7103,
						7152,
						7156,
						7281,
						7559,
						8319,
						8742,
						8854,
						8886
					]
				}
			}
		],
		"interface": {
			"addresses": {
				"v4": "172.16.0.2",
				"v6": "2606:4700:110:822e:3e0"
			}
		},
		"services": {
			"http_proxy": "172.16.0.1:2480"
		}
	},
	"warp_enabled": false,
	"waitlist_enabled": false,
	"created": "2022-12-18T09:54:43.039543Z",
	"updated": "2024-08-15T13:45:10.034331432Z",
	"tos": "2022-12-18T09:54:41.536765Z",
	"place": 0,
	"locale": "en-US",
	"enabled": true,
	"install_id": "",
	"fcm_token": ""
}

 

Здесь client_id - это "client_id": "LHJ3". Но китайцы раскладывают его на массив из 3 байт.

Edited by avn
Link to comment
Share on other sites

  • 0

У меня почему-то удаленная сторона WARP с вашим конфигом вообще не отвечает.

Потому проверьте на следующей бете сами.

Команда
interface Wireguard0 wireguard peer <peer> client-id send <value>

value - десятеричное число, сделанное простым переводом hex: из 0x1620a6 получается просто 1450150

В итоге в сеть улетает как задумано:

Untitled.jpg

  • Upvote 2
Link to comment
Share on other sites

  • 0
В 21.08.2024 в 13:24, Le ecureuil сказал:

Вобщем, проверяйте на следующей beta.

Не завелось. Пакеты одинаковые. Слева - keenetic (неуспешно), справа (проходящий трафик) те же настройки (успешно). Я вообще не понимаю, что происходит. Не приходит ни одного пакета обратно.

Скрытый текст

image.thumb.png.81fb28cfd2c4e37908ae80be3aee67e6.png

Трейс (WireShark) - keenetic 1.lkk, проходящий - 3.lkk

1.lkk 3.lkk

Link to comment
Share on other sites

  • 0
В 21.08.2024 в 13:24, Le ecureuil сказал:

Вобщем, проверяйте на следующей beta.

Думаю ошибка где-то здесь, нужно занулить три байта header-а. Мне кажется это подходящее место. Если пойдет прием, значит мы на верном пути. Сейчас прием по нулям.

static void wg_packet_consume_data_done(struct wg_peer *peer,
					struct sk_buff *skb,
					struct endpoint *endpoint)
{

  ????????????

	skb->dev = dev;
	/* We've already verified the Poly1305 auth tag, which means this packet
	 * was not modified in transit. We can therefore tell the networking
	 * stack that all checksums of every layer of encapsulation have already
	 * been checked "by the hardware" and therefore is unnecessary to check
	 * again in software.
	 */
	skb->ip_summed = CHECKSUM_UNNECESSARY;

 

func (b *Bind) NewReceiveFunc(fn conn.ReceiveFunc) conn.ReceiveFunc {
	return func(buf []byte) (n int, ep conn.Endpoint, err error) {
		n, ep, err = fn(buf)
		if err != nil || n < 4 {
			return
		}

		if buf[1] != b.reseved[0] || buf[2] != b.reseved[1] || buf[3] != b.reseved[2] {
			err = errors.New("bad reseved")
			return
		}

		buf[1] = 0
		buf[2] = 0
		buf[3] = 0
		return
	}
}
Edited by avn
Link to comment
Share on other sites

  • 0

Если захват происходит на интерфейсе ISP, то тут вопрос не в Keenetic, что нет ответа. До модуля wg эти пакеты еще даже не дошли в момент захвата, потому что-то занулять бессмысленно, пока не будет ответа в проводе от ISP.

Link to comment
Share on other sites

  • 0
В 05.09.2024 в 10:11, Le ecureuil сказал:

Посмотрел дампы, разницы не вижу. Видимо что-то еще важно, но непонятно что.

Пересмотрел еще раз патч, смущает кусок с cpu_to_le32 для маски:

#define SKB_TYPE_LE32(skb, asc) ((((struct message_header *)(skb)->data)->type) & ((asc) ? 0xFFFFFFFF : cpu_to_le32(0xFF)))

Не может он быть корнем проблемы?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...