← Documents Documentation/networking/tc-actions-env-rules.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

TC Actions - Environmental Rules

TC action과 caller 사이에서 packet clone, skb 수정, drop과 free 책임을 나누는 규칙입니다.

Source pathDocumentation/networking/tc-actions-env-rules.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

tc-actions-env-rules.rst:1-29

TC action이 packet을 분기하면 clone하고, 공유될 수 있는 `skb`를 수정하기 전에는 `pskb_expand_head()`로 writable 상태를 확보합니다. 소유하지 않은 packet은 직접 drop하지 않고 결과 code로 caller에 책임을 넘깁니다.

Caller는 `TC_ACT_SHOT`, `TC_ACT_STOLEN`, `TC_ACT_QUEUED` 반환값에 맞춰 packet 수명을 마무리합니다. 이 계약을 어기면 double-free, use-after-free 또는 leak이 생길 수 있습니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ================================
4 TC Actions - Environmental Rules
5 ================================
6
7
8 The "environmental" rules for authors of any new tc actions are:
9
10 1) If you stealeth or borroweth any packet thou shalt be branching
11 from the righteous path and thou shalt cloneth.
12
13 For example if your action queues a packet to be processed later,
14 or intentionally branches by redirecting a packet, then you need to
15 clone the packet.
16
17 2) If you munge any packet thou shalt call pskb_expand_head in the case
18 someone else is referencing the skb. After that you "own" the skb.
19
20 3) Dropping packets you don't own is a no-no. You simply return
21 TC_ACT_SHOT to the caller and they will drop it.
22
23 The "environmental" rules for callers of actions (qdiscs etc) are:
24
25 #) Thou art responsible for freeing anything returned as being
26 TC_ACT_SHOT/STOLEN/QUEUED. If none of TC_ACT_SHOT/STOLEN/QUEUED is
27 returned, then all is great and you don't need to do anything.
28
29 Post on netdev if something is unclear.
30

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

문서 제목과 적용 범위

1-7

이 문서는 GPL-2.0 라이선스를 따르며 새 TC action 작성자와 action caller가 지켜야 할 환경 규칙을 정의합니다.

.. SPDX-License-Identifier: GPL-2.0

================================
TC Actions - Environmental Rules
================================

TC action 작성자의 skb 규칙

8-20

새 TC action 작성자가 지켜야 할 환경 규칙은 다음과 같습니다.

1. Packet을 가져가거나 빌려 별도 경로로 분기한다면 반드시 clone해야 합니다. 예를 들어 나중에 처리하도록 packet을 queue에 넣거나 redirect로 의도적인 분기를 만들면 packet clone이 필요합니다.

2. Packet을 수정하려면 다른 주체가 그 `skb`를 참조하고 있을 가능성에 대비해 `pskb_expand_head()`를 호출해야 합니다. 그 호출 뒤부터 action이 해당 `skb`를 소유합니다.

3. 자신이 소유하지 않은 packet을 직접 drop하면 안 됩니다. Caller에 `TC_ACT_SHOT`을 반환하면 caller가 packet을 drop합니다.

TC action 소유권 규칙
상황Action의 동작책임
Queue 또는 redirect 분기packet clone원래 경로와 새 경로 분리
Packet 수정pskb_expand_head()호출 뒤 skb 소유
소유하지 않은 packet dropTC_ACT_SHOT 반환caller가 free/drop

Clone, copy-on-write와 drop 책임을 구분합니다.

The "environmental" rules for authors of any new tc actions are:

1) If you stealeth or borroweth any packet thou shalt be branching
   from the righteous path and thou shalt cloneth.

   For example if your action queues a packet to be processed later,
   or intentionally branches by redirecting a packet, then you need to
   clone the packet.

2) If you munge any packet thou shalt call pskb_expand_head in the case
   someone else is referencing the skb. After that you "own" the skb.

3) Dropping packets you don't own is a no-no. You simply return

Qdisc 등 caller의 해제 책임

21-29

Qdisc처럼 action을 호출하는 쪽의 환경 규칙은 다음과 같습니다.

Action이 `TC_ACT_SHOT`, `TC_ACT_STOLEN` 또는 `TC_ACT_QUEUED`를 반환했다면 caller가 해당 결과에 맞는 해제 책임을 집니다. 이 세 값이 하나도 반환되지 않았다면 caller가 별도로 처리할 것은 없습니다.

규칙이 불명확하면 netdev mailing list에 질문해야 합니다.

TC action 반환 책임
Action 실행SHOT / STOLEN / QUEUEDCaller가 반환 의미에 따라 free 처리
Action 실행그 밖의 결과추가 free 불필요

Action 결과에 따라 caller의 packet 수명 책임이 결정됩니다.

   TC_ACT_SHOT to the caller and they will drop it.

The "environmental" rules for callers of actions (qdiscs etc) are:

#) Thou art responsible for freeing anything returned as being
   TC_ACT_SHOT/STOLEN/QUEUED. If none of TC_ACT_SHOT/STOLEN/QUEUED is
   returned, then all is great and you don't need to do anything.

Post on netdev if something is unclear.