My understanding from historians is that, whether or not the goal was right, it may have been an impossible situation.
Wars are politics and end only with a stable political settlement; without that, they can go on indefinitely - such as in Afghanistan recently.
Like Afghanistan, there was nobody in Vietnam that could run the country, politically, except the North Vietnamese. All the US could do was build someone else's capability, which wasn't working (in Vietname or Afghanistan) or fight indefinitely.
Wars are politics and end only with a stable political settlement; without that, they can go on indefinitely - such as in Afghanistan recently.
Like Afghanistan, there was nobody in Vietnam that could run the country, politically, except the North Vietnamese. All the US could do was build someone else's capability, which wasn't working (in Vietname or Afghanistan) or fight indefinitely.