Why can't you just use string value?
Because RFC 3397 says he must not do that:
To enable the searchlist to be encoded compactly, searchstrings in the searchlist MUST be concatenated and encoded using the technique described in section 4.1.4 of "Domain Names - Implementation And Specification" [RFC1035]. In this scheme, an entire domain name or a list of labels at the end of a domain name is replaced with a pointer to a prior occurrence of the same name.
Even spreading the individual names into several occurrences of the Option 119 would not help as RFC3397 further says that the payload of all occurrences has to be concatenated and handled as a whole.
Is there any adequate way of generating Value for DHCP Option 119 othen than studying RFC3397 and writing a script?
Nope. What you actually have to study is RFC1035, but otherwise yes, a script is your only chance if you want a dynamic list. If you're fine with a static list, you can do the encoding manually.
And unless you need to specify several subdomains of the same domain (like e.g. c.b.a and d.b.a), you don't need the pointers which makes the job much simpler. Example:
and
have no part in common, so you only provide the length of each substring as a byte right in front of it and indicate the end of each fqdn by a zero byte. Here we go:
/ip dhcp server option add name=domain-search code=119 value="0x02'my'0x04'test'0x03'com'0x000x04'your'0x06'domain'0x03'org'0x00"
/ip dhcp server option print detail
0 name="domain-search" code=119 value="0x02'my'0x04'test'0x03'com'0x0004'your'0x06'domain'0x03'org'0x00"
raw-value="026d79047465737403636f6d0004796f757206646f6d61696e036f726700"
The pointers are just a small bit more complex - to add
to the list above, you would do the following:
ip dhcp-server option add name=domain-search code=119 value="0x02'my'0x04'test'0x03'com'0x0004'your'0x06'domain'0x03'org'0x0002'my'0xc012"
The 0xc0 says the following byte is a pointer to the rest of the name, which starts at 18th (0x12) byte from the beginning, counted from 0.