요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
================================
TC Actions - Environmental Rules
================================
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
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.
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합니다.
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-29Qdisc처럼 action을 호출하는 쪽의 환경 규칙은 다음과 같습니다.
Action이 `TC_ACT_SHOT`, `TC_ACT_STOLEN` 또는 `TC_ACT_QUEUED`를 반환했다면 caller가 해당 결과에 맞는 해제 책임을 집니다. 이 세 값이 하나도 반환되지 않았다면 caller가 별도로 처리할 것은 없습니다.
규칙이 불명확하면 netdev mailing list에 질문해야 합니다.
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.
요약·해설
tc-actions-env-rules.rst:1-29TC 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이 생길 수 있습니다.